Class: Frenchy::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/frenchy/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  options.stringify_keys!

  @host = options.delete("host") || "http://127.0.0.1:8080"
  @timeout = options.delete("timeout") || 30
  @retries = options.delete("retries") || 0
  @backoff_delay = options.delete("backoff_delay") || 1.0
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/frenchy/client.rb', line 6

def host
  @host
end

#retriesObject

Returns the value of attribute retries.



6
7
8
# File 'lib/frenchy/client.rb', line 6

def retries
  @retries
end

#timeoutObject

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