stocktwits-api 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'faraday'
6
+ gem 'json'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.0"
13
+ gem "rcov", ">= 0"
14
+ end
15
+
16
+ group :test do
17
+ gem 'minitest'
18
+ end
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.4)
5
+ faraday (0.7.0)
6
+ addressable (~> 2.2.4)
7
+ multipart-post (~> 1.1.0)
8
+ rack (>= 1.1.0, < 2)
9
+ git (1.2.5)
10
+ jeweler (1.6.0)
11
+ bundler (~> 1.0.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ json (1.5.1)
15
+ minitest (2.2.2)
16
+ multipart-post (1.1.2)
17
+ rack (1.2.2)
18
+ rake (0.9.1)
19
+ rcov (0.9.9)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ faraday
27
+ jeweler (~> 1.6.0)
28
+ json
29
+ minitest
30
+ rcov
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Larry Staton Jr.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ = stocktwits-api
2
+
3
+ A wrapper for the StockTwits API.
4
+
5
+ == Usage
6
+
7
+ Query the StockTwits API for streams, user streams, and symbol streams:
8
+
9
+ require 'stocktwits'
10
+
11
+ StockTwits.stream("all") # JSON object with messages from the all stream
12
+ StockTwits.user("stocktwits") # JSON object with messages from the stocktwits stream
13
+ StockTwits.symbol("AAPL") # JSON object with messages from the AAPL stream
14
+ StockTwits.symbol("AAPL,MSFT") # JSON object with messages from the AAPL stream and MSFT stream
15
+
16
+ == Contributing to stocktwits-api
17
+
18
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
19
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
20
+ * Fork the project
21
+ * Start a feature/bugfix branch
22
+ * Commit and push until you are happy with your contribution
23
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
24
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2011 Larry Staton Jr. See LICENSE.txt for further details.
29
+
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "stocktwits-api"
18
+ gem.homepage = "http://github.com/statonjr/stocktwits-api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A wrapper for the StockTwits API.}
21
+ gem.description = %Q{StockTwits is a financial idea network.}
22
+ gem.email = "statonjr@gmail.com"
23
+ gem.authors = ["Larry Staton Jr."]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency "faraday"
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rdoc/task'
47
+ RDoc::Task.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "stocktwits #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,40 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'stocktwits/errors.rb'
4
+
5
+ module StockTwits
6
+
7
+ BASE_URL = "http://api.stocktwits.com"
8
+
9
+ @connection = Faraday.new(:url => BASE_URL) do |builder|
10
+ builder.use Faraday::Response::StockTwitsErrors
11
+ builder.adapter Faraday.default_adapter
12
+ end
13
+
14
+ def self.stream(name="public")
15
+
16
+ response = @connection.get("/api/streams/#{name}.json")
17
+ response.body
18
+
19
+ end
20
+
21
+ def self.user(name="stocktwits")
22
+
23
+ response = @connection.get "/api/streams/user/#{name}.json"
24
+ response.body
25
+
26
+ end
27
+
28
+ def self.symbol(name="AAPL")
29
+
30
+ if name && name.split(",").length > 1
31
+ response = @connection.get("/api/streams/symbols.json?symbols=#{name}")
32
+ else
33
+ response = @connection.get("/api/streams/symbol/#{name}.json")
34
+ end
35
+
36
+ response.body
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+
3
+ module Faraday
4
+ class Response::StockTwitsErrors < Response::Middleware
5
+
6
+ def initialize(app)
7
+ super app
8
+ end
9
+
10
+ def call(env)
11
+ # Handle request
12
+
13
+ # Always call super last
14
+ super
15
+ end
16
+
17
+ def on_complete(env)
18
+ # Handle response
19
+ body = JSON.parse(env[:body])
20
+ status = body["response"]["status"]
21
+ case status
22
+ when 200
23
+ env[:body]
24
+ else
25
+ env[:body] = body["errors"][0]
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{stocktwits-api}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Larry Staton Jr."]
12
+ s.date = %q{2011-06-05}
13
+ s.description = %q{StockTwits is a financial idea network.}
14
+ s.email = %q{statonjr@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/stocktwits.rb",
28
+ "lib/stocktwits/errors.rb",
29
+ "stocktwits-api.gemspec",
30
+ "test/helper.rb",
31
+ "test/test_stocktwits.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/statonjr/stocktwits-api}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.6.2}
37
+ s.summary = %q{A wrapper for the StockTwits API.}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<faraday>, [">= 0"])
44
+ s.add_runtime_dependency(%q<json>, [">= 0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ s.add_runtime_dependency(%q<faraday>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<faraday>, [">= 0"])
51
+ s.add_dependency(%q<json>, [">= 0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
54
+ s.add_dependency(%q<rcov>, [">= 0"])
55
+ s.add_dependency(%q<faraday>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<faraday>, [">= 0"])
59
+ s.add_dependency(%q<json>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<faraday>, [">= 0"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'minitest/autorun'
11
+ require 'minitest/pride'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'stocktwits'
@@ -0,0 +1,73 @@
1
+ require 'helper'
2
+
3
+ # class TestStocktwits < MiniTest::Spec
4
+ describe StockTwits do
5
+
6
+ describe "streams" do
7
+ it "should return the public stream by default" do
8
+ response = StockTwits.stream
9
+ wont_be_empty response
10
+ response.must_match /messages/
11
+ end
12
+
13
+ it "should return the stream for the argument" do
14
+ response = StockTwits.stream("all")
15
+ wont_be_empty response
16
+ response.must_match /messages/
17
+ end
18
+
19
+ it "should display error message when invalid stream" do
20
+ response = StockTwits.stream("moose")
21
+ wont_be_empty response
22
+ response.must_equal "Authentication error"
23
+ end
24
+ end
25
+
26
+ describe "user streams" do
27
+ it "should return the stream for user stocktwits by default" do
28
+ response = StockTwits.user
29
+ wont_be_empty response
30
+ response.must_match /messages/
31
+ end
32
+
33
+ it "should return the stream for the user in the argument" do
34
+ response = StockTwits.user("statonjr")
35
+ wont_be_empty response
36
+ response.must_match /messages/
37
+ end
38
+
39
+ it "should display helpful message when invalid username" do
40
+ response = StockTwits.user("poppycock")
41
+ wont_be_empty response
42
+ response.must_equal "User not found"
43
+ end
44
+ end
45
+
46
+ describe "symbol streams" do
47
+ it "should return the stream for AAPL by default" do
48
+ response = StockTwits.symbol
49
+ wont_be_empty response
50
+ response.must_match /AAPL/
51
+ end
52
+
53
+ it "should return the stream for the symbol in the arguments" do
54
+ response = StockTwits.symbol("MSFT")
55
+ wont_be_empty response
56
+ response.must_match /MSFT/
57
+ end
58
+
59
+ it "should return the streams for multiple symbols passed in" do
60
+ response = StockTwits.symbol("AAPL,MSFT")
61
+ wont_be_empty response
62
+ response.must_match /AAPL/
63
+ response.must_match /MSFT/
64
+ end
65
+
66
+ it "should display helpful message when invalid argument" do
67
+ response = StockTwits.symbol("SPEA")
68
+ wont_be_empty response
69
+ response.must_equal "Symbol not found"
70
+ end
71
+ end
72
+
73
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stocktwits-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Larry Staton Jr.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-05 00:00:00.000000000 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: &2152854960 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2152854960
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ requirement: &2152854240 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2152854240
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &2152853520 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2152853520
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &2152852800 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2152852800
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &2152852120 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2152852120
70
+ - !ruby/object:Gem::Dependency
71
+ name: faraday
72
+ requirement: &2152851420 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: *2152851420
81
+ description: StockTwits is a financial idea network.
82
+ email: statonjr@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.rdoc
88
+ files:
89
+ - .document
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - lib/stocktwits.rb
97
+ - lib/stocktwits/errors.rb
98
+ - stocktwits-api.gemspec
99
+ - test/helper.rb
100
+ - test/test_stocktwits.rb
101
+ has_rdoc: true
102
+ homepage: http://github.com/statonjr/stocktwits-api
103
+ licenses:
104
+ - MIT
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ segments:
116
+ - 0
117
+ hash: 1545794505768486286
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 1.6.2
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: A wrapper for the StockTwits API.
130
+ test_files: []