Class: ErpIntegration::Fulfil::Client
- Inherits:
-
Object
- Object
- ErpIntegration::Fulfil::Client
- Defined in:
- lib/erp_integration/fulfil/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#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.
-
#merchant_id ⇒ Object
readonly
Returns the value of attribute merchant_id.
Instance Method Summary collapse
-
#base_url ⇒ String
Generates the url prefix for the Faraday connection client.
-
#initialize(api_key:, merchant_id:, logger: nil) ⇒ Client
constructor
A new instance of Client.
-
#version ⇒ String
Sets the default version for the Fulfil API endpoints.
Constructor Details
#initialize(api_key:, merchant_id:, logger: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/erp_integration/fulfil/client.rb', line 9 def initialize(api_key:, merchant_id:, logger: nil) @api_key = api_key @merchant_id = merchant_id @logger = logger end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/erp_integration/fulfil/client.rb', line 6 def api_key @api_key end |
#connection ⇒ Faraday::Connection
Sets up the Faraday connection to talk to the Fulfil API.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/erp_integration/fulfil/client.rb', line 29 def connection @connection ||= Faraday.new(url: base_url) do |faraday| faraday.headers = default_headers faraday.request :json # Encode request bodies as JSON faraday.request :retry # Retry transient failures faraday.response :follow_redirects faraday.response :json # Decode response bodies as JSON # Notice that logging headers will expose sensitive information # like api-key. To avoid use filters: # https://lostisland.github.io/faraday/middleware/logger faraday.response :logger, @logger, { headers: false, bodies: true } if @logger # Custom error handling for the error response faraday.use ErpIntegration::Middleware::ErrorHandling # 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.
23 24 25 |
# File 'lib/erp_integration/fulfil/client.rb', line 23 def faraday_adapter @faraday_adapter ||= Faraday.default_adapter end |
#merchant_id ⇒ Object (readonly)
Returns the value of attribute merchant_id.
6 7 8 |
# File 'lib/erp_integration/fulfil/client.rb', line 6 def merchant_id @merchant_id end |
Instance Method Details
#base_url ⇒ String
Generates the url prefix for the Faraday connection client.
17 18 19 |
# File 'lib/erp_integration/fulfil/client.rb', line 17 def base_url "https://#{merchant_id}.fulfil.io/" end |
#version ⇒ String
Sets the default version for the Fulfil API endpoints.
64 65 66 |
# File 'lib/erp_integration/fulfil/client.rb', line 64 def version @version ||= 'v2' end |