Class: CityboxApi::Shipments

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

Overview

module for shipments services

Instance Method Summary collapse

Constructor Details

#initializeShipments

Returns a new instance of Shipments.



4
5
6
7
8
# File 'lib/citybox_api/shipments.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

#allow_shipment(opts = {}) ⇒ Object

sent an allow shipping request



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/citybox_api/shipments.rb', line 11

def allow_shipment opts={}
 		server_url = "http://b2b.correos.cl:8008/ServicioAdmisionCEPExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoAdmisionCEP.asmx"
	opts = check_shipment_opts opts
 		xml = shipment_xml "admitirEnvio", opts

	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"]["admitirEnvioResponse"]["admitirEnvioResult"]
	rescue => error
		return CityboxApi.catch_error(error)
	end
end

#cancel_shipment(opts = {}) ⇒ Object



40
41
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
# File 'lib/citybox_api/shipments.rb', line 40

def cancel_shipment opts={}
 		server_url = "http://b2b.correos.cl:8008/ServicioAnulacionExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoAnulacionEnvio.asmx"

	#check params
	CityboxApi.check_params [ :shipment_number, :admission_code, :sender_code ], 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>
			    <anularEnvio xmlns='http://tempuri.org/'>
			      <usuario>#{@user}</usuario>
			      <contrasena>#{@password}</contrasena>
			      <numeroEnvio>#{opts[:shipment_number]}</numeroEnvio>
			      <codigoAdmision>#{opts[:admission_code]}</codigoAdmision>
			      <clienteRemitente>#{opts[:sender_code]}</clienteRemitente>
			    </anularEnvio>
			  </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"]["anularEnvioResponse"]["anularEnvioResult"]
	rescue => error
		return CityboxApi.catch_error(error)
	end
end

#validate_shipment(opts = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/citybox_api/shipments.rb', line 26

def validate_shipment opts={}
 		server_url = "http://b2b.correos.cl:8008/ServicioValidacionAdmisionCEPExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoValidaAdmisionCEP.asmx"
	opts = check_shipment_opts opts
 		xml = shipment_xml "validarEnvio", opts

	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"]["validarEnvioResponse"]["validarEnvioResult"]
	rescue => error
		return CityboxApi.catch_error(error)
	end
end