Class: Deliveries::Couriers::CorreosExpress::Pickups::Trace

Inherits:
Object
  • Object
show all
Defined in:
lib/deliveries/couriers/correos_express/pickups/trace.rb,
lib/deliveries/couriers/correos_express/pickups/trace/format_response.rb

Defined Under Namespace

Classes: FormatResponse

Constant Summary collapse

WSDL_LIVE_PATH =
File.expand_path('../..', __dir__) + '/correos_express/pickups/trace/correos.wsdl'.freeze
WSDL_TEST_PATH =
File.expand_path('../..', __dir__) + '/correos_express/pickups/trace/correos.test.wsdl'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracking_code:) ⇒ Trace

Returns a new instance of Trace.



13
14
15
# File 'lib/deliveries/couriers/correos_express/pickups/trace.rb', line 13

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

Instance Attribute Details

#tracking_codeObject

Returns the value of attribute tracking_code.



11
12
13
# File 'lib/deliveries/couriers/correos_express/pickups/trace.rb', line 11

def tracking_code
  @tracking_code
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/deliveries/couriers/correos_express/pickups/trace.rb', line 17

def execute
  params = {
    'solicitante' => CorreosExpress.config(:client_code),
    'dato' => tracking_code,
    'password' => '',
    'codCliente' => CorreosExpress.config(:pickup_receiver_code)
  }

  basic_auth = [
    CorreosExpress.config(:username),
    CorreosExpress.config(:password)
  ]

  client = Savon.client wsdl: CorreosExpress.live? ? WSDL_LIVE_PATH : WSDL_TEST_PATH,
                        basic_auth: basic_auth,
                        logger: Deliveries.logger,
                        log: Deliveries.debug

  response = client.call(:seguimiento_recogida, message: params)

  response_result = response.body[:seguimiento_recogida_response][:return]
  unless response_result && response_result[:recogida].present?
    raise Deliveries::APIError,
          response_result[:mensaje_retorno].to_s.strip
  end

  response_result
end