Class: StreamGrabber::Twitter

Inherits:
Object
  • Object
show all
Defined in:
lib/stream_grabber/twitter.rb

Instance Method Summary collapse

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_fiveObject



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, message_from(tweet["text"], tweet["id"])]
  end
  tweets
end

#message_from(text, id) ⇒ Object



20
21
22
# File 'lib/stream_grabber/twitter.rb', line 20

def message_from(text, id)
  %Q{<a href="http://twitter.com/#{@user_name}/status/#{id}">#{text}</a>}
end