Class: Messed::Interface::Adapter::TwitterStreaming
- Inherits:
-
TwitterConsumer
- Object
- Messed::Interface::Adapter
- TwitterConsumer
- Messed::Interface::Adapter::TwitterStreaming
- Includes:
- Logger::LoggingModule
- Defined in:
- lib/messed/interface/adapter/twitter_streaming.rb
Constant Summary
Constants inherited from Messed::Interface::Adapter
Instance Attribute Summary
Attributes inherited from TwitterConsumer
#errors, #last_error, #last_ok, #last_status, #packets_processed, #started_at
Attributes inherited from Messed::Interface::Adapter
Instance Method Summary collapse
Methods included from Logger::LoggingModule
Methods inherited from TwitterConsumer
Methods inherited from Messed::Interface::Adapter
for_name, #init, #initialize, #load_state, register_for_name, #save_state, #send, #state_file, #type
Constructor Details
This class inherits a constructor from Messed::Interface::Adapter
Instance Method Details
#start ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/messed/interface/adapter/twitter_streaming.rb', line 10 def start stream = Twitter::JSONStream.connect( :path => "/1/statuses/#{interface.configuration.['streaming']['type']}.json?track=%23classicmoviequotes", :auth => "#{interface.configuration.['username']}:#{interface.configuration.['password']}" ) stream.each_item do |item| self.last_ok = Time.new result = JSON.parse(item) = Message::Twitter.new do |m| m.body = result['text'] m.from = result['from_user'] m.to = result['to_user_id'] m.created_at = Time.rfc2822(result['created_at']) m.profile_image_url = result['profile_image_url'] m.id = result['id'] m.geo = result['geo'] m.from_user_id = result['from_user_id'] m.iso_language_code = result['iso_language_code'] m.source = result['source'] end self.packets_processed += 1 interface.application.incoming << end stream.on_error do || logger.error "message #{.inspect}" self.errors += 1 self.last_error = end stream.on_max_reconnects do |timeout, retries| logger.error "message -> #{timeout} #{retries}" # Something is wrong on your side. Send yourself an email. end end |