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.
-
#name ⇒ Object
Returns the value of attribute name.
-
#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(name, options = {}) ⇒ Client
constructor
Create a new client instance.
Constructor Details
#initialize(name, options = {}) ⇒ Client
Create a new client instance
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/frenchy/client.rb', line 10 def initialize(name, ={}) .stringify_keys! @name = name.to_s @host = .fetch("host") { "http://127.0.0.1:8080" } @timeout = .fetch("timeout") { 30 } @retries = .fetch("retries") { 0 } @backoff_delay = .fetch("backoff_delay") { 1.0 } @headers = .fetch("headers") { {} } end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/frenchy/client.rb', line 7 def host @host end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/frenchy/client.rb', line 7 def name @name end |
#retries ⇒ Object
Returns the value of attribute retries.
7 8 9 |
# File 'lib/frenchy/client.rb', line 7 def retries @retries end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/frenchy/client.rb', line 7 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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/frenchy/client.rb', line 23 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::ServerError => err try += 1 end end raise err end |