Class: StreamGrabber::Twitter
- Inherits:
-
Object
- Object
- StreamGrabber::Twitter
- Defined in:
- lib/stream_grabber/twitter.rb
Instance Method Summary collapse
-
#initialize(user_name, api_key = nil) ⇒ Twitter
constructor
A new instance of Twitter.
- #last_five ⇒ Object
- #message_from(text, id) ⇒ Object
Constructor Details
#initialize(user_name, api_key = nil) ⇒ Twitter
Returns a new instance of Twitter.
6 7 8 9 |
# File 'lib/stream_grabber/twitter.rb', line 6 def initialize(user_name, api_key=nil) @user_name = user_name @doc = JSON.load(open("http://api.twitter.com/1/statuses/user_timeline.json?count=6&screen_name=#{user_name}")) end |
Instance Method Details
#last_five ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/stream_grabber/twitter.rb', line 11 def last_five tweets = {} @doc.each do |tweet| date = Time.parse(tweet["created_at"]).to_i tweets[date] = [:twitter, (tweet["text"], tweet["id"])] end tweets end |
#message_from(text, id) ⇒ Object
20 21 22 |
# File 'lib/stream_grabber/twitter.rb', line 20 def (text, id) %Q{<a href="http://twitter.com/#{@user_name}/status/#{id}">#{text}</a>} end |