stocktwit 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- require "stocktwit/reader"
1
+ require "stocktwit/rss"
@@ -0,0 +1,45 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+
4
+ module Stocktwit
5
+ module Rss
6
+ class << self
7
+ def read
8
+ # StockTwits API URL (can be refreshed every minute or so)
9
+ url = 'http://stocktwits.com/streams/all.xml'
10
+
11
+ # get the XML data as a string
12
+ xml_data = Net::HTTP.get_response(URI.parse(url)).body
13
+
14
+ # extract event information
15
+ doc = REXML::Document.new(xml_data)
16
+
17
+ tweets = []
18
+ doc.elements.each('stream/tweets/tweet') do |el|
19
+ tweets << {
20
+ :user_id => el.elements['twitter_user_id'].text,
21
+ :status_id => el.elements['status_id'].text,
22
+ :tweet_datetime => el.elements['tweet_datetime'].text,
23
+ :twitter_username => el.elements['twitter_username'].text,
24
+ :tweet_text => el.elements['tweet_text'].text
25
+ }
26
+ end
27
+
28
+ tickers = {}
29
+ doc.elements.each('stream/tweets/tweet/stocks/stock/ticker') do |el|
30
+ unless tickers[el.text]
31
+ tickers[el.text] = 0
32
+ end
33
+ tickers[el.text] += 1
34
+ end
35
+
36
+ return {
37
+ :tweets => tweets,
38
+ :tickers => tickers.keys.collect {|k|
39
+ {:name => k, :count => tickers[k]}
40
+ }
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Stocktwit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stocktwit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Scott
@@ -29,7 +29,7 @@ extensions: []
29
29
  extra_rdoc_files: []
30
30
 
31
31
  files:
32
- - lib/stocktwit/reader.rb
32
+ - lib/stocktwit/rss.rb
33
33
  - lib/stocktwit/version.rb
34
34
  - lib/stocktwit.rb
35
35
  - LICENSE
@@ -1,9 +0,0 @@
1
- module Stocktwit
2
- module Reader
3
- class << self
4
- def read
5
- "Stocktwit::Reader#read"
6
- end
7
- end
8
- end
9
- end