citybox_api 0.1.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODc1ZDhkZTUyODQyYzgwYTc0ODVjZTIwMmM0ZjA2NjUzZjMyODE5Yg==
4
+ NmFhOWYwMmI4NDQ2YzA0NTdjMmVjNGI3M2NlM2QyNzFhMGY0YTVlOQ==
5
5
  data.tar.gz: !binary |-
6
- ZDg5ZDE0OTgwZWM1MTIzMzE3OTc2Y2U5MmRjNmRkMDBmNzllNTYzOA==
6
+ NzdkZDQ0ZWM2YWI4OWEwNWE3MDQxYzA5N2IzZjliZDUzZjJkN2UyMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWI4YTJhYTllNjNjYzIyZWFlYWJjNzQwOTA2ZGJlYTczYjQ4OGE4ZTk4Yjk4
10
- ODgzNTZlOGQyZjFkYTAxMGFjZDJmNmZiMDIxNmFlOGNiODdiNTJkNzM4NjZh
11
- ZjQ0ODc4NzQ4YjQ0NWRmY2UwZGRlMmRjYjFmNjY3OTZjOGFmZWQ=
9
+ NzM0NjNmNWJjMGRmMTE4NDJhODc0Zjk4NjU0YTA5YWE3YjI5N2QwNTg2Yjkx
10
+ ODVhYTI1M2IzZGQ4NGMzODM5NmMzYWZmMjI5MGJlMWQzMTRlMjI4MzBlMThi
11
+ Yjg2MjhlNmU5NWMzYmExNTZjODk4YjRmNmJiNzMxNzg4NDI1ZTY=
12
12
  data.tar.gz: !binary |-
13
- MjcxZjMwNzQ0YTk1ZWQyYzc0YjkzNjQ4NjdhOTZiMmI1ZTA2ZWQyOTQwMTYw
14
- MzI4ODAzZGZhNDg2ZTJkZDI3NjJlOTdjYzAzNWM1Y2FhODM0YjljOGQ4NGMx
15
- Zjk2NTNmMDU4ZmE5YzYzMWU4ZDk1MmI4YTcwNDRiN2M2ZDgwM2E=
13
+ YTlmZTAzYjAyODE3YTEyZDQ0MWVjNWFmZjA4ZjY5ZjdjMzZhY2Q4ZTkyYTE5
14
+ ZTAzNmE1YmQ2Y2I2ZDg3YjY3NmQ1MTVjMDQwYWMzZjhlZjJiM2Y5ZThlNTU5
15
+ YzkxZjUyODA4MDg3NjJhMmMwNDFkNjg4YmM4MTUzZDc0YWJjYmY=
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /config.rb
@@ -23,9 +23,8 @@ module CityboxApi
23
23
  xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
24
24
  json_response = Crack::XML.parse(xml_response)
25
25
  json_response["soap:Envelope"]["soap:Body"]["listarTodasLasSucursalesResponse"]["listarTodasLasSucursalesResult"]["SucursalTO"]
26
- rescue => e
27
- puts e
28
- return nil
26
+ rescue => error
27
+ return CityboxApi.catch_error(error)
29
28
  end
30
29
  end
31
30
 
@@ -46,9 +45,8 @@ module CityboxApi
46
45
  xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
47
46
  json_response = Crack::XML.parse(xml_response)
48
47
  json_response["soap:Envelope"]["soap:Body"]["listarSucursalesSegunComunaResponse"]["listarSucursalesSegunComunaResult"]["SucursalTO"]
49
- rescue => e
50
- puts e
51
- return nil
48
+ rescue => error
49
+ return CityboxApi.catch_error(error)
52
50
  end
53
51
  end
54
52
 
@@ -76,9 +74,8 @@ module CityboxApi
76
74
  xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
77
75
  json_response = Crack::XML.parse(xml_response)
78
76
  json_response["soap:Envelope"]["soap:Body"]["consultaSucursalMasCercanaResponse"]["consultaSucursalMasCercanaResult"]
79
- rescue => e
80
- puts e
81
- return nil
77
+ rescue => error
78
+ return CityboxApi.catch_error(error)
82
79
  end
83
80
  end
84
81
  end
@@ -24,9 +24,8 @@ module CityboxApi
24
24
  xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
