Class: EzClient::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



4
5
6
7
# File 'lib/ezclient/client.rb', line 4

def initialize(options = {})
  self.options = options
  self.clients = {}
end

Instance Method Details

#perform(*args) ⇒ Object



26
27
28
# File 'lib/ezclient/client.rb', line 26

def perform(*args)
  request(*args).perform
end

#perform!(*args) ⇒ Object



30
31
32
# File 'lib/ezclient/client.rb', line 30

def perform!(*args)
  request(*args).perform!
end

#request(verb, url, **options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ezclient/client.rb', line 9

def request(verb, url, **options)
  options = { **default_options, **options } # TODO: raise on unknown options

  keep_alive_timeout = options.delete(:keep_alive)
  api_auth = options.delete(:api_auth)

  if keep_alive_timeout
    client = persistent_client_for(url, timeout: keep_alive_timeout)
  else
    client = HTTP::Client.new
  end

  EzClient::Request.new(verb, url, client: client, **options).tap do |request|
    request.api_auth!(*api_auth) if api_auth
  end
end