Class: ResoWebApi::BaseClient

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/reso_web_api/base_client.rb

Overview

Base class for Faraday-based HTTP clients

Direct Known Subclasses

Authentication::AuthStrategy, Client

Constant Summary collapse

USER_AGENT =
"Reso Web API Ruby Gem v#{VERSION}"

Instance Method Summary collapse

Instance Method Details

#connection(&block) ⇒ Faraday::Connection

Return the Faraday::Connection object for this client. Yields the connection object being constructed (for customzing middleware).

Returns:

  • (Faraday::Connection)

    The connection object



20
21
22
23
24
25
26
27
# File 'lib/reso_web_api/base_client.rb', line 20

def connection(&block)
  @connection ||= Faraday.new(url: endpoint, headers: headers) do |conn|
    conn.request :url_encoded
    conn.response :logger, logger
    yield conn if block_given?
    conn.adapter adapter unless conn.builder.send(:adapter_set?)
  end
end

#headersHash

Return the headers to be sent with every request.

Returns:

  • (Hash)

    The request headers.



31
32
33
34
35
# File 'lib/reso_web_api/base_client.rb', line 31

def headers
  {
    :user_agent => user_agent
  }.merge(@headers)
end