Module: Citybox::BranchOffices

Defined in:
lib/citybox/branch_offices.rb

Overview

module for branch offices services

Class Method Summary collapse

Class Method Details

.list_branch_officesObject

list all branch offices



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/citybox/branch_offices.rb', line 7

def self.list_branch_offices
	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>
			    <listarTodasLasSucursales xmlns='http://tempuri.org/'>
			      <usuario>#{Citybox.user}</usuario>
			      <contrasena>#{Citybox.password}</contrasena>
			    </listarTodasLasSucursales>
			  </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"]["listarTodasLasSucursalesResponse"]["listarTodasLasSucursalesResult"]["SucursalTO"]
	rescue => e
		puts e
		return nil
	end
end

.list_branch_offices_by_commune(commune_id) ⇒ Object

list all branch offices for commune with id ‘commune_id’



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

def self.list_branch_offices_by_commune commune_id
	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>
			    <listarSucursalesSegunComuna xmlns='http://tempuri.org/'>
			      <usuario>#{Citybox.user}</usuario>
			      <contrasena>#{Citybox.password}</contrasena>
			      <codigoComuna>#{commune_id}</codigoComuna>
			    </listarSucursalesSegunComuna>
			  </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"]["listarSucursalesSegunComunaResponse"]["listarSucursalesSegunComunaResult"]["SucursalTO"]
	rescue => e
		puts e
		return nil
	end
end

.list_branch_offices_near_to(opts = {}) ⇒ Object

list all branch offices near to a especific location



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
# File 'lib/citybox/branch_offices.rb', line 52

def self.list_branch_offices_near_to opts={}
	request_id = rand(10000)
	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>
			    <consultaSucursalMasCercana xmlns='http://tempuri.org/'>
			      <usuario>#{Citybox.user}</usuario>
			      <contrasena>#{Citybox.password}</contrasena>
			      <id>#{request_id}</id>
			      <nombreCalle>#{opts[:street_name]}</nombreCalle>
			      <numeroCalle>#{opts[:street_number]}</numeroCalle>
			      <restoCalle>#{opts[:street_detail]}</restoCalle>
			      <NombreComuna>#{opts[:commune_name]}</NombreComuna>
			      <latitud>#{opts[:latitude]}</latitud>
			      <longitud>#{opts[:longitude]}</longitud>
			    </consultaSucursalMasCercana>
			  </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"]["consultaSucursalMasCercanaResponse"]["consultaSucursalMasCercanaResult"]
	rescue => e
		puts e
		return nil
	end
end