Class: CityboxApi::Regions

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

Overview

module for regions services

Instance Method Summary collapse

Constructor Details

#initializeRegions

Returns a new instance of Regions.



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

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

Instance Method Details

#list_communesObject

list all communes



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

def list_communes
    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>
          <listarTodasLasComunas xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
          </listarTodasLasComunas>
        </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"]["listarTodasLasComunasResponse"]["listarTodasLasComunasResult"]["ComunaTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#list_communes_by_region(region_id) ⇒ Object

list all communes for region with id ‘region_id’



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/citybox_api/regions.rb', line 54

def list_communes_by_region region_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>
          <listarComunasSegunRegion xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
            <codigoRegion>#{region_id}</codigoRegion>
          </listarComunasSegunRegion>
        </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"]["listarComunasSegunRegionResponse"]["listarComunasSegunRegionResult"]["ComunaTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end

#list_regionsObject

list all regions



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

def list_regions
    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>
          <listarTodasLasRegiones xmlns='http://tempuri.org/'>
            <usuario>#{@user}</usuario>
            <contrasena>#{@password}</contrasena>
          </listarTodasLasRegiones>
        </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"]["listarTodasLasRegionesResponse"]["listarTodasLasRegionesResult"]["RegionTO"]
  rescue => error
    return CityboxApi.catch_error(error)
  end
end