Class: ErpIntegration::Fulfil::Client
- Inherits:
-
Object
- Object
- ErpIntegration::Fulfil::Client
- Defined in:
- lib/erp_integration/fulfil/client.rb
Constant Summary collapse
- FORMATTER =
ErpIntegration::Middleware::Formatter
Instance Attribute Summary collapse
-
#api_keys_pool ⇒ Object
readonly
Returns the value of attribute api_keys_pool.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#connection ⇒ Faraday::Connection
Sets up the Faraday connection to talk to the Fulfil API.
-
#faraday_adapter ⇒ Symbol
Sets the default adapter for the Faraday Connection.
-
#rotate_statuses ⇒ Object
writeonly
Sets the attribute rotate_statuses.
Instance Method Summary collapse
-
#initialize(api_keys_pool:, base_url:, logger: nil) ⇒ Client
constructor
A new instance of Client.
-
#version ⇒ String
Sets the default version for the Fulfil API endpoints.
Constructor Details
#initialize(api_keys_pool:, base_url:, logger: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 |
# File 'lib/erp_integration/fulfil/client.rb', line 11 def initialize(api_keys_pool:, base_url:, logger: nil) @api_keys_pool = api_keys_pool @base_url = base_url.strip @logger = logger end |
Instance Attribute Details
#api_keys_pool ⇒ Object (readonly)
Returns the value of attribute api_keys_pool.
8 9 10 |
# File 'lib/erp_integration/fulfil/client.rb', line 8 def api_keys_pool @api_keys_pool end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/erp_integration/fulfil/client.rb', line 8 def base_url @base_url end |
#connection ⇒ Faraday::Connection
Sets up the Faraday connection to talk to the Fulfil API.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/erp_integration/fulfil/client.rb', line 25 def connection @connection ||= Faraday.new(url: base_url) do |faraday| faraday.headers = default_headers faraday.request :json_encode # Encode request bodies as JSON faraday.response :json_decode # Decode response bodies as JSON # Custom error handling for the error response faraday.use :error_handling # Custom middleware for rotating API keys faraday.use :api_keys_rotation, # Custom middleware for logging requests and responses faraday.use :custom_logger, @logger, formatter: FORMATTER if @logger # Adapter definition should be last in order to make the json parsers be loaded correctly faraday.adapter faraday_adapter end end |
#faraday_adapter ⇒ Symbol
Sets the default adapter for the Faraday Connection.
19 20 21 |
# File 'lib/erp_integration/fulfil/client.rb', line 19 def faraday_adapter @faraday_adapter ||= Faraday.default_adapter end |
#rotate_statuses=(value) ⇒ Object (writeonly)
Sets the attribute rotate_statuses
9 10 11 |
# File 'lib/erp_integration/fulfil/client.rb', line 9 def rotate_statuses=(value) @rotate_statuses = value end |
Instance Method Details
#version ⇒ String
Sets the default version for the Fulfil API endpoints.
58 59 60 |
# File 'lib/erp_integration/fulfil/client.rb', line 58 def version @version ||= 'v2' end |