Class: WeShipClient::Interactors::GetTracking
- Inherits:
-
Object
- Object
- WeShipClient::Interactors::GetTracking
- Defined in:
- lib/we_ship_client/interactors/get_tracking.rb
Overview
Class to interact with the /track API endpoint.
Constant Summary collapse
- ERRONEOUS_EXCEPTION_MSGS =
[ 'RQA Mapping', 'OQA Mapping', 'SML Mapping', 'Out for Delivery' ].freeze
Instance Method Summary collapse
-
#call ⇒ Entities::Responses::TrackResponse
Get the tracking response.
-
#initialize(auth_token:, track_request:, timeout: nil) ⇒ GetTracking
constructor
A new instance of GetTracking.
Constructor Details
#initialize(auth_token:, track_request:, timeout: nil) ⇒ GetTracking
Returns a new instance of GetTracking.
24 25 26 27 28 |
# File 'lib/we_ship_client/interactors/get_tracking.rb', line 24 def initialize(auth_token:, track_request:, timeout: nil) @auth_token = auth_token @request = track_request @timeout = timeout end |
Instance Method Details
#call ⇒ Entities::Responses::TrackResponse
Get the tracking response.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/we_ship_client/interactors/get_tracking.rb', line 35 def call response = client.http_client.post( "#{client.base_url}/track", data: request.to_hash, headers: { Authorization: "JWT #{auth_token}" } ) handle_exception(response) unless response.status == 200 json_response = JSON.parse(response.body, symbolize_names: true) handle_exception(response) if json_response[:results].nil? filter_results(json_response) modified_response(response_class.new(json_response)) end |