Class: Deliveries::Couriers::Spring::Shipments::Trace::FormatResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/deliveries/couriers/spring/shipments/trace/format_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response:) ⇒ FormatResponse

Returns a new instance of FormatResponse.



11
12
13
# File 'lib/deliveries/couriers/spring/shipments/trace/format_response.rb', line 11

def initialize(response:)
  self.response = response
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/deliveries/couriers/spring/shipments/trace/format_response.rb', line 9

def response
  @response
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/deliveries/couriers/spring/shipments/trace/format_response.rb', line 15

def execute
  checkpoints = response[:Events].sort_by { |event| event[:DateTime] }

  tracking_info_params = {}
  tracking_info_params[:courier_id] = Deliveries::Couriers::Spring::COURIER_ID
  tracking_info_params[:tracking_code] = response[:TrackingNumber]
  tracking_info_params[:status] = status(checkpoints.last[:Code])
  tracking_info_params[:checkpoints] = formatted_checkpoints(checkpoints)

  tracking_info_params
end