Module: Herald::Watcher::Twitter

Defined in:
lib/herald/watchers/twitter.rb

Overview

TODO, ignore retweets, if option passed

Constant Summary collapse

TWITTER_API =
"http://search.twitter.com/search.json"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_tweet_idObject

Returns the value of attribute last_tweet_id.



8
9
10
# File 'lib/herald/watchers/twitter.rb', line 8

def last_tweet_id
  @last_tweet_id
end

#uriObject

Returns the value of attribute uri.



8
9
10
# File 'lib/herald/watchers/twitter.rb', line 8

def uri
  @uri
end

Class Method Details

.included(base) ⇒ Object

lazy-load open-uri when this Module is used



11
12
13
14
# File 'lib/herald/watchers/twitter.rb', line 11

def self.included(base)
  Herald.lazy_load('open-uri')
  Herald.lazy_load('crack')
end

Instance Method Details

#cleanupObject



31
# File 'lib/herald/watchers/twitter.rb', line 31

def cleanup; end

#parse_options(options) ⇒ Object



16
# File 'lib/herald/watchers/twitter.rb', line 16

def parse_options(options); end

#prepareObject

executed before Watcher starts



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/herald/watchers/twitter.rb', line 19

def prepare
  # twitter doesn't allow you to query its api without
  # providing a query string
  if @keywords.empty?
    raise ArgumentError, "Keywords are missing"
  end
  # initialise array, first element will be the Twitter API with search query string, 
  # the second element will be a "since_id" extra query parameter, added at close of 
  # activities() loop
  @uri = ["#{TWITTER_API}?q=#{@keywords.join('+')}"]
end

#to_sObject



33
34
35
# File 'lib/herald/watchers/twitter.rb', line 33

def to_s
  "Herald Twitter Watcher, Keywords: '#{@keywords}', Timer: #{@timer}, State: #{@keep_alive ? 'Watching' : 'Stopped'}"
end