Class: Frenchy::Client
- Inherits:
-
Object
- Object
- Frenchy::Client
- Defined in:
- lib/frenchy/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#get(path, params) ⇒ Object
Issue a get request with the given path and query parameters.
-
#initialize(options = {}) ⇒ Client
constructor
Create a new client instance.
Constructor Details
#initialize(options = {}) ⇒ Client
Create a new client instance
9 10 11 12 13 14 15 16 |
# File 'lib/frenchy/client.rb', line 9 def initialize(={}) .stringify_keys! @host = .delete("host") || "http://127.0.0.1:8080" @timeout = .delete("timeout") || 30 @retries = .delete("retries") || 0 @backoff_delay = .delete("backoff_delay") || 1.0 end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/frenchy/client.rb', line 6 def host @host end |
#retries ⇒ Object
Returns the value of attribute retries.
6 7 8 |
# File 'lib/frenchy/client.rb', line 6 def retries @retries end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/frenchy/client.rb', line 6 def timeout @timeout end |
Instance Method Details
#get(path, params) ⇒ Object
Issue a get request with the given path and query parameters. Get requests can be retried.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/frenchy/client.rb', line 20 def get(path, params) try = 0 err = nil while try <= @retries sleep (@backoff_delay * (try*try)) if try > 0 begin return perform("GET", path, params) rescue Frenchy::Error => err try += 1 end end raise err end |