9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/exa/connection.rb', line 9
def self.build(api_key:, **options, &block)
Faraday.new(url: options[:base_url] || DEFAULT_BASE_URL) do |conn|
conn.["x-api-key"] = api_key
conn.request :json
if options[:debug]
conn.response :logger, Logger.new($stdout), headers: true, bodies: true
end
conn.response :raise_error
conn.response :json, content_type: /\bjson$/
conn.options.timeout = options[:timeout] || 30
conn.options.open_timeout = options[:open_timeout] || 10
if block_given?
conn.adapter options[:adapter] || Faraday.default_adapter, &block
else
conn.adapter options[:adapter] || Faraday.default_adapter
end
end
end
|