25
25
  json_response = Crack::XML.parse(xml_response)
26
26
  json_response["soap:Envelope"]["soap:Body"]["listarTodasLasRegionesResponse"]["listarTodasLasRegionesResult"]["RegionTO"]
27
- rescue => e
28
- puts e
29
- return nil
27
+ rescue => error
28
+ return CityboxApi.catch_error(error)
30
29
  end
31
30
  end
32
31
 
@@ -46,9 +45,8 @@ module CityboxApi
46
45
  xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
47
46
  json_response = Crack::XML.parse(xml_response)
48
47
  json_response["soap:Envelope"]["soap:Body"]["listarTodasLasComunasResponse"]["listarTodasLasComunasResult"]["ComunaTO"]
49
- rescue => e
50
- puts e
51
- return nil
48
+ rescue => error
49
+ return CityboxApi.catch_error(error)
52
50
  end
53
51
  end
54
52
 
@@ -69,9 +67,8 @@ module CityboxApi
69
67
  xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
70
68
  json_response = Crack::XML.parse(xml_response)
71
69
  json_response["soap:Envelope"]["soap:Body"]["listarComunasSegunRegionResponse"]["listarComunasSegunRegionResult"]["ComunaTO"]
72
- rescue => e
73
- puts e
74
- return nil
70
+ rescue => error
71
+ return CityboxApi.catch_error(error)
75
72
  end
76
73
  end
77
74
  end
