Class: Flamingo::Wader
- Inherits:
-
Object
- Object
- Flamingo::Wader
- Defined in:
- lib/flamingo/wader.rb
Defined Under Namespace
Classes: AuthenticationError, HttpStatusError, InvalidParametersError, MaxReconnectsExceededError, ServerUnavailableError, UnknownStreamError, WaderError
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#password ⇒ Object
Returns the value of attribute password.
-
#screen_name ⇒ Object
Returns the value of attribute screen_name.
-
#server_unavailable_max_retries ⇒ Object
Returns the value of attribute server_unavailable_max_retries.
-
#server_unavailable_retries ⇒ Object
Returns the value of attribute server_unavailable_retries.
-
#server_unavailable_wait ⇒ Object
Returns the value of attribute server_unavailable_wait.
-
#stream ⇒ Object
Returns the value of attribute stream.
Instance Method Summary collapse
-
#initialize(screen_name, password, stream) ⇒ Wader
constructor
A new instance of Wader.
- #retries ⇒ Object
-
#run ⇒ Object
The main EventMachine run loop.
- #stop ⇒ Object
Constructor Details
#initialize(screen_name, password, stream) ⇒ Wader
Returns a new instance of Wader.
33 34 35 36 37 38 39 |
# File 'lib/flamingo/wader.rb', line 33 def initialize(screen_name,password,stream) self.screen_name = screen_name self.password = password self.stream = stream self.server_unavailable_max_retries = 5 self.server_unavailable_wait = 60 end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
28 29 30 |
# File 'lib/flamingo/wader.rb', line 28 def connection @connection end |
#password ⇒ Object
Returns the value of attribute password.
28 29 30 |
# File 'lib/flamingo/wader.rb', line 28 def password @password end |
#screen_name ⇒ Object
Returns the value of attribute screen_name.
28 29 30 |
# File 'lib/flamingo/wader.rb', line 28 def screen_name @screen_name end |
#server_unavailable_max_retries ⇒ Object
Returns the value of attribute server_unavailable_max_retries.
28 29 30 |
# File 'lib/flamingo/wader.rb', line 28 def server_unavailable_max_retries @server_unavailable_max_retries end |
#server_unavailable_retries ⇒ Object
Returns the value of attribute server_unavailable_retries.
28 29 30 |
# File 'lib/flamingo/wader.rb', line 28 def server_unavailable_retries @server_unavailable_retries end |
#server_unavailable_wait ⇒ Object
Returns the value of attribute server_unavailable_wait.
28 29 30 |
# File 'lib/flamingo/wader.rb', line 28 def server_unavailable_wait @server_unavailable_wait end |
#stream ⇒ Object
Returns the value of attribute stream.
28 29 30 |
# File 'lib/flamingo/wader.rb', line 28 def stream @stream end |
Instance Method Details
#retries ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/flamingo/wader.rb', line 70 def retries if connection # This is weird but necessary because twitter-stream increments the # reconnect_retries a bit oddly. They are incremented prior to the # actual reconnect which means that the last reconnect_retries value # is 1 more than the real value. rs = connection.reconnect_retries rs == 0 ? 0 : rs - 1 else 0 end end |
#run ⇒ Object
The main EventMachine run loop
Start the stream listener (using twitter-stream, github.com/voloko/twitter-stream) Listen for responses and errors;
dispatch each for later handling
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/flamingo/wader.rb', line 48 def run self.server_unavailable_retries = 0 begin connect_and_run rescue => e # This is largely to get around a bug in Twitter-Stream that should # be fixed in the next release. If the server is just not there on # the first try, it blows up. Hopefully this code can be removed after # that release. Flamingo.logger.warn "Failure initiating connection. Most likely "+ "because server is unavailable.\n#{e}\n#{e.backtrace.join("\n\t")}" if server_unavailable_retries < server_unavailable_max_retries sleep(server_unavailable_wait) self.server_unavailable_retries += 1 retry else raise ServerUnavailableError.new end end raise @error if @error end |
#stop ⇒ Object
83 84 85 86 87 88 |
# File 'lib/flamingo/wader.rb', line 83 def stop if connection connection.stop end EM.stop end |