Class: ResoWebApi::BaseClient
- Inherits:
-
Object
- Object
- ResoWebApi::BaseClient
- Extended by:
- Dry::Initializer
- Defined in:
- lib/reso_web_api/base_client.rb
Overview
Base class for Faraday-based HTTP clients
Direct Known Subclasses
Constant Summary collapse
- USER_AGENT =
"Reso Web API Ruby Gem v#{VERSION}"
Instance Method Summary collapse
-
#connection(&block) ⇒ Faraday::Connection
Return the Faraday::Connection object for this client.
-
#headers ⇒ Hash
Return the headers to be sent with every request.
Instance Method Details
#connection(&block) ⇒ Faraday::Connection
Return the Faraday::Connection object for this client. Yields the connection object being constructed (for customzing middleware).
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 |
#headers ⇒ Hash
Return the headers to be sent with every request.
31 32 33 34 35 |
# File 'lib/reso_web_api/base_client.rb', line 31 def headers { :user_agent => user_agent }.merge(@headers) end |