Class: CityboxApi::BranchOffices

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

Overview

module for branch offices services

Instance Method Summary collapse

Constructor Details

#initializeBranchOffices

Returns a new instance of BranchOffices.



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

def initialize
  raise CityboxApi::INVALID_CREDENTIALS if CityboxApi.configuration.key == nil
  @server_url = "http://b2b.correos.cl:8008/ServicioListadoSucursalesExterno/cch/ws/distribucionGeografica/implementacion/ServicioExternoListarSucursales.asmx"
    @user = CityboxApi.configuration.user
    @password = CityboxApi.configuration.key
end

Instance Method Details

#list_branch_officesObject

list all branch offices



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

def 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>#{@user}</usuario>
            <contrasena>#{@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 => error
    return CityboxApi.catch_error(error)
  end
end

#list_branch_offices_by_commune(commune_id) ⇒ Object

list all branch offices for commune with id ‘commune_id’



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

def 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>#{@user}</usuario>
            <contrasena>#{@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 => error
    return CityboxApi.catch_error(error)
  end
end

#list_branch_offices_near_to(opts = {}) ⇒ Object

list all branch offices near to a especific location



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

def 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>#{@user}</usuario>
            <contrasena>#{@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 => error
    return CityboxApi.catch_error(error)
  end
end