@@ -0,0 +1,141 @@
1
+ module CityboxApi
2
+ # module for shipments services
3
+ class Shipments
4
+ def initialize
5
+ raise CityboxApi::INVALID_CREDENTIALS if CityboxApi.configuration.key == nil
6
+ @user = CityboxApi.configuration.user
7
+ @password = CityboxApi.configuration.key
8
+ end
9
+
10
+ # sent an allow shipping request
11
+ def allow_shipment opts={}
12
+ server_url = "http://b2b.correos.cl:8008/ServicioAdmisionCEPExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoAdmisionCEP.asmx"
13
+ opts = check_shipment_opts opts
14
+ xml = shipment_xml "admitirEnvio", opts
15
+
16
+ begin
17
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
18
+ json_response = Crack::XML.parse(xml_response)
19
+ json_response["soap:Envelope"]["soap:Body"]["admitirEnvioResponse"]["admitirEnvioResult"]
20
+ rescue => error
21
+ return CityboxApi.catch_error(error)
22
+ end
23
+ end
24
+
25
+
26
+ def validate_shipment opts={}
27
+ server_url = "http://b2b.correos.cl:8008/ServicioValidacionAdmisionCEPExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoValidaAdmisionCEP.asmx"
28
+ opts = check_shipment_opts opts
29
+ xml = shipment_xml "validarEnvio", opts
30
+
31
+ begin
32
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
33
+ json_response = Crack::XML.parse(xml_response)
34
+ json_response["soap:Envelope"]["soap:Body"]["validarEnvioResponse"]["validarEnvioResult"]
35
+ rescue => error
36
+ return CityboxApi.catch_error(error)
37
+ end
38
+ end
39
+
40
+ def cancel_shipment opts={}
41
+ server_url = "http://b2b.correos.cl:8008/ServicioAnulacionExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoAnulacionEnvio.asmx"
42
+
43
+ #check params
44
+ CityboxApi.check_params [ :shipment_number, :admission_code, :sender_code ], opts
45
+
46
+
47
+ xml = "<?xml version='1.0' encoding='utf-8'?>
48
+ <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/'>
49
+ <soap:Body>
50
+ <anularEnvio xmlns='http://tempuri.org/'>
51
+ <usuario>#{@user}</usuario>
52
+ <contrasena>#{@password}</contrasena>
53
+ <numeroEnvio>#{opts[:shipment_number]}</numeroEnvio>
54
+ <codigoAdmision>#{opts[:admission_code]}</codigoAdmision>
55
+ <clienteRemitente>#{opts[:sender_code]}</clienteRemitente>
56
+ </anularEnvio>
57
+ </soap:Body>
58
+ </soap:Envelope>"
59
+
60
+ begin
61
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
62
+ json_response = Crack::XML.parse(xml_response)
63
+ json_response["soap:Envelope"]["soap:Body"]["anularEnvioResponse"]["anularEnvioResult"]
64
+ rescue => error
65
+ return CityboxApi.catch_error(error)
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def check_shipment_opts opts
72
+ #default values
73
+ opts[:sender_country] ||= "056" #chile
74
+ opts[:receiver_country] ||= "056" #chile
75
+ opts[:declared_import_value] ||= "NO"
76
+ opts[:destination_email] ||= "NO"
77
+ opts[:success_return] ||= "N"
78
+ opts[:documents_number] ||= 0
79
+ opts[:secure_payment] ||= "N"
80
+
81
+ #check params
82
+ CityboxApi.check_params [
83
+ :admission_code, :sender_code, :sender_street, :sender_commune, :sender_contact_person, :receiver_name,
84
+ :receiver_street, :receiver_commune, :service_code, :pieces_number, :kilograms, :reference_number,
85
+ :declared_import_value, :payment_type
86
+ ], opts
87
+
88
+ return opts
89
+ end
90
+
91
+ def shipment_xml service_name, opts={}
92
+ "<?xml version='1.0' encoding='utf-8'?>
93
+ <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/'>
94
+ <soap:Body>
95
+ <#{service_name} xmlns='http://tempuri.org/'>
96
+ <usuario>#{@user}</usuario>
97
+ <contrasena>#{@password}</contrasena>
98
+ <admisionTo>
99
+ <ExtensionData />
100
+ <CodigoAdmision>#{opts[:admission_code]}</CodigoAdmision>
101
+ <ClienteRemitente>#{opts[:sender_code]}</ClienteRemitente>
102
+ <NombreRemitente>#{opts[:sender_name]}</NombreRemitente>
103
+ <DireccionRemitente>#{opts[:sender_street]}</DireccionRemitente>
104
+ <PaisRemitente>#{opts[:sender_country]}</PaisRemitente>
105
+ <CodigoPostalRemitente></CodigoPostalRemitente>
106
+ <ComunaRemitente>#{opts[:sender_commune]}</ComunaRemitente>
107
+ <RutRemitente>#{opts[:sender_rut]}</RutRemitente>
108
+ <PersonaContactoRemitente>#{opts[:sender_contact_person]}</PersonaContactoRemitente>
109
+ <TelefonoContactoRemitente>#{opts[:sender_contact_phone]}</TelefonoContactoRemitente>
110
+ <ClienteDestinatario></ClienteDestinatario>
111
+ <CentroDestinatario></CentroDestinatario>
112
+ <NombreDestinatario>#{opts[:receiver_name]}</NombreDestinatario>
113
+ <DireccionDestinatario>#{opts[:receiver_street]}</DireccionDestinatario>
114
+ <PaisDestinatario>#{opts[:receiver_country]}</PaisDestinatario>
115
+ <CodigoPostalDestinatario></CodigoPostalDestinatario>
116
+ <ComunaDestinatario>#{opts[:receiver_commune]}</ComunaDestinatario>
117
+ <RutDestinatario>#{opts[:receiver_rut]}</RutDestinatario>
118
+ <PersonaContactoDestinatario>#{opts[:receiver_contact_person]}</PersonaContactoDestinatario>
119
+ <TelefonoContactoDestinatario>#{opts[:receiver_contact_phone].to_i}</TelefonoContactoDestinatario>
120
+ <CodigoServicio>#{opts[:service_code]}</CodigoServicio>
121
+ <NumeroTotalPiezas>#{opts[:pieces_number].to_i}</NumeroTotalPiezas>
122
+ <Kilos>#{opts[:kilograms]}</Kilos>
123
+ <Volumen>#{opts[:volume].to_i}</Volumen>
124
+ <NumeroReferencia>#{opts[:reference_number]}</NumeroReferencia>
125
+ <ImporteReembolso>0</ImporteReembolso>
126
+ <ImporteValorDeclarado>#{opts[:declared_import_value].to_i}</ImporteValorDeclarado>
127
+ <TipoPortes>#{opts[:payment_type]}</TipoPortes>
128
+ <Observaciones>#{opts[:observations]}</Observaciones>
129
+ <Observaciones2></Observaciones2>
130
+ <EmailDestino>#{opts[:destination_email]}</EmailDestino>
131
+ <TipoMercancia>#{opts[:commodity_type]}</TipoMercancia>
132
+ <DevolucionConforme>#{opts[:success_return]}</DevolucionConforme>
133
+ <NumeroDocumentos>#{opts[:documents_number].to_i}</NumeroDocumentos>
134
+ <PagoSeguro>#{opts[:secure_payment]}</PagoSeguro>
135
+ </admisionTo>
136
+ </#{service_name}>
137
+ </soap:Body>
138
+ </soap:Envelope>"
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,56 @@
1
+ module CityboxApi
2
+ # module for take ups services
3
+ class TakeUps
4
+ def initialize
5
+ raise CityboxApi::INVALID_CREDENTIALS if CityboxApi.configuration.key == nil
6
+ @user = CityboxApi.configuration.user
7
+ @password = CityboxApi.configuration.key
8
+ @server_url = "http://b2b.correos.cl:8008/ServicioRetiroEnvioExterno/cch/ws/retirosCEP/externo/implementacion/ServicioExternoRetiro.asmx"
9
+ end
10
+
11
+ def register opts={}
12
+ # default values
13
+ opts[:sender_country] ||= "056"
14
+
15
+ # check params
16
+ CityboxApi.check_params [ :admission_code, :sender_code, :sender_contact_person, :sender_contact_phone, :take_up_date,
17
+ :take_up_from_hour, :take_up_to_hour ], opts
18
+
19
+ # format for date: aaaa-mm-dd
20
+ xml = "<?xml version='1.0' encoding='utf-8'?>
21
+ <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/'>
22
+ <soap:Body>
23
+ <registrarRetiro xmlns='http://tempuri.org/'>
24
+ <usuario>#{@user}</usuario>
25
+ <contrasena>#{@password}</contrasena>
26
+ <retiroTO>
27
+ <ExtensionData />
28
+ <CodigoAdmision>#{opts[:admission_code]}</CodigoAdmision>
29
+ <ClienteRemitente>#{opts[:sender_code]}</ClienteRemitente>
30
+ <CentroRemitente></CentroRemitente>
31
+ <NombreRemitente>#{opts[:sender_name]}</NombreRemitente>
32
+ <DireccionRemitente>#{opts[:sender_address]}</DireccionRemitente>
33
+ <PaisRemitente>#{opts[:sender_country]}</PaisRemitente>
34
+ <CodigoPostalRemitente>#{opts[:sender_postal_code]}</CodigoPostalRemitente>
35
+ <ComunaRemitente>#{opts[:sender_commune]}</ComunaRemitente>
36
+ <RutRemitente>#{opts[:sender_rut]}</RutRemitente>
37
+ <PersonaContactoRemitente>#{opts[:sender_contact_person]}</PersonaContactoRemitente>
38
+ <TelefonoContactoRemitente>#{opts[:sender_contact_phone]}</TelefonoContactoRemitente>
39
+ <FechaRetiro>#{opts[:take_up_date]}</FechaRetiro>
40
+ <HoraDesde>#{opts[:take_up_from_hour]}</HoraDesde>
41
+ <HoraHasta>#{opts[:take_up_to_hour]}</HoraHasta>
42
+ </retiroTO>
43
+ </registrarRetiro>
44
+ </soap:Body>
45
+ </soap:Envelope>"
46
+
47
+ begin
48
+ xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
49
+ json_response = Crack::XML.parse(xml_response)
50
+ json_response["soap:Envelope"]["soap:Body"]["registrarRetiroResponse"]["registrarRetiroResult"]
51
+ rescue => error
52
+ return CityboxApi.catch_error(error)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,149 @@
1
+ module CityboxApi
2
+ # module for tariff services
3
+ class Tariff
4
+ def initialize
5
+ raise CityboxApi::INVALID_CREDENTIALS if CityboxApi.configuration.key == nil
6
+ @user = CityboxApi.configuration.user
7
+ @password = CityboxApi.configuration.key
8
+ @server_url = "http://b2b.correos.cl:8008/ServicioTarificacionCEPEmpresasExterno/cch/ws/tarificacionCEP/externo/implementacion/ExternoTarificacion.asmx"
9
+ end
10
+
11
+ def apply_tariff_to_person opts={}
12
+ server_url = "http://b2b.correos.cl:8008/ServicioTarificadorPersonasExterno/cch/ws/tarificacion/externo/implementacion/ServicioExternoTarificadorPersonas.asmx"
13
+
14
+ # default values
15
+ opts[:scope] ||= "1" # national scope
16
+
17
+ # check_params
18
+ CityboxApi.check_params [ :origin_iata, :destination_iata, :scope, :weight ], opts
19
+
20
+ xml = "<?xml version='1.0' encoding='utf-8'?>
21
+ <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/'>
22
+ <soap:Body>
23
+ <aplicarTarifaPersona xmlns='http://tempuri.org/'>
24
+ <usuario>#{@user}</usuario>
25
+ <contrasena>#{@password}</contrasena>
26
+ <iataOrigen>#{opts[:origin_iata]}</iataOrigen>
27
+ <iataDestino>#{opts[:destination_iata]}</iataDestino>
28
+ <cobertura>#{opts[:scope]}</cobertura>
29
+ <peso>#{opts[:weight].to_f}</peso>
30
+ </aplicarTarifaPersona>
31
+ </soap:Body>
32
+ </soap:Envelope>"
33
+ begin
34
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
35
+ json_response = Crack::XML.parse(xml_response)
36
+ json_response["soap:Envelope"]["soap:Body"]["aplicarTarifaPersonaResponse"]["aplicarTarifaPersonaResult"]
37
+ rescue => error
38
+ return CityboxApi.catch_error(error)
39
+ end
40
+ end
41
+
42
+ def see_scope opts={}
43
+ # default values
44
+ opts[:sender_country] ||= "056" # chilean by default
45
+ opts[:receiver_country] ||= "056" # chilean by default
46
+ opts[:insured_import_value] ||= "NO"
47
+
48
+ # check params
49
+ CityboxApi.check_params [ :sender_country, :sender_commune, :receiver_country, :receiver_commune, :payment_type, :number_of_pieces, :kilograms ], opts
50
+
51
+ xml = "<?xml version='1.0' encoding='utf-8'?>
52
+ <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/'>
53
+ <soap:Body>
54
+ <consultaCobertura xmlns='http://tempuri.org/'>
55
+ <usuario>#{@user}</usuario>
56
+ <contrasena>#{@password}</contrasena>
57
+ <consultaCobertura>
58
+ <ExtensionData />
59
+ <CodigoPostalDestinatario>#{opts[:receiver_postal_code]}</CodigoPostalDestinatario>
60
+ <CodigoPostalRemitente>#{opts[:sender_postal_code]}</CodigoPostalRemitente>
61
+ <ComunaDestino>#{opts[:receiver_commune]}</ComunaDestino>
62
+ <ComunaRemitente>#{opts[:sender_commune]}</ComunaRemitente>
63
+ <ImporteReembolso>#{opts[:import_refund]}</ImporteReembolso>
64
+ <ImporteValorAsegurado>#{opts[:insured_import_value]}</ImporteValorAsegurado>
65
+ <Kilos>#{opts[:kilograms]}</Kilos>
66
+ <NumeroTotalPieza>#{opts[:number_of_pieces]}</NumeroTotalPieza>
67
+ <PaisDestinatario>#{opts[:receiver_country]}</PaisDestinatario>
68
+ <PaisRemitente>#{opts[:sender_country]}</PaisRemitente>
69
+ <TipoPortes>#{opts[:payment_type]}</TipoPortes>
70
+ <Volumen>#{opts[:volume]}</Volumen>
71
+ </consultaCobertura>
72
+ </consultaCobertura>
73
+ </soap:Body>
74
+ </soap:Envelope>"
75
+
76
+ begin
77
+ xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
78
+ json_response = Crack::XML.parse(xml_response)
79
+ json_response["soap:Envelope"]["soap:Body"]["consultaCoberturaResponse"]["consultaCoberturaResult"]["ServicioTO"]
80
+ rescue => error
81
+ return CityboxApi.catch_error(error)
82
+ end
83
+ end
84
+
85
+ def see_scope_by_product opts={}
86
+ # default values
87
+ opts[:sender_country] ||= "056" # chilean by default
88
+ opts[:receiver_country] ||= "056" # chilean by default
89
+ opts[:insured_import_value] ||= "NO"
90
+
91
+ # check params
92
+ CityboxApi.check_params [ :service_code, :sender_country, :sender_commune, :receiver_country, :receiver_commune, :payment_type, :number_of_pieces, :kilograms ], opts
93
+
94
+ xml = "<?xml version='1.0' encoding='utf-8'?>
95
+ <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/'>
96
+ <soap:Body>
97
+ <consultaCoberturaPorProducto xmlns='http://tempuri.org/'>
98
+ <usuario>#{@user}</usuario>
99
+ <contrasena>#{@password}</contrasena>
100
+ <consultaCobertura>
101
+ <ExtensionData />
102
+ <CodigoPostalDestinatario>#{opts[:receiver_postal_code]}</CodigoPostalDestinatario>
103
+ <CodigoPostalRemitente>#{opts[:sender_postal_code]}</CodigoPostalRemitente>
104
+ <CodigoServicio>#{opts[:service_code]}</CodigoServicio>
105
+ <ComunaDestino>#{opts[:receiver_commune]}</ComunaDestino>
106
+ <ComunaRemitente>#{opts[:sender_commune]}</ComunaRemitente>
107
+ <ImporteReembolso>#{opts[:import_refund]}</ImporteReembolso>
108
+ <ImporteValorAsegurado>#{opts[:insured_import_value]}</ImporteValorAsegurado>
109
+ <Kilos>#{opts[:kilograms]}</Kilos>
110
+ <NumeroTotalPieza>#{opts[:number_of_pieces]}</NumeroTotalPieza>
111
+ <PaisDestinatario>#{opts[:receiver_country]}</PaisDestinatario>
112
+ <PaisRemitente>#{opts[:sender_country]}</PaisRemitente>
113
+ <TipoPortes>#{opts[:payment_type]}</TipoPortes>
114
+ <Volumen>#{opts[:volume]}</Volumen>
115
+ </consultaCobertura>
116
+ </consultaCoberturaPorProducto>
117
+ </soap:Body>
118
+ </soap:Envelope>"
119
+
120
+ begin
121
+ xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
122
+ json_response = Crack::XML.parse(xml_response)
123
+ json_response["soap:Envelope"]["soap:Body"]["consultaCoberturaPorProductoResponse"]["consultaCoberturaPorProductoResult"]
124
+ rescue => error
125
+ return CityboxApi.catch_error(error)
126
+ end
127
+ end
128
+
129
+ def see_products_by_client
130
+ xml = "<?xml version='1.0' encoding='utf-8'?>
131
+ <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/'>
132
+ <soap:Body>
133
+ <consultaProductosPorCliente xmlns='http://tempuri.org/'>
134
+ <usuario>#{@user}</usuario>
135
+ <contrasena>#{@password}</contrasena>
136
+ </consultaProductosPorCliente>
137
+ </soap:Body>
138
+ </soap:Envelope>"
139
+
140
+ begin
141
+ xml_response = RestClient.post @server_url, xml, content_type: "text/xml"
142
+ json_response = Crack::XML.parse(xml_response)
143
+ json_response["soap:Envelope"]["soap:Body"]["consultaProductosPorClienteResponse"]["consultaProductosPorClienteResult"]["ProductoTo"]
144
+ rescue => error
145
+ return CityboxApi.catch_error(error)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,148 @@
1
+ module CityboxApi
2
+ # module formany getter utilities
3
+ class Utilities
4
+ def initialize
5
+ raise CityboxApi::INVALID_CREDENTIALS if CityboxApi.configuration.key == nil
6
+ @user = CityboxApi.configuration.user
7
+ @password = CityboxApi.configuration.key
8
+ end
9
+
10
+ def list_cityboxes
11
+ server_url = "http://b2b.correos.cl:8008/ServicioCityboxExterno/cch/ws/citybox/externo/implementacion/ServicioCityboxExterno.asmx"
12
+ xml = "<?xml version='1.0' encoding='utf-8'?>
13
+ <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/'>
14
+ <soap:Body>
15
+ <listarCityboxDisponibles xmlns='http://tempuri.org/'>
16
+ <usuario>#{@user}</usuario>
17
+ <contrasena>#{@password}</contrasena>
18
+ </listarCityboxDisponibles>
19
+ </soap:Body>
20
+ </soap:Envelope>"
21
+
22
+ begin
23
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
24
+ json_response = Crack::XML.parse(xml_response)
25
+ json_response["soap:Envelope"]["soap:Body"]["listarCityboxDisponiblesResponse"]["listarCityboxDisponiblesResult"]["CityboxTO"]
26
+ rescue => error
27
+ return CityboxApi.catch_error(error)
28
+ end
29
+ end
30
+
31
+ def list_master_products
32
+ server_url = "http://b2b.correos.cl:8008/ServicioProductosCorreosExterno/cch/ws/ProductosCorreos/externo/implementacion/ServicioExternoProductoCorreos.asmx"
33
+ xml = "<?xml version='1.0' encoding='utf-8'?>
34
+ <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/'>
35
+ <soap:Body>
36
+ <listarMaestroProductos xmlns='http://tempuri.org/'>
37
+ <usuario>#{@user}</usuario>
38
+ <contrasena>#{@password}</contrasena>
39
+ </listarMaestroProductos>
40
+ </soap:Body>
41
+ </soap:Envelope>"
42
+
43
+ begin
44
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
45
+ json_response = Crack::XML.parse(xml_response)
46
+ json_response["soap:Envelope"]["soap:Body"]["listarMaestroProductosResponse"]["listarMaestroProductosResult"]["ProductoTO"]
47
+ rescue => error
48
+ return CityboxApi.catch_error(error)
49
+ end
50
+ end
51
+
52
+ def see_scl_documents shipment_number
53
+ server_url = "http://b2b.correos.cl:8008/ServicioConsultaAvisoDocumentoSCLExterno/cch/ws/externo/implementacion/ServicioExternoConsultaAvisoDocumentoSCL.asmx"
54
+ xml = "<?xml version='1.0' encoding='utf-8'?>
55
+ <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/'>
56
+ <soap:Body>
57
+ <consultaDocumentosSCL xmlns='http://tempuri.org/'>
58
+ <usuario>#{@user}</usuario>
59
+ <contrasena>#{@password}</contrasena>
60
+ <numeroEnvio>#{shipment_number}</numeroEnvio>
61
+ </consultaDocumentosSCL>
62
+ </soap:Body>
63
+ </soap:Envelope>"
64
+
65
+ begin
66
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
67
+ json_response = Crack::XML.parse(xml_response)
68
+ json_response["soap:Envelope"]["soap:Body"]["consultaDocumentosSCLResponse"]["consultaDocumentosSCLResult"]["DocumentoSclTO"]
69
+ rescue => error
70
+ return CityboxApi.catch_error(error)
71
+ end
72
+ end
73
+
74
+ def see_fivps shipment_number
75
+ server_url = "http://b2b.correos.cl:8008/ServicioConsultaFivpsExterno/cch/ws/aduana/externo/implementacion/ServicioExternoConsultaFivps.asmx"
76
+ xml = "<?xml version='1.0' encoding='utf-8'?>
77
+ <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/'>
78
+ <soap:Body>
79
+ <consultaFIVPS xmlns='http://tempuri.org/'>
80
+ <usuario>#{@user}</usuario>
81
+ <contrasena>#{@password}</contrasena>
82
+ <numeroEnvio>#{shipment_number}</numeroEnvio>
83
+ </consultaFIVPS>
84
+ </soap:Body>
85
+ </soap:Envelope>"
86
+
87
+ begin
88
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
89
+ json_response = Crack::XML.parse(xml_response)
90
+ json_response["soap:Envelope"]["soap:Body"]["consultaFIVPSResponse"]["consultaFIVPSResult"]["FivpsTO"]
91
+ rescue => error
92
+ return CityboxApi.catch_error(error)
93
+ end
94
+ end
95
+
96
+ def normalize_address opts={}
97
+ server_url = "http://b2b.correos.cl:8008/ServicioNormalizacionExterno/cch/ws/distribucionGeografica/externo/implementacion/ServicioExternoNormalizacion.asmx"
98
+ # default values
99
+ opts[:request_id] ||= rand(10000)
100
+
101
+ # check params
102
+ CityboxApi.check_params [:full_address, :commune], opts
103
+
104
+ xml = "<?xml version='1.0' encoding='utf-8'?>
105
+ <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/'>
106
+ <soap:Body>
107
+ <normalizarDireccion xmlns='http://tempuri.org/'>
108
+ <usuario>#{@user}</usuario>
109
+ <contrasena>#{@password}</contrasena>
110
+ <id>#{opts[:request_id]}</id>
111
+ <direccion>#{opts[:full_address]}</direccion>
112
+ <comuna>#{opts[:commune]}</comuna>
113
+ </normalizarDireccion>
114
+ </soap:Body>
115
+ </soap:Envelope>"
116
+
117
+ begin
118
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
119
+ json_response = Crack::XML.parse(xml_response)
120
+ json_response["soap:Envelope"]["soap:Body"]["normalizarDireccionResponse"]["normalizarDireccionResult"]
121
+ rescue => error
122
+ return CityboxApi.catch_error(error)
123
+ end
124
+ end
125
+
126
+ def claim_status claim_number
127
+ server_url = "http://b2b.correos.cl:8008/ServicioEstadoDeReclamosExterno/cch/ws/reclamos/implementacion/ServicioExternoEstadoDeReclamos.asmx"
128
+ xml = "<?xml version='1.0' encoding='utf-8'?>
129
+ <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/'>
130
+ <soap:Body>
131
+ <consultaEstadoDeReclamo xmlns='http://tempuri.org/'>
132
+ <usuario>#{@user}</usuario>
133
+ <contrasena>#{@password}</contrasena>
134
+ <numero>#{claim_number}</numero>
135
+ </consultaEstadoDeReclamo>
136
+ </soap:Body>
137
+ </soap:Envelope>"
138
+
139
+ begin
140
+ xml_response = RestClient.post server_url, xml, content_type: "text/xml"
141
+ json_response = Crack::XML.parse(xml_response)
142
+ json_response["soap:Envelope"]["soap:Body"]["consultaEstadoDeReclamoResponse"]["consultaEstadoDeReclamoResult"]
143
+ rescue => error
144
+ return CityboxApi.catch_error(error)
145
+ end
146
+ end
147
+ end
148
+ end
@@ -1,3 +1,3 @@
1
1
  module CityboxApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/citybox_api.rb CHANGED
