Skip to content

Instantly share code, notes, and snippets.

@tiagomatos
Last active June 11, 2018 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagomatos/70cd80549bfb77da2216d31f0b8b362d to your computer and use it in GitHub Desktop.
Save tiagomatos/70cd80549bfb77da2216d31f0b8b362d to your computer and use it in GitHub Desktop.
Jumpseller Correos de Chile PES
require 'net/http'
HOST = 'http://b2b.correos.cl/ServicioAdmisionCEPExterno/cch/ws/enviosCEP/externo/implementacion/ServicioExternoAdmisionCEP.asmx?WSDL'
def post_xml xml_string
uri = URI.parse HOST
request = Net::HTTP::Post.new uri.path
request.body = xml_string
request.content_type = 'text/xml'
response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
response.body
end
xml_str = <<EOF
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:admitirEnvio>
<tem:usuario>JUMPSELLERPROD</tem:usuario>
<tem:contrasena>XXX</tem:contrasena>
<tem:admisionTo>
<tem:ExtensionData/>
<tem:CodigoAdmision>c</tem:CodigoAdmision>
<tem:ClienteRemitente>531649</tem:ClienteRemitente>
<tem:NombreRemitente>Jumpseller</tem:NombreRemitente>
<tem:DireccionRemitente>Av. Nueva Providencia, 2353</tem:DireccionRemitente>
<tem:PaisRemitente>056</tem:PaisRemitente>
<tem:CodigoPostalRemitente>7510058</tem:CodigoPostalRemitente>
<tem:ComunaRemitente>Santiago</tem:ComunaRemitente>
<tem:PersonaContactoRemitente>Paulo</tem:PersonaContactoRemitente>
<tem:TelefonoContactoRemitente>123123123</tem:TelefonoContactoRemitente>
<tem:NombreDestinatario>Paulo</tem:NombreDestinatario>
<tem:DireccionDestinatario>SUCURSAL CONCON</tem:DireccionDestinatario>
<tem:PaisDestinatario>056</tem:PaisDestinatario>
<tem:CodigoPostalDestinatario>2510727</tem:CodigoPostalDestinatario>
<tem:ComunaDestinatario>CONCON</tem:ComunaDestinatario>
<tem:PersonaContactoRemitente>Tiago Matos</tem:PersonaContactoRemitente>
<tem:TelefonoContactoRemitente>123123123</tem:TelefonoContactoRemitente>
<tem:CodigoServicio>07</tem:CodigoServicio>
<tem:NumeroTotalPiezas>1</tem:NumeroTotalPiezas>
<tem:Kilos>1</tem:Kilos>
<tem:NumeroReferencia>2680</tem:NumeroReferencia>
<tem:TipoPortes>P</tem:TipoPortes>
<tem:DevolucionConforme>N</tem:DevolucionConforme>
<tem:NumeroDocumentos>1</tem:NumeroDocumentos>
<tem:ImporteValorDeclarado>42900</tem:ImporteValorDeclarado>
</tem:admisionTo>
</tem:admitirEnvio>
</soapenv:Body></soapenv:Envelope>
EOF
p post_xml(xml_str)
# outputs:
# "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><admitirEnvioResponse xmlns=\"http://tempuri.org/\"><admitirEnvioResult><ExtensionData /><Cuartel>6</Cuartel><Sector>21</Sector><SDP>1</SDP><AbreviaturaCentro>531649</AbreviaturaCentro><CodigoDelegacionDestino>864</CodigoDelegacionDestino><NombreDelegacionDestino>PLANTA CEP RM</NombreDelegacionDestino><DireccionDestino>NUEVA PROVIDENCIA 2353 PISO 18</DireccionDestino><CodigoEncaminamiento>12475100587</CodigoEncaminamiento><GrabarEnvio>S</GrabarEnvio><NumeroEnvio>990059187494</NumeroEnvio><ComunaDestino>PROVIDENCIA</ComunaDestino><AbreviaturaServicio>PED</AbreviaturaServicio><CodigoAdmision>C</CodigoAdmision></admitirEnvioResult></admitirEnvioResponse></soap:Body></soap:Envelope>"
@tiagomatos
Copy link
Author

tiagomatos commented Jun 11, 2018

output:
<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><admitirEnvioResponse xmlns=\"http://tempuri.org/\"><admitirEnvioResult><ExtensionData /><CodigoSucursal>GKF</CodigoSucursal><NombreSucursal>SUCURSAL NUEVA CONCON</NombreSucursal><SDP>1</SDP><AbreviaturaCentro>531649</AbreviaturaCentro><CodigoDelegacionDestino>252</CodigoDelegacionDestino><NombreDelegacionDestino>VI\xC3\x91A DEL MAR</NombreDelegacionDestino><DireccionDestino>SUCURSAL CONCON </DireccionDestino><CodigoEncaminamiento>10725190017</CodigoEncaminamiento><GrabarEnvio>S</GrabarEnvio><NumeroEnvio>990059242645</NumeroEnvio><ComunaDestino>CONCON</ComunaDestino><AbreviaturaServicio>PES</AbreviaturaServicio><CodigoAdmision>C</CodigoAdmision></admitirEnvioResult></admitirEnvioResponse></soap:Body></soap:Envelope>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment