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


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

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.


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

def headers
  {
    :user_agent => user_agent
  }
end