class CityboxApi::Regions

module for regions services

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

list_communes() click to toggle source

list all communes

# 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) click to toggle source

list all communes for region with id 'region_id'

# 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_regions() click to toggle source

list all regions

# 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