@@ -5,10 +5,27 @@ require 'crack'
5
5
  require 'citybox_api/regions'
6
6
  require 'citybox_api/branch_offices'
7
7
  require 'citybox_api/configuration'
8
-
8
+ require 'citybox_api/shipments'
9
+ require 'citybox_api/take_ups'
10
+ require 'citybox_api/tariff'
11
+ require 'citybox_api/utilities'
9
12
 
10
13
  module CityboxApi
11
14
  # Credentials for API
12
15
  INVALID_CREDENTIALS = "Key cant be blank!"
13
16
  CityboxApi.configure
17
+
18
+ def self.catch_error error
19
+ puts error
20
+ json_response = Crack::XML.parse(error.response)
21
+ fault_code = json_response["soap:Envelope"]["soap:Body"]["soap:Fault"]["faultcode"]
22
+ fault_string = json_response["soap:Envelope"]["soap:Body"]["soap:Fault"]["faultstring"]
23
+ fault = {faultCode: fault_code, fault_string: fault_string}
24
+ puts fault
25
+ return nil
26
+ end
27
+
28
+ def self.check_params params, opts
29
+ params.each{|p| raise "#{p} can't be blank" unless opts[p]}
30
+ end
14
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citybox_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joaquin Nuñez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,6 +103,10 @@ files:
103
103
  - lib/citybox_api/branch_offices.rb
104
104
  - lib/citybox_api/configuration.rb
105
105
  - lib/citybox_api/regions.rb
106
+ - lib/citybox_api/shipments.rb
107
+ - lib/citybox_api/take_ups.rb
108
+ - lib/citybox_api/tariff.rb
109
+ - lib/citybox_api/utilities.rb
106
110
  - lib/citybox_api/version.rb
107
111
  homepage: https://github.com/joacong/citybox_api
108
112
  licenses: