Class: WeShipClient::Interactors::GetTracking

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(auth_token:, track_request:, timeout: nil) ⇒ GetTracking

Returns a new instance of GetTracking.

Parameters:

  • auth_token (String)

    A token generated by TokenClient

  • track_request (Entities::TrackRequest)

    The request payload

  • timeout (Integer, nil) (defaults to: nil)

    The request timeout



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

#callEntities::Responses::TrackResponse

Get the tracking response.

Returns:

Raises:



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