Class: WaseEndpoint::Twitterer
- Inherits:
-
Object
- Object
- WaseEndpoint::Twitterer
- Defined in:
- lib/wase_endpoint/twitterer.rb
Instance Method Summary collapse
-
#fetch ⇒ Object
Fetches the timeline and returns any new messages.
-
#initialize(username, password) ⇒ Twitterer
constructor
A new instance of Twitterer.
- #send(recipient, program_counter, program_list_uri, output_uri, input_uri = nil, input_uri_1 = nil) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Twitterer
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/wase_endpoint/twitterer.rb', line 4 def initialize(username, password) twitter_http_auth = Twitter::HTTPAuth.new(username, password) @twitter_client = Twitter::Base.new(twitter_http_auth) # Call the test api method to validate the authentication. @twitter_client.help # The oldest message ID could be stored here, but since twitter IDs # aren't always time-linear, comparing the messages is safer. = [] end |
Instance Method Details
#fetch ⇒ Object
Fetches the timeline and returns any new messages.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wase_endpoint/twitterer.rb', line 17 def fetch = [] # Ignore any messages that don't have the hashtag. # Use twitter search to do this instead? @twitter_client.replies.reject{|m| !m.text[/#wase/]}.each do |reply| = Message.new(reply.id, reply.text) # Skip if we've already processed this message. unless .include?() << << end end end |
#send(recipient, program_counter, program_list_uri, output_uri, input_uri = nil, input_uri_1 = nil) ⇒ Object
34 35 36 37 |
# File 'lib/wase_endpoint/twitterer.rb', line 34 def send(recipient, program_counter, program_list_uri, output_uri, input_uri=nil, input_uri_1=nil) text = ["#{recipient} #wase", program_counter, program_list_uri, Time.now.utc.to_i, output_uri, input_uri, input_uri_1].compact.join(', ') @twitter_client.update(text) end |