Class: Frenchy::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Create a new client instance



8
9
10
11
12
13
14
# File 'lib/frenchy/client.rb', line 8

def initialize(options={})
  options.symbolize_keys!

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

Instance Method Details

#delete(path, params) ⇒ Object



36
# File 'lib/frenchy/client.rb', line 36

def delete(path, params); perform(:delete, path, params); end

#get(path, params) ⇒ Object

Issue a get request with the given path and query parameters



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/frenchy/client.rb', line 17

def get(path, params)
  try = 0
  error = nil

  while try <= @retries
    begin
      return perform(:get, path, params)
    rescue Frenchy::ServerError, Frenchy::InvalidResponse => error
      sleep (0.35 * (try*try))
      try += 1
    end
  end

  raise error
end

#post(path, params) ⇒ Object

Issue a non-retryable request with the given path and query parameters



34
# File 'lib/frenchy/client.rb', line 34

def post(path, params); perform(:post, path, params); end

#put(path, params) ⇒ Object



35
# File 'lib/frenchy/client.rb', line 35

def put(path, params); perform(:put, path, params); end