Class: CityboxApi::Tariff

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

Overview

module for tariff services

Instance Method Summary collapse

Constructor Details

#initializeTariff

Returns a new instance of Tariff.



4
5
6
7
8
9
# File 'lib/citybox_api/tariff.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/ServicioTarificacionCEPEmpresasExterno/cch/ws/tarificacionCEP/externo/implementacion/ExternoTarificacion.asmx"
end

Instance Method Details

#apply_tariff_to_person(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
# File 'lib/citybox_api/tariff.rb', line 11

def apply_tariff_to_person opts={}
    server_url = "http://b2b.correos.cl:8008/ServicioTarificadorPersonasExterno/cch/ws/tarificacion/externo/implementacion/ServicioExternoTarificadorPersonas.asmx"

  # default values
  opts[:scope] ||= "1" # national scope

  # check_params
  CityboxApi.check_params [ :origin_iata, :destination_iata, :scope, :weight ], 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>
          <aplicarTarifaPersona xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <iataOrigen>#{opts[:origin_iata]}</iataOrigen>
            <iataDestino>#{opts[:destination_iata]}</iataDestino>
            <cobertura>#{opts[:scope]}</cobertura>
            <peso>#{opts[:weight].to_f}</peso>
          </aplicarTarifaPersona>
        </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"]["aplicarTarifaPersonaResponse"]["aplicarTarifaPersonaResult"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#see_products_by_clientObject



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

def see_products_by_client
  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>
          <consultaProductosPorCliente xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
          </consultaProductosPorCliente>
        </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"]["consultaProductosPorClienteResponse"]["consultaProductosPorClienteResult"]["ProductoTo"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#see_scope(opts = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/citybox_api/tariff.rb', line 42

def see_scope opts={}
  # default values
  opts[:sender_country] ||= "056" # chilean by default
  opts[:receiver_country] ||= "056" # chilean by default
  opts[:insured_import_value] ||= "NO"

  # check params
  CityboxApi.check_params [ :sender_country, :sender_commune, :receiver_country, :receiver_commune, :payment_type, :number_of_pieces, :kilograms ], 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>
          <consultaCobertura xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <consultaCobertura>
              <ExtensionData />
              <CodigoPostalDestinatario>#{opts[:receiver_postal_code]}</CodigoPostalDestinatario>
              <CodigoPostalRemitente>#{opts[:sender_postal_code]}</CodigoPostalRemitente>
              <ComunaDestino>#{opts[:receiver_commune]}</ComunaDestino>
              <ComunaRemitente>#{opts[:sender_commune]}</ComunaRemitente>
              <ImporteReembolso>#{opts[:import_refund]}</ImporteReembolso>
              <ImporteValorAsegurado>#{opts[:insured_import_value]}</ImporteValorAsegurado>
              <Kilos>#{opts[:kilograms]}</Kilos>
              <NumeroTotalPieza>#{opts[:number_of_pieces]}</NumeroTotalPieza>
              <PaisDestinatario>#{opts[:receiver_country]}</PaisDestinatario>
              <PaisRemitente>#{opts[:sender_country]}</PaisRemitente>
              <TipoPortes>#{opts[:payment_type]}</TipoPortes>
              <Volumen>#{opts[:volume]}</Volumen>
            </consultaCobertura>
          </consultaCobertura>
        </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"]["consultaCoberturaResponse"]["consultaCoberturaResult"]["ServicioTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#see_scope_by_product(opts = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
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
125
126
127
# File 'lib/citybox_api/tariff.rb', line 85

def see_scope_by_product opts={}
  # default values
  opts[:sender_country] ||= "056" # chilean by default
  opts[:receiver_country] ||= "056" # chilean by default
  opts[:insured_import_value] ||= "NO"

  # check params
  CityboxApi.check_params [ :service_code, :sender_country, :sender_commune, :receiver_country, :receiver_commune, :payment_type, :number_of_pieces, :kilograms ], 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>
          <consultaCoberturaPorProducto xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <consultaCobertura>
              <ExtensionData />
              <CodigoPostalDestinatario>#{opts[:receiver_postal_code]}</CodigoPostalDestinatario>
              <CodigoPostalRemitente>#{opts[:sender_postal_code]}</CodigoPostalRemitente>
              <CodigoServicio>#{opts[:service_code]}</CodigoServicio>
              <ComunaDestino>#{opts[:receiver_commune]}</ComunaDestino>
              <ComunaRemitente>#{opts[:sender_commune]}</ComunaRemitente>
              <ImporteReembolso>#{opts[:import_refund]}</ImporteReembolso>
              <ImporteValorAsegurado>#{opts[:insured_import_value]}</ImporteValorAsegurado>
              <Kilos>#{opts[:kilograms]}</Kilos>
              <NumeroTotalPieza>#{opts[:number_of_pieces]}</NumeroTotalPieza>
              <PaisDestinatario>#{opts[:receiver_country]}</PaisDestinatario>
              <PaisRemitente>#{opts[:sender_country]}</PaisRemitente>
              <TipoPortes>#{opts[:payment_type]}</TipoPortes>
              <Volumen>#{opts[:volume]}</Volumen>
            </consultaCobertura>
          </consultaCoberturaPorProducto>
        </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"]["consultaCoberturaPorProductoResponse"]["consultaCoberturaPorProductoResult"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end