Class: CityboxApi::TakeUps

Inherits:
Object
  • Object
show all
Defined in:
lib/citybox_api/take_ups.rb

Overview

module for take ups services

Instance Method Summary collapse

Constructor Details

#initializeTakeUps

Returns a new instance of TakeUps.



4
5
6
7
8
9
# File 'lib/citybox_api/take_ups.rb', line 4

def initialize
  raise CityboxApi::INVALID_CREDENTIALS if CityboxApi.configuration.key == nil
    @user = CityboxApi.configuration.user
    @password = CityboxApi.configuration.key
    @server_url = "http://b2b.correos.cl:8008/ServicioRetiroEnvioExterno/cch/ws/retirosCEP/externo/implementacion/ServicioExternoRetiro.asmx"
end

Instance Method Details

#register(opts = {}) ⇒ Object



11
12
13
14
15
16
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
45
46
47
48
49
50
51
52
53
54
# File 'lib/citybox_api/take_ups.rb', line 11

def register opts={}
  # default values
  opts[:sender_country] ||= "056"

  # check params
  CityboxApi.check_params [ :admission_code, :sender_code, :sender_contact_person, :sender_contact_phone, :take_up_date,
                :take_up_from_hour, :take_up_to_hour ], opts

  # format for date: aaaa-mm-dd
  xml = "<?xml version='1.0' encoding='utf-8'?>
      <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
        <soap:Body>
          <registrarRetiro xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <retiroTO>
              <ExtensionData />
              <CodigoAdmision>#{opts[:admission_code]}</CodigoAdmision>
              <ClienteRemitente>#{opts[:sender_code]}</ClienteRemitente>
              <CentroRemitente></CentroRemitente>
              <NombreRemitente>#{opts[:sender_name]}</NombreRemitente>
              <DireccionRemitente>#{opts[:sender_address]}</DireccionRemitente>
              <PaisRemitente>#{opts[:sender_country]}</PaisRemitente>
              <CodigoPostalRemitente>#{opts[:sender_postal_code]}</CodigoPostalRemitente>
              <ComunaRemitente>#{opts[:sender_commune]}</ComunaRemitente>
              <RutRemitente>#{opts[:sender_rut]}</RutRemitente>
              <PersonaContactoRemitente>#{opts[:sender_contact_person]}</PersonaContactoRemitente>
              <TelefonoContactoRemitente>#{opts[:sender_contact_phone]}</TelefonoContactoRemitente>
              <FechaRetiro>#{opts[:take_up_date]}</FechaRetiro>
              <HoraDesde>#{opts[:take_up_from_hour]}</HoraDesde>
              <HoraHasta>#{opts[:take_up_to_hour]}</HoraHasta>
            </retiroTO>
          </registrarRetiro>
        </soap:Body>
      </soap:Envelope>"

  begin
    xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
    json_response = Crack::XML.parse(xml_response)
    json_response["soap:Envelope"]["soap:Body"]["registrarRetiroResponse"]["registrarRetiroResult"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end