Class: TweetTail::TweetPoller

Inherits:
Object
  • Object
show all
Defined in:
lib/tweet-tail/tweet_poller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ TweetPoller

Returns a new instance of TweetPoller.



6
7
8
# File 'lib/tweet-tail/tweet_poller.rb', line 6

def initialize(query)
  @query   = query
end

Instance Attribute Details

#latest_resultsObject

Returns the value of attribute latest_results.



4
5
6
# File 'lib/tweet-tail/tweet_poller.rb', line 4

def latest_results
  @latest_results
end

#queryObject

Returns the value of attribute query.



4
5
6
# File 'lib/tweet-tail/tweet_poller.rb', line 4

def query
  @query
end

#refresh_urlObject

Returns the value of attribute refresh_url.



4
5
6
# File 'lib/tweet-tail/tweet_poller.rb', line 4

def refresh_url
  @refresh_url
end

Instance Method Details

#refreshObject



10
11
12
13
14
15
16
17
18
# File 'lib/tweet-tail/tweet_poller.rb', line 10

def refresh
  unless @refresh_url
    @latest_feed = JSON.parse(initial_json_data)
  else
    @latest_feed = JSON.parse(refresh_json_data)
  end
  @latest_results = @latest_feed["results"].reverse
  @refresh_url    = @latest_feed["refresh_url"]
end

#render_latest_resultsObject



20
21
22
23
24
25
26
# File 'lib/tweet-tail/tweet_poller.rb', line 20

def render_latest_results
  @latest_results.inject("") do |output, tweet|
    screen_name = tweet['from_user']
    message     = tweet['text']
    output += "#{screen_name}: #{message}\n"
  end
end