Class: SekoEcomAPI::OmniParcelClient
- Inherits:
-
Object
- Object
- SekoEcomAPI::OmniParcelClient
- Includes:
- Client
- Defined in:
- lib/seko_ecom_api/clients/omni_parcel_client.rb
Constant Summary collapse
- BASE_URL =
'https://api.omniparcel.com/'
- TEST_BASE_URL =
'https://staging.omniparcel.com/'
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#conn_opts ⇒ Object
readonly
Returns the value of attribute conn_opts.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(access_key:, adapter: :http, test: false, conn_opts: {}) ⇒ OmniParcelClient
constructor
A new instance of OmniParcelClient.
- #retrieve_rates(params) ⇒ Object
Methods included from Client
Constructor Details
#initialize(access_key:, adapter: :http, test: false, conn_opts: {}) ⇒ OmniParcelClient
Returns a new instance of OmniParcelClient.
14 15 16 17 18 19 |
# File 'lib/seko_ecom_api/clients/omni_parcel_client.rb', line 14 def initialize(access_key:, adapter: :http, test: false, conn_opts: {}) @access_key = access_key @adapter = adapter @test = test @conn_opts = conn_opts end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
12 13 14 |
# File 'lib/seko_ecom_api/clients/omni_parcel_client.rb', line 12 def access_key @access_key end |
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
12 13 14 |
# File 'lib/seko_ecom_api/clients/omni_parcel_client.rb', line 12 def adapter @adapter end |
#conn_opts ⇒ Object (readonly)
Returns the value of attribute conn_opts.
12 13 14 |
# File 'lib/seko_ecom_api/clients/omni_parcel_client.rb', line 12 def conn_opts @conn_opts end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
12 13 14 |
# File 'lib/seko_ecom_api/clients/omni_parcel_client.rb', line 12 def test @test end |
Instance Method Details
#connection ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/seko_ecom_api/clients/omni_parcel_client.rb', line 31 def connection @connection ||= Faraday.new do |conn| conn.url_prefix = test ? TEST_BASE_URL : BASE_URL conn..merge!(conn_opts) conn.headers['Access_Key'] = access_key conn.request :json conn.response :json, content_type: 'application/json' conn.response :encoding conn.adapter adapter end end |
#retrieve_rates(params) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/seko_ecom_api/clients/omni_parcel_client.rb', line 21 def retrieve_rates(params) response = handle_response post_request('ratesqueryv1/availablerates', params: parse_params(params)) available_rates = response['available']&.map { |rate| Rate.new(rate) } rejected_rates = response['rejected']&.map { |rate| Rate.new(rate) } hidden_rates = response['hidden']&.map { |rate| Rate.new(rate) } Struct.new(:available, :rejected, :hidden).new(available_rates, rejected_rates, hidden_rates) end |