Class: CityboxApi::Utilities

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

Overview

module formany getter utilities

Instance Method Summary collapse

Constructor Details

#initializeUtilities

Returns a new instance of Utilities.



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

def initialize
  raise CityboxApi::INVALID_CREDENTIALS if CityboxApi.configuration.key == nil
    @user = CityboxApi.configuration.user
    @password = CityboxApi.configuration.key
end

Instance Method Details

#claim_status(claim_number) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/citybox_api/utilities.rb', line 126

def claim_status claim_number
  server_url = "http://b2b.correos.cl:8008/ServicioEstadoDeReclamosExterno/cch/ws/reclamos/implementacion/ServicioExternoEstadoDeReclamos.asmx"
  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>
          <consultaEstadoDeReclamo xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <numero>#{claim_number}</numero>
          </consultaEstadoDeReclamo>
        </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"]["consultaEstadoDeReclamoResponse"]["consultaEstadoDeReclamoResult"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#list_cityboxesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/citybox_api/utilities.rb', line 10

def list_cityboxes
  server_url = "http://b2b.correos.cl:8008/ServicioCityboxExterno/cch/ws/citybox/externo/implementacion/ServicioCityboxExterno.asmx"
  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>
          <listarCityboxDisponibles xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
          </listarCityboxDisponibles>
        </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"]["listarCityboxDisponiblesResponse"]["listarCityboxDisponiblesResult"]["CityboxTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#list_master_productsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/citybox_api/utilities.rb', line 31

def list_master_products
  server_url = "http://b2b.correos.cl:8008/ServicioProductosCorreosExterno/cch/ws/ProductosCorreos/externo/implementacion/ServicioExternoProductoCorreos.asmx"
  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>
          <listarMaestroProductos xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
          </listarMaestroProductos>
        </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"]["listarMaestroProductosResponse"]["listarMaestroProductosResult"]["ProductoTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#normalize_address(opts = {}) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/citybox_api/utilities.rb', line 96

def normalize_address opts={}
  server_url = "http://b2b.correos.cl:8008/ServicioNormalizacionExterno/cch/ws/distribucionGeografica/externo/implementacion/ServicioExternoNormalizacion.asmx"
  # default values
  opts[:request_id] ||= rand(10000)

  # check params
  CityboxApi.check_params [:full_address, :commune], opts

  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>
          <normalizarDireccion xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <id>#{opts[:request_id]}</id>
            <direccion>#{opts[:full_address]}</direccion>
            <comuna>#{opts[:commune]}</comuna>
          </normalizarDireccion>
        </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"]["normalizarDireccionResponse"]["normalizarDireccionResult"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#see_fivps(shipment_number) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/citybox_api/utilities.rb', line 74

def see_fivps shipment_number
  server_url = "http://b2b.correos.cl:8008/ServicioConsultaFivpsExterno/cch/ws/aduana/externo/implementacion/ServicioExternoConsultaFivps.asmx"
  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>
          <consultaFIVPS xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <numeroEnvio>#{shipment_number}</numeroEnvio>
          </consultaFIVPS>
        </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"]["consultaFIVPSResponse"]["consultaFIVPSResult"]["FivpsTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#see_scl_documents(shipment_number) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/citybox_api/utilities.rb', line 52

def see_scl_documents shipment_number
  server_url = "http://b2b.correos.cl:8008/ServicioConsultaAvisoDocumentoSCLExterno/cch/ws/externo/implementacion/ServicioExternoConsultaAvisoDocumentoSCL.asmx"
  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>
          <consultaDocumentosSCL xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <numeroEnvio>#{shipment_number}</numeroEnvio>
          </consultaDocumentosSCL>
        </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"]["consultaDocumentosSCLResponse"]["consultaDocumentosSCLResult"]["DocumentoSclTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end