correios-ws 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +100 -0
- data/Rakefile +2 -0
- data/correios-ws.gemspec +18 -0
- data/lib/correios-ws/version.rb +3 -0
- data/lib/correios-ws.rb +164 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andrew S Aguiar
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
## Correios-Ws
|
2
|
+
|
3
|
+
correios-ws uses correios web-services SOAP to calculate shipping.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
$ gem 'correios-ws'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install correios-ws
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'correios-ws'
|
22
|
+
|
23
|
+
calculator = Correios::ShippingCalculator.new(codigo_empresa, senha)
|
24
|
+
|
25
|
+
package_data = Correios::PackageData.new do |p|
|
26
|
+
p.peso = '0.650'
|
27
|
+
p.comprimento = '45'
|
28
|
+
p.altura = '45'
|
29
|
+
p.largura = '45'
|
30
|
+
end
|
31
|
+
|
32
|
+
# calculator.calculate(cep_origem, cep_destino, package_date, array_with_services)
|
33
|
+
result = calculator.calculate('08061-430','08061-456', package_data, [
|
34
|
+
Correios::Servicos::PAC_SEM_CONTRATO,
|
35
|
+
Correios::Servicos::PAC_COM_CONTRATO,
|
36
|
+
Correios::Servicos::SEDEX_SEM_CONTRATO,
|
37
|
+
Correios::Servicos::SEDEX_A_COBRAR_SEM_CONTRATO,
|
38
|
+
Correios::Servicos::SEDEX_A_COBRAR_COM_CONTRATO,
|
39
|
+
Correios::Servicos::SEDEX_10_SEM_CONTRATO,
|
40
|
+
Correios::Servicos::SEDEX_HOJE_SEM_CONTRATO,
|
41
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_1,
|
42
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_2,
|
43
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_3,
|
44
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_4,
|
45
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_5,
|
46
|
+
Correios::Servicos::ESEDEX_COM_CONTRATO,
|
47
|
+
Correios::Servicos::ESEDEX_PRIORITARIO_COM_CONTRATO,
|
48
|
+
Correios::Servicos::ESEDEX_EXPRESS_COM_CONTRATO,
|
49
|
+
Correios::Servicos::GRUPO_1_ESEDEX_COM_CONTRATO,
|
50
|
+
Correios::Servicos::GRUPO_2_ESEDEX_COM_CONTRATO,
|
51
|
+
Correios::Servicos::GRUPO_3_ESEDEX_COM_CONTRATO
|
52
|
+
])
|
53
|
+
# OR
|
54
|
+
# result = calculator.calculate('08054-550','09051-456', package_data, Correios::Servicos::ALL)
|
55
|
+
|
56
|
+
# services is a Hash with each result
|
57
|
+
services = result.services
|
58
|
+
|
59
|
+
# to get a particular service use the contants in
|
60
|
+
# Correios::Servicos
|
61
|
+
#
|
62
|
+
# Example:
|
63
|
+
pac_sem_contrato = services[Correios::Servicos::PAC_SEM_CONTRATO]
|
64
|
+
pac_com_contrato = services[Correios::Servicos::PAC_COM_CONTRATO]
|
65
|
+
sedex_sem_contrato = services[Correios::Servicos::SEDEX_SEM_CONTRATO]
|
66
|
+
sedex_a_cobrar_sem_contrato = services[Correios::Servicos::SEDEX_A_COBRAR_SEM_CONTRATO]
|
67
|
+
sedex_a_cobrar_com_contrato = services[Correios::Servicos::SEDEX_A_COBRAR_COM_CONTRATO]
|
68
|
+
sedex_10_sem_contrato = services[Correios::Servicos::SEDEX_10_SEM_CONTRATO]
|
69
|
+
sedex_hoje_sem_contrato = services[Correios::Servicos::SEDEX_HOJE_SEM_CONTRATO]
|
70
|
+
sedex_com_contrato_1 = services[Correios::Servicos::SEDEX_COM_CONTRATO_1]
|
71
|
+
sedex_com_contrato_2 = services[Correios::Servicos::SEDEX_COM_CONTRATO_2]
|
72
|
+
sedex_com_contrato_3 = services[Correios::Servicos::SEDEX_COM_CONTRATO_3]
|
73
|
+
sedex_com_contrato_4 = services[Correios::Servicos::SEDEX_COM_CONTRATO_4]
|
74
|
+
sedex_com_contrato_5 = services[Correios::Servicos::SEDEX_COM_CONTRATO_5]
|
75
|
+
esedex_com_contrato = services[Correios::Servicos::ESEDEX_COM_CONTRATO]
|
76
|
+
esedex_prioritario_com_contrato = services[Correios::Servicos::ESEDEX_PRIORITARIO_COM_CONTRATO]
|
77
|
+
esedex_express_com_contrato = services[Correios::Servicos::ESEDEX_EXPRESS_COM_CONTRATO]
|
78
|
+
grupo_1_esedex_com_contrato = services[Correios::Servicos::GRUPO_1_ESEDEX_COM_CONTRATO]
|
79
|
+
grupo_2_esedex_com_contrato = services[Correios::Servicos::GRUPO_2_ESEDEX_COM_CONTRATO]
|
80
|
+
grupo_3_esedex_com_contrato = services[Correios::Servicos::GRUPO_3_ESEDEX_COM_CONTRATO]
|
81
|
+
|
82
|
+
# for each service use its methods
|
83
|
+
puts esedex_com_contrato.codigo
|
84
|
+
puts esedex_com_contrato.valor
|
85
|
+
puts esedex_com_contrato.valor_mao_propria
|
86
|
+
puts esedex_com_contrato.valor_aviso_recebimento
|
87
|
+
puts esedex_com_contrato.valor_declarado
|
88
|
+
puts esedex_com_contrato.prazo_entrega
|
89
|
+
puts esedex_com_contrato.entrega_domiciliar
|
90
|
+
puts esedex_com_contrato.entrega_sabado
|
91
|
+
puts esedex_com_contrato.error
|
92
|
+
puts esedex_com_contrato.msg_error
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork it
|
97
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
98
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
99
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
100
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/correios-ws.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/correios-ws/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Andrew S Aguiar']
|
6
|
+
gem.email = ['andrewaguiar6@gmail.com']
|
7
|
+
gem.description = 'correios-ws uses correios web-services SOAP to calculate shipping'
|
8
|
+
gem.summary = 'correios shipping calculation using SOAP'
|
9
|
+
gem.homepage = 'http://www.github.com/andrewaguiar/correios-ws'
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = 'correios-ws'
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.version = Correios::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency 'soap4r'
|
18
|
+
end
|
data/lib/correios-ws.rb
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Correios
|
3
|
+
class CalcPrecoPrazo
|
4
|
+
attr_accessor(:nCdEmpresa,
|
5
|
+
:sDsSenha,
|
6
|
+
:nCdServico,
|
7
|
+
:nCdServico,
|
8
|
+
:nCdServico,
|
9
|
+
:sCepOrigem,
|
10
|
+
:sCepDestino,
|
11
|
+
:nVlPeso,
|
12
|
+
:nCdFormato,
|
13
|
+
:nVlComprimento,
|
14
|
+
:nVlAltura,
|
15
|
+
:nVlLargura,
|
16
|
+
:nVlDiametro,
|
17
|
+
:sCdMaoPropria,
|
18
|
+
:nVlValorDeclarado,
|
19
|
+
:sCdAvisoRecebimento)
|
20
|
+
def initialize
|
21
|
+
yield self if block_given?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Servicos
|
26
|
+
PAC_SEM_CONTRATO = '41106'
|
27
|
+
PAC_COM_CONTRATO = '41068'
|
28
|
+
SEDEX_SEM_CONTRATO = '40010'
|
29
|
+
SEDEX_A_COBRAR_SEM_CONTRATO = '40045'
|
30
|
+
SEDEX_A_COBRAR_COM_CONTRATO = '40126'
|
31
|
+
SEDEX_10_SEM_CONTRATO = '40215'
|
32
|
+
SEDEX_HOJE_SEM_CONTRATO = '40290'
|
33
|
+
SEDEX_COM_CONTRATO_1 = '40096'
|
34
|
+
SEDEX_COM_CONTRATO_2 = '40436'
|
35
|
+
SEDEX_COM_CONTRATO_3 = '40444'
|
36
|
+
SEDEX_COM_CONTRATO_4 = '40568'
|
37
|
+
SEDEX_COM_CONTRATO_5 = '40606'
|
38
|
+
ESEDEX_COM_CONTRATO = '81019'
|
39
|
+
ESEDEX_PRIORITARIO_COM_CONTRATO = '81027'
|
40
|
+
ESEDEX_EXPRESS_COM_CONTRATO = '81035'
|
41
|
+
GRUPO_1_ESEDEX_COM_CONTRATO = '81868'
|
42
|
+
GRUPO_2_ESEDEX_COM_CONTRATO = '81833'
|
43
|
+
GRUPO_3_ESEDEX_COM_CONTRATO = '81850'
|
44
|
+
ALL = [
|
45
|
+
Correios::Servicos::PAC_SEM_CONTRATO,
|
46
|
+
Correios::Servicos::PAC_COM_CONTRATO,
|
47
|
+
Correios::Servicos::SEDEX_SEM_CONTRATO,
|
48
|
+
Correios::Servicos::SEDEX_A_COBRAR_SEM_CONTRATO,
|
49
|
+
Correios::Servicos::SEDEX_A_COBRAR_COM_CONTRATO,
|
50
|
+
Correios::Servicos::SEDEX_10_SEM_CONTRATO,
|
51
|
+
Correios::Servicos::SEDEX_HOJE_SEM_CONTRATO,
|
52
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_1,
|
53
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_2,
|
54
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_3,
|
55
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_4,
|
56
|
+
Correios::Servicos::SEDEX_COM_CONTRATO_5,
|
57
|
+
Correios::Servicos::ESEDEX_COM_CONTRATO,
|
58
|
+
Correios::Servicos::ESEDEX_PRIORITARIO_COM_CONTRATO,
|
59
|
+
Correios::Servicos::ESEDEX_EXPRESS_COM_CONTRATO,
|
60
|
+
Correios::Servicos::GRUPO_1_ESEDEX_COM_CONTRATO,
|
61
|
+
Correios::Servicos::GRUPO_2_ESEDEX_COM_CONTRATO,
|
62
|
+
Correios::Servicos::GRUPO_3_ESEDEX_COM_CONTRATO
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
class PackageData
|
67
|
+
attr_accessor :peso, :formato, :comprimento, :altura, :largura, :diametro, :valor_declarado, :mao_propria, :aviso_recebimento
|
68
|
+
|
69
|
+
FORMATS = { :box => 1, :roll => 2, :envelope => 3 }
|
70
|
+
|
71
|
+
def initialize
|
72
|
+
@peso, @formato, @comprimento, @altura, @largura, @diametro, @valor_declarado, @mao_propria, @aviso_recebimento = '', FORMATS[:box], '', '', '', '', '', '', ''
|
73
|
+
yield self if block_given?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class ShippingCalculator
|
78
|
+
require 'soap/wsdlDriver'
|
79
|
+
|
80
|
+
WSDL_URL = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?WSDL'
|
81
|
+
|
82
|
+
def initialize codigo_empresa, senha
|
83
|
+
@codigo_empresa, @senha = codigo_empresa, senha
|
84
|
+
@wsdl_client = wSDLDriverFactory = SOAP::WSDLDriverFactory.new( WSDL_URL ).create_rpc_driver
|
85
|
+
end
|
86
|
+
|
87
|
+
def calculate cep_origem, cep_destino, pacote, servicos
|
88
|
+
calcPrecoPrazo = CalcPrecoPrazo.new do |o|
|
89
|
+
o.nCdEmpresa = @codigo_empresa
|
90
|
+
o.sDsSenha = @senha
|
91
|
+
o.nCdServico = servicos.collect{|s| s.to_s }.join(',')
|
92
|
+
o.sCepOrigem = cep_origem
|
93
|
+
o.sCepDestino = cep_destino
|
94
|
+
|
95
|
+
#Package Informations
|
96
|
+
o.nVlPeso = pacote.peso
|
97
|
+
o.nCdFormato = pacote.formato
|
98
|
+
#Dimensions
|
99
|
+
o.nVlComprimento = pacote.comprimento
|
100
|
+
o.nVlAltura = pacote.altura
|
101
|
+
o.nVlLargura = pacote.largura
|
102
|
+
o.nVlDiametro = pacote.diametro
|
103
|
+
# other options
|
104
|
+
o.sCdMaoPropria = pacote.mao_propria ? 'S' : 'N'
|
105
|
+
o.nVlValorDeclarado = pacote.valor_declarado
|
106
|
+
o.sCdAvisoRecebimento = pacote.aviso_recebimento ? 'S' : 'N'
|
107
|
+
end
|
108
|
+
|
109
|
+
return Result.new(@wsdl_client.CalcPrecoPrazo(calcPrecoPrazo))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class Service
|
114
|
+
attr_accessor(:codigo,
|
115
|
+
:valor,
|
116
|
+
:valor_mao_propria,
|
117
|
+
:valor_aviso_recebimento,
|
118
|
+
:valor_declarado,
|
119
|
+
:prazo_entrega,
|
120
|
+
:entrega_domiciliar,
|
121
|
+
:entrega_sabado,
|
122
|
+
:valor_mao_propria,
|
123
|
+
:error,
|
124
|
+
:msg_error)
|
125
|
+
|
126
|
+
def initialize
|
127
|
+
yield self if block_given?
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class Result
|
132
|
+
def initialize soap_result
|
133
|
+
@soap_result = soap_result
|
134
|
+
end
|
135
|
+
|
136
|
+
def soap_result
|
137
|
+
@soap_result
|
138
|
+
end
|
139
|
+
|
140
|
+
def services
|
141
|
+
results = Hash.new
|
142
|
+
|
143
|
+
@soap_result.calcPrecoPrazoResult['Servicos']['cServico'].each do |cservico|
|
144
|
+
results[cservico['Codigo'].to_s] = Service.new do |s|
|
145
|
+
s.codigo = cservico['Codigo']
|
146
|
+
s.valor = cservico['Valor']
|
147
|
+
s.prazo_entrega = cservico['PrazoEntrega']
|
148
|
+
#Dados adicionais Valor
|
149
|
+
s.valor_mao_propria = cservico['ValorMaoPropria']
|
150
|
+
s.valor_aviso_recebimento = cservico['ValorAvisoRecebimento']
|
151
|
+
s.valor_declarado = cservico['ValorDeclarado']
|
152
|
+
#Dados adicionais entrega
|
153
|
+
s.entrega_domiciliar = cservico['EntregaDomiciliar']
|
154
|
+
s.entrega_sabado = cservico['EntregaSabado']
|
155
|
+
#Informacoes de Erro
|
156
|
+
s.error = cservico['Erro'] == 1
|
157
|
+
s.msg_error = cservico['MsgErro']
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
results
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: correios-ws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew S Aguiar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: soap4r
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: correios-ws uses correios web-services SOAP to calculate shipping
|
31
|
+
email:
|
32
|
+
- andrewaguiar6@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- correios-ws.gemspec
|
43
|
+
- lib/correios-ws.rb
|
44
|
+
- lib/correios-ws/version.rb
|
45
|
+
homepage: http://www.github.com/andrewaguiar/correios-ws
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: correios shipping calculation using SOAP
|
69
|
+
test_files: []
|