Class: Tweetwine::RestClientWrapper
- Inherits:
-
Object
- Object
- Tweetwine::RestClientWrapper
- Defined in:
- lib/tweetwine/rest_client_wrapper.rb
Constant Summary collapse
- MAX_RETRIES =
3
- RETRY_BASE_WAIT_TIMEOUT =
4
Instance Method Summary collapse
-
#initialize(io) ⇒ RestClientWrapper
constructor
A new instance of RestClientWrapper.
Constructor Details
#initialize(io) ⇒ RestClientWrapper
Returns a new instance of RestClientWrapper.
12 13 14 |
# File 'lib/tweetwine/rest_client_wrapper.rb', line 12 def initialize(io) @io = io end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tweetwine/rest_client_wrapper.rb', line 18 def method_missing(name, *args, &block) tries = 0 begin tries += 1 RestClient.send(name, *args, &block) rescue Errno::ECONNRESET => e if tries < MAX_RETRIES timeout = RETRY_BASE_WAIT_TIMEOUT**tries @io.warn("Could not connect -- retrying in #{timeout} seconds") sleep timeout retry else raise ClientError, e end rescue RestClient::Exception, SocketError, SystemCallError => e raise ClientError, e end end |