Class: Deliveries::Couriers::Envialia::Shipments::Trace::FormatResponse

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

Constant Summary collapse

STATUS_CODES =
{
  '0' => 'Documentado',
  '1' => 'En Tránsito',
  '2' => 'En Reparto',
  '3' => 'Incidencia',
  '4' => 'Entregado',
  '5' => 'Devuelto',
  '6' => 'Recanalizado',
  '8' => 'Destruido (P.O.Delegación)',
  '9' => 'Falta definitiva de expedición',
  '10' => 'Pendiente nuevo reparto',
  '11' => 'En CS destino',
  '12' => 'Recogeran en delegacion',
  '14' => 'Entrega Parcial',
  '15' => 'Tránsito 72H.',
  '16' => 'Pendiente de emisión'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response:) ⇒ FormatResponse

Returns a new instance of FormatResponse.



13
14
15
# File 'lib/deliveries/couriers/envialia/shipments/trace/format_response.rb', line 13

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

Instance Attribute Details

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/deliveries/couriers/envialia/shipments/trace/format_response.rb', line 35

def execute
  body = response.dig('Envelope', 'Body', 'WebServService___ConsEnvEstadosResponse', 'strEnvEstados')
  parsed_response = Hash.from_xml(body).dig('CONSULTA', 'ENV_ESTADOS')

  checkpoints = formatted_checkpoints(parsed_response)

  tracking_info_params = {}
  tracking_info_params[:courier_id] = 'envialia'
  tracking_info_params[:tracking_code] = nil
  tracking_info_params[:status] = checkpoints.last.try(:status)
  tracking_info_params[:checkpoints] = formatted_checkpoints(parsed_response)

  tracking_info_params
end