Class: PriceHubble::Client::Base
- Inherits:
-
Object
- Object
- PriceHubble::Client::Base
- Includes:
- Utils::Request, Utils::Response, Utils::Bangers, Utils::Decision
- Defined in:
- lib/price_hubble/client/base.rb
Overview
The base API client class definition. It bundles all the separated application logic on a low level.
Direct Known Subclasses
Constant Summary
Constants included from Utils::Request
Instance Method Summary collapse
-
#configure(con) ⇒ Object
Configure the connection instance in a generic manner.
-
#connection ⇒ Faraday::Connection
Create a new Faraday connection on the first shot, and pass the cached connection object on subsequent calls.
Methods included from Utils::Bangers
Methods included from Utils::Decision
Methods included from Utils::Response
#assign_entity, #bang_entity, #failed?, #status?
Methods included from Utils::Request
#use_authentication, #use_default_context
Instance Method Details
#configure(con) ⇒ Object
Configure the connection instance in a generic manner. Each client can modify the connection in a specific way, when the application requires special handling. Just overwrite the configure
method, and call super(con). Here is a full example:
def configure(con)
super(con)
con.request :url_encoded
con.response :logger
con.adapter Faraday.default_adapter
end
rubocop:disable Metrics/MethodLength because of the middleware list
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/price_hubble/client/base.rb', line 28 def configure(con) con.use :instrumentation # The definition order is execution order con.request :ph_data_sanitization con.request :ph_default_headers con.request :json con.request :multipart con.request :url_encoded # The definition order is reverse to the execution order con.response :ph_recursive_open_struct con.response :ph_data_sanitization con.response :dates con.response :json, content_type: /\bjson$/ con.response :follow_redirects con.adapter Faraday.default_adapter end |
#connection ⇒ Faraday::Connection
Create a new Faraday connection on the first shot, and pass the cached connection object on subsequent calls.
53 54 55 56 |
# File 'lib/price_hubble/client/base.rb', line 53 def connection @connection ||= Faraday.new(url: PriceHubble.configuration.base_url, &method(:configure)) end |