class Deliveries::Couriers::MondialRelay::Shipments::Trace::FormatResponse
Attributes
response[RW]
Public Class Methods
new(response:)
click to toggle source
# File lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb, line 11 def initialize(response:) self.response = response end
Public Instance Methods
execute()
click to toggle source
# File lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb, line 15 def execute statuses = response[:tracing][:ret_wsi2_sub_tracing_colis_detaille].delete_if do |key, _value| key[:libelle].blank? end tracking_info_params = {} tracking_info_params[:courier_id] = 'mondial_relay' tracking_info_params[:status] = shipment_status(response[:stat].to_i, last_status(statuses)) tracking_info_params[:checkpoints] = formatted_checkpoints(statuses) tracking_info_params end
Private Instance Methods
checkpoint_status(message)
click to toggle source
# File lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb, line 71 def checkpoint_status(message) case message when 'Disponible en el Punto Pack', 'Recepcionado en el Punto Pack', 'DISPONIBLE AU POINT RELAIS', 'PRISE EN CHARGE POINT RELAIS' :in_collection_point when 'Recogido en agencia Punto Pack', 'RÉCEPTION DES DONNÉES' :registered when 'Recogido en el hub', 'En reparto', 'PRISE EN CHARGE EN AGENCE', 'COLIS REMIS AU LIVREUR' :in_transit when 'Paquete entregado al Destinata', 'Liquidado en Ensena', 'COLIS LIVRÉ' :delivered else :unknown_status end end
formatted_checkpoint(status)
click to toggle source
# File lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb, line 45 def formatted_checkpoint(status) Deliveries::Checkpoint.new( status: checkpoint_status(status[:libelle]), location: status[:emplacement], tracked_at: Time.zone.strptime("#{status[:date]} #{status[:heure]}", '%d/%m/%y %H:%M'), description: status[:libelle] ) end
formatted_checkpoints(statuses)
click to toggle source
# File lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb, line 36 def formatted_checkpoints(statuses) checkpoints = [] statuses.each do |status| checkpoints << formatted_checkpoint(status) end checkpoints end
last_status(statuses)
click to toggle source
# File lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb, line 30 def last_status(statuses) statuses.map { |s| s[:libelle] } .compact .last end
shipment_status(stat, last_checkpoint_status)
click to toggle source
# File lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb, line 54 def shipment_status(stat, last_checkpoint_status) case stat when 80 :registered when 82 :delivered when 81 if ['Disponible en el Punto Pack', 'DISPONIBLE AU POINT RELAIS'].include?(last_checkpoint_status) :in_collection_point else :in_transit end else :unknown_status end end