correios-frete 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +33 -17
- data/README_v0.3.0.rdoc +164 -0
- data/Rakefile +2 -2
- data/correios-frete.gemspec +9 -4
- data/lib/correios-frete.rb +1 -0
- data/lib/correios/frete.rb +5 -51
- data/lib/correios/frete/calculador.rb +60 -0
- data/lib/correios/frete/logger.rb +23 -0
- data/lib/correios/frete/parser.rb +12 -8
- data/lib/correios/frete/servico.rb +62 -58
- data/lib/correios/frete/version.rb +3 -3
- data/lib/correios/frete/web_service.rb +46 -27
- data/spec/correios/frete/calculador_spec.rb +120 -0
- data/spec/correios/frete/web_service_spec.rb +25 -14
- data/spec/correios/frete_spec.rb +36 -93
- metadata +9 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
== Versão 1.0.0
|
2
|
+
- Aviso: Quebra de compatibilidade com a versão 0.3.0.
|
3
|
+
- Novo: Adicionado log de requisição e resposta do Web Service dos Correios.
|
4
|
+
|
1
5
|
== Versão 0.3.0
|
2
6
|
- Novo: Métodos diretos para cálculo de um serviço de frete por vez. Exemplo: Correios::Frete#calcular_sedex.
|
7
|
+
|
3
8
|
== Versão 0.2.1
|
4
9
|
- Melhoria: Alias Correios::Frete::Servico#sucesso? para Correios::Frete::Servico#success?
|
5
10
|
- Melhoria: Alias Correios::Frete::Servico#erro? para Correios::Frete::Servico#error?
|
data/README.rdoc
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
= correios-frete
|
2
2
|
|
3
|
+
---
|
4
|
+
Esta documentação é da <b>versão 1.0.0</b>.
|
5
|
+
Para a versão 0.3.0, por favor veja {README_v0.3.0.rdoc}[https://github.com/prodis/correios-frete/blob/master/README_v0.3.0.rdoc]
|
6
|
+
---
|
7
|
+
|
3
8
|
Cálculo de frete utilizando o Web Service dos Correios (http://www.correios.com.br/webservices).
|
4
9
|
|
5
|
-
|
10
|
+
Os serviços de frete suportados são PAC, SEDEX, SEDEX 10, SEDEX Hoje e e-SEDEX (necessário informar código de empresa e senha).
|
6
11
|
|
7
12
|
== Instalando
|
8
13
|
|
@@ -17,12 +22,12 @@ Serviços de frete suportados são PAC, SEDEX, SEDEX 10, SEDEX Hoje e e-SEDEX (n
|
|
17
22
|
|
18
23
|
require 'correios-frete'
|
19
24
|
|
20
|
-
frete = Correios::Frete.new :cep_origem => "04094-050",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
frete = Correios::Frete::Calculador.new :cep_origem => "04094-050",
|
26
|
+
:cep_destino => "90619-900",
|
27
|
+
:peso => 0.3,
|
28
|
+
:comprimento => 30,
|
29
|
+
:largura => 15,
|
30
|
+
:altura => 2
|
26
31
|
|
27
32
|
Cálculo de vários serviços ao mesmo tempo:
|
28
33
|
|
@@ -72,6 +77,17 @@ Usando a interface pública em inglês:
|
|
72
77
|
servico.success? # => true
|
73
78
|
servico.error? # => false
|
74
79
|
|
80
|
+
== Log
|
81
|
+
|
82
|
+
Por padrão, cada chamada ao Web Service dos Correios é logada usando STDOUT.
|
83
|
+
|
84
|
+
Para desabilitar o log ou configurar um outro mecanismo de log, você pode configurar o módulo Correios::Frete.
|
85
|
+
|
86
|
+
Correios::Frete.configure do |config|
|
87
|
+
config.log_enabled = false # Desabilita o log
|
88
|
+
config.logger = Rails.logger # Usa o logger do Rails
|
89
|
+
end
|
90
|
+
|
75
91
|
== Informações adicionais
|
76
92
|
|
77
93
|
=== Serviços suportados
|
@@ -82,18 +98,18 @@ Usando a interface pública em inglês:
|
|
82
98
|
:e_sedex
|
83
99
|
|
84
100
|
|
85
|
-
=== Maneiras de configurar atributos no construtor de Correios::Frete
|
101
|
+
=== Maneiras de configurar atributos no construtor de Correios::Frete::Calculador
|
86
102
|
|
87
103
|
==== Com um hash
|
88
|
-
frete = Correios::Frete.new :cep_origem => "04094-050",
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
104
|
+
frete = Correios::Frete::Calculador.new :cep_origem => "04094-050",
|
105
|
+
:cep_destino => "90619-900",
|
106
|
+
:peso => 0.3,
|
107
|
+
:comprimento => 30,
|
108
|
+
:largura => 15,
|
109
|
+
:altura => 2
|
94
110
|
|
95
111
|
==== Com um bloco
|
96
|
-
frete = Correios::Frete.new do |f|
|
112
|
+
frete = Correios::Frete::Calculador.new do |f|
|
97
113
|
f.cep_origem = "04094-050"
|
98
114
|
f.cep_destino = "90619-900"
|
99
115
|
f.peso = 0.3
|
@@ -103,7 +119,7 @@ Usando a interface pública em inglês:
|
|
103
119
|
end
|
104
120
|
|
105
121
|
|
106
|
-
=== Atributos de Correios::Frete
|
122
|
+
=== Atributos de Correios::Frete::Calculador
|
107
123
|
|
108
124
|
==== String
|
109
125
|
cep_origem, cep_destino, codigo_empresa, senha
|
@@ -134,7 +150,7 @@ Usando a interface pública em inglês:
|
|
134
150
|
|
135
151
|
(The MIT License)
|
136
152
|
|
137
|
-
{Prodis a.k.a. Fernando Hamasaki
|
153
|
+
{Prodis a.k.a. Fernando Hamasaki}[http://prodis.blog.br]
|
138
154
|
|
139
155
|
Copyright (c) 2011 Prodis
|
140
156
|
|
data/README_v0.3.0.rdoc
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
= correios-frete
|
2
|
+
|
3
|
+
---
|
4
|
+
Esta documentação é da <b>versão 0.3.0</b>.
|
5
|
+
Para a versão 1.0.0 ou acima, por favor veja {README.rdoc}[https://github.com/prodis/correios-frete/blob/master/README.rdoc]
|
6
|
+
---
|
7
|
+
|
8
|
+
Cálculo de frete utilizando o Web Service dos Correios (http://www.correios.com.br/webservices).
|
9
|
+
|
10
|
+
Os serviços de frete suportados são PAC, SEDEX, SEDEX 10, SEDEX Hoje e e-SEDEX (necessário informar código de empresa e senha).
|
11
|
+
|
12
|
+
== Instalando
|
13
|
+
|
14
|
+
=== Gemfile
|
15
|
+
gem 'correios-frete'
|
16
|
+
|
17
|
+
=== Instalação direta
|
18
|
+
$ gem install correios-frete
|
19
|
+
|
20
|
+
|
21
|
+
== Usando
|
22
|
+
|
23
|
+
require 'correios-frete'
|
24
|
+
|
25
|
+
frete = Correios::Frete.new :cep_origem => "04094-050",
|
26
|
+
:cep_destino => "90619-900",
|
27
|
+
:peso => 0.3,
|
28
|
+
:comprimento => 30,
|
29
|
+
:largura => 15,
|
30
|
+
:altura => 2
|
31
|
+
|
32
|
+
Cálculo de vários serviços ao mesmo tempo:
|
33
|
+
|
34
|
+
servicos = frete.calcular :sedex, :pac
|
35
|
+
|
36
|
+
servicos[:sedex].nome # => "SEDEX"
|
37
|
+
servicos[:sedex].valor # => 26.2
|
38
|
+
servicos[:sedex].prazo_entrega # => 1
|
39
|
+
|
40
|
+
servicos[:pac].nome # => "PAC"
|
41
|
+
servicos[:pac].valor # => 10.0
|
42
|
+
servicos[:pac].prazo_entrega # => 5
|
43
|
+
|
44
|
+
Cálculo de um serviço de frete passando o serviço para parâmetro:
|
45
|
+
|
46
|
+
servico = frete.calcular :sedex
|
47
|
+
service.nome # => "SEDEX"
|
48
|
+
servico.valor # => 26.2
|
49
|
+
servico.prazo_entrega # => 1
|
50
|
+
|
51
|
+
servico = frete.calcular :pac
|
52
|
+
service.nome # => "PAC"
|
53
|
+
servico.valor # => 10.0
|
54
|
+
servico.prazo_entrega # => 5
|
55
|
+
|
56
|
+
Cálculo de um serviço de frete chamando o método direto do serviço:
|
57
|
+
|
58
|
+
servico = frete.calcular_sedex
|
59
|
+
service.nome # => "SEDEX"
|
60
|
+
servico.valor # => 26.2
|
61
|
+
servico.prazo_entrega # => 1
|
62
|
+
|
63
|
+
servico = frete.calcular_pac
|
64
|
+
service.nome # => "PAC"
|
65
|
+
servico.valor # => 10.0
|
66
|
+
servico.prazo_entrega # => 5
|
67
|
+
|
68
|
+
Verificação de sucesso e erro:
|
69
|
+
|
70
|
+
servico = frete.calcular_sedex
|
71
|
+
servico.sucesso? # => true
|
72
|
+
servico.erro? # => false
|
73
|
+
|
74
|
+
Usando a interface pública em inglês:
|
75
|
+
|
76
|
+
servico = frete.calculate_sedex
|
77
|
+
servico.success? # => true
|
78
|
+
servico.error? # => false
|
79
|
+
|
80
|
+
== Informações adicionais
|
81
|
+
|
82
|
+
=== Serviços suportados
|
83
|
+
:pac
|
84
|
+
:sedex
|
85
|
+
:sedex_10
|
86
|
+
:sedex_hoje
|
87
|
+
:e_sedex
|
88
|
+
|
89
|
+
|
90
|
+
=== Maneiras de configurar atributos no construtor de Correios::Frete
|
91
|
+
|
92
|
+
==== Com um hash
|
93
|
+
frete = Correios::Frete.new :cep_origem => "04094-050",
|
94
|
+
:cep_destino => "90619-900",
|
95
|
+
:peso => 0.3,
|
96
|
+
:comprimento => 30,
|
97
|
+
:largura => 15,
|
98
|
+
:altura => 2
|
99
|
+
|
100
|
+
==== Com um bloco
|
101
|
+
frete = Correios::Frete.new do |f|
|
102
|
+
f.cep_origem = "04094-050"
|
103
|
+
f.cep_destino = "90619-900"
|
104
|
+
f.peso = 0.3
|
105
|
+
f.comprimento = 30
|
106
|
+
f.largura = 15
|
107
|
+
f.altura = 2
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
=== Atributos de Correios::Frete
|
112
|
+
|
113
|
+
==== String
|
114
|
+
cep_origem, cep_destino, codigo_empresa, senha
|
115
|
+
==== Float
|
116
|
+
peso, valor_declarado
|
117
|
+
==== Fixnum
|
118
|
+
comprimento, largura, altura, diametro
|
119
|
+
==== Boolean
|
120
|
+
mao_propria, aviso_recebimento
|
121
|
+
==== Symbol
|
122
|
+
formato (:caixa_pacote, :rolo_prisma)
|
123
|
+
|
124
|
+
|
125
|
+
=== Atributos de Correios::Frete::Servico
|
126
|
+
|
127
|
+
==== String
|
128
|
+
codigo, erro, msg_erro, nome
|
129
|
+
==== Float
|
130
|
+
valor, valor_mao_propria, valor_aviso_recebimento, valor_valor_declarado
|
131
|
+
==== Fixnum
|
132
|
+
prazo_entrega
|
133
|
+
==== Boolean
|
134
|
+
entrega_domiciliar, entrega_sabado
|
135
|
+
==== Symbol
|
136
|
+
tipo (:pac, :sedex, :sedex_10, :sedex_hoje, :e_sedex)
|
137
|
+
|
138
|
+
== Copyright
|
139
|
+
|
140
|
+
(The MIT License)
|
141
|
+
|
142
|
+
{Prodis a.k.a. Fernando Hamasaki}[http://prodis.blog.br]
|
143
|
+
|
144
|
+
Copyright (c) 2011 Prodis
|
145
|
+
|
146
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
147
|
+
a copy of this software and associated documentation files (the
|
148
|
+
"Software"), to deal in the Software without restriction, including
|
149
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
150
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
151
|
+
permit persons to whom the Software is furnished to do so, subject to
|
152
|
+
the following conditions:
|
153
|
+
|
154
|
+
The above copyright notice and this permission notice shall be
|
155
|
+
included in all copies or substantial portions of the Software.
|
156
|
+
|
157
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
158
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
159
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
160
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
161
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
162
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
163
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
164
|
+
|
data/Rakefile
CHANGED
@@ -20,8 +20,8 @@ Jeweler::Tasks.new do |gem|
|
|
20
20
|
gem.summary = %Q{Cálculo de frete dos Correios.}
|
21
21
|
gem.description = %Q{Cálculo de frete utilizando o Web Service dos Correios (http://www.correios.com.br/webservices). Serviços de frete suportados são PAC, SEDEX, SEDEX 10, SEDEX Hoje e e-SEDEX (necessário informar código de empresa e senha).}
|
22
22
|
gem.email = "prodis@gmail.com"
|
23
|
-
gem.authors = ["Prodis a.k.a. Fernando Hamasaki
|
24
|
-
gem.version = Correios::Frete::Version::
|
23
|
+
gem.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
24
|
+
gem.version = Correios::Frete::Version::VERSION
|
25
25
|
# dependencies defined in Gemfile
|
26
26
|
end
|
27
27
|
Jeweler::RubygemsDotOrgTasks.new
|
data/correios-frete.gemspec
CHANGED
@@ -5,15 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{correios-frete}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Prodis a.k.a. Fernando Hamasaki
|
12
|
-
s.date = %q{2011-08-
|
11
|
+
s.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
12
|
+
s.date = %q{2011-08-10}
|
13
13
|
s.description = %q{Cálculo de frete utilizando o Web Service dos Correios (http://www.correios.com.br/webservices). Serviços de frete suportados são PAC, SEDEX, SEDEX 10, SEDEX Hoje e e-SEDEX (necessário informar código de empresa e senha).}
|
14
14
|
s.email = %q{prodis@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"README.rdoc"
|
16
|
+
"README.rdoc",
|
17
|
+
"README_v0.3.0.rdoc"
|
17
18
|
]
|
18
19
|
s.files = [
|
19
20
|
".document",
|
@@ -22,14 +23,18 @@ Gem::Specification.new do |s|
|
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"README.rdoc",
|
26
|
+
"README_v0.3.0.rdoc",
|
25
27
|
"Rakefile",
|
26
28
|
"correios-frete.gemspec",
|
27
29
|
"lib/correios-frete.rb",
|
28
30
|
"lib/correios/frete.rb",
|
31
|
+
"lib/correios/frete/calculador.rb",
|
32
|
+
"lib/correios/frete/logger.rb",
|
29
33
|
"lib/correios/frete/parser.rb",
|
30
34
|
"lib/correios/frete/servico.rb",
|
31
35
|
"lib/correios/frete/version.rb",
|
32
36
|
"lib/correios/frete/web_service.rb",
|
37
|
+
"spec/correios/frete/calculador_spec.rb",
|
33
38
|
"spec/correios/frete/parser_spec.rb",
|
34
39
|
"spec/correios/frete/servico_spec.rb",
|
35
40
|
"spec/correios/frete/web_service_spec.rb",
|
data/lib/correios-frete.rb
CHANGED
data/lib/correios/frete.rb
CHANGED
@@ -1,58 +1,12 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
3
|
-
class Frete
|
4
|
-
attr_accessor :cep_origem, :cep_destino
|
5
|
-
attr_accessor :peso, :comprimento, :altura, :largura, :diametro
|
6
|
-
attr_accessor :formato, :mao_propria, :aviso_recebimento, :valor_declarado
|
7
|
-
attr_accessor :codigo_empresa, :senha
|
8
|
-
attr_writer :web_service, :parser
|
9
|
-
|
10
|
-
DEFAULT_OPTIONS = {
|
11
|
-
:peso => 0.0,
|
12
|
-
:comprimento => 0.0,
|
13
|
-
:altura => 0.0,
|
14
|
-
:largura => 0.0,
|
15
|
-
:diametro => 0.0,
|
16
|
-
:formato => :caixa_pacote,
|
17
|
-
:mao_propria => false,
|
18
|
-
:aviso_recebimento => false,
|
19
|
-
:valor_declarado => 0.0
|
20
|
-
}
|
2
|
+
require 'correios/frete/logger'
|
21
3
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
4
|
+
module Correios
|
5
|
+
module Frete
|
6
|
+
extend Logger
|
26
7
|
|
8
|
+
def self.configure
|
27
9
|
yield self if block_given?
|
28
10
|
end
|
29
|
-
|
30
|
-
def web_service
|
31
|
-
@web_service ||= Correios::Frete::WebService.new
|
32
|
-
end
|
33
|
-
|
34
|
-
def parser
|
35
|
-
@parser ||= Correios::Frete::Parser.new
|
36
|
-
end
|
37
|
-
|
38
|
-
def calcular(*service_types)
|
39
|
-
response = web_service.request(self, service_types)
|
40
|
-
services = parser.servicos(response)
|
41
|
-
|
42
|
-
if service_types.size == 1
|
43
|
-
services.values.first
|
44
|
-
else
|
45
|
-
services
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
alias calculate calcular
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def method_missing(method_name, *args)
|
54
|
-
return calcular($2.to_sym) if method_name.to_s =~ /^(calcular|calculate)_(.*)/ && Correios::Frete::Servico.code_from_type($2.to_sym)
|
55
|
-
super
|
56
|
-
end
|
57
11
|
end
|
58
12
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Correios
|
3
|
+
module Frete
|
4
|
+
class Calculador
|
5
|
+
attr_accessor :cep_origem, :cep_destino
|
6
|
+
attr_accessor :peso, :comprimento, :altura, :largura, :diametro
|
7
|
+
attr_accessor :formato, :mao_propria, :aviso_recebimento, :valor_declarado
|
8
|
+
attr_accessor :codigo_empresa, :senha
|
9
|
+
attr_writer :web_service, :parser
|
10
|
+
|
11
|
+
DEFAULT_OPTIONS = {
|
12
|
+
:peso => 0.0,
|
13
|
+
:comprimento => 0.0,
|
14
|
+
:altura => 0.0,
|
15
|
+
:largura => 0.0,
|
16
|
+
:diametro => 0.0,
|
17
|
+
:formato => :caixa_pacote,
|
18
|
+
:mao_propria => false,
|
19
|
+
:aviso_recebimento => false,
|
20
|
+
:valor_declarado => 0.0
|
21
|
+
}
|
22
|
+
|
23
|
+
def initialize(options = {})
|
24
|
+
DEFAULT_OPTIONS.merge(options).each do |attr, value|
|
25
|
+
self.send("#{attr}=", value)
|
26
|
+
end
|
27
|
+
|
28
|
+
yield self if block_given?
|
29
|
+
end
|
30
|
+
|
31
|
+
def web_service
|
32
|
+
@web_service ||= Correios::Frete::WebService.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def parser
|
36
|
+
@parser ||= Correios::Frete::Parser.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def calcular(*service_types)
|
40
|
+
response = web_service.request(self, service_types)
|
41
|
+
services = parser.servicos(response)
|
42
|
+
|
43
|
+
if service_types.size == 1
|
44
|
+
services.values.first
|
45
|
+
else
|
46
|
+
services
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
alias calculate calcular
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def method_missing(method_name, *args)
|
55
|
+
return calcular($2.to_sym) if method_name.to_s =~ /^(calcular|calculate)_(.*)/ && Correios::Frete::Servico.code_from_type($2.to_sym)
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Correios
|
5
|
+
module Frete
|
6
|
+
module Logger
|
7
|
+
attr_writer :log_enabled
|
8
|
+
attr_writer :logger
|
9
|
+
|
10
|
+
def log_enabled?
|
11
|
+
@log_enabled != false
|
12
|
+
end
|
13
|
+
|
14
|
+
def logger
|
15
|
+
@logger ||= ::Logger.new STDOUT
|
16
|
+
end
|
17
|
+
|
18
|
+
def log(message)
|
19
|
+
logger.info(message) if log_enabled?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'nokogiri'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Correios
|
5
|
+
module Frete
|
6
|
+
class Parser
|
7
|
+
def servicos(xml)
|
8
|
+
servicos = {}
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
Nokogiri::XML(xml).root.elements.each do |element|
|
11
|
+
servico = Correios::Frete::Servico.new.parse(element.to_xml)
|
12
|
+
servicos[servico.tipo] = servico
|
13
|
+
end
|
12
14
|
|
13
|
-
|
15
|
+
servicos
|
16
|
+
end
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
@@ -1,77 +1,81 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'sax-machine'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Correios
|
5
|
+
module Frete
|
6
|
+
class Servico
|
7
|
+
include SAXMachine
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
AVAILABLE_SERVICES = {
|
10
|
+
"41106" => { :type => :pac , :name => "PAC" },
|
11
|
+
"40010" => { :type => :sedex , :name => "SEDEX" },
|
12
|
+
"40215" => { :type => :sedex_10 , :name => "SEDEX 10" },
|
13
|
+
"40290" => { :type => :sedex_hoje, :name => "SEDEX Hoje" },
|
14
|
+
"81019" => { :type => :e_sedex , :name => "e-SEDEX" }
|
15
|
+
}
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
element :Codigo, :as => :codigo
|
18
|
+
element :Valor, :as => :valor
|
19
|
+
element :PrazoEntrega, :as => :prazo_entrega
|
20
|
+
element :ValorMaoPropria, :as => :valor_mao_propria
|
21
|
+
element :ValorAvisoRecebimento, :as => :valor_aviso_recebimento
|
22
|
+
element :ValorValorDeclarado, :as => :valor_valor_declarado
|
23
|
+
element :EntregaDomiciliar, :as => :entrega_domiciliar
|
24
|
+
element :EntregaSabado, :as => :entrega_sabado
|
25
|
+
element :Erro, :as => :erro
|
26
|
+
element :MsgErro, :as => :msg_erro
|
27
|
+
attr_reader :tipo, :nome
|
26
28
|
|
27
|
-
|
29
|
+
alias_method :original_parse, :parse
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
def parse(xml_text)
|
32
|
+
original_parse xml_text
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
if AVAILABLE_SERVICES[codigo]
|
35
|
+
@tipo = AVAILABLE_SERVICES[codigo][:type]
|
36
|
+
@nome = AVAILABLE_SERVICES[codigo][:name]
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
cast_to_float! :valor, :valor_mao_propria, :valor_aviso_recebimento, :valor_valor_declarado
|
40
|
+
cast_to_int! :prazo_entrega
|
41
|
+
cast_to_boolean! :entrega_domiciliar, :entrega_sabado
|
42
|
+
self
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def success?
|
46
|
+
erro == "0"
|
47
|
+
end
|
48
|
+
alias sucesso? success?
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def error?
|
51
|
+
!success?
|
52
|
+
end
|
53
|
+
alias erro? error?
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def self.code_from_type(type)
|
56
|
+
# I don't use select method for Ruby 1.8.7 compatibility.
|
57
|
+
AVAILABLE_SERVICES.map { |key, value| key if value[:type] == type }.compact.first
|
58
|
+
end
|
57
59
|
|
58
|
-
|
60
|
+
private
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
def cast_to_float!(*attributes)
|
63
|
+
attributes.each do |attr|
|
64
|
+
instance_variable_set("@#{attr}", send(attr).to_s.gsub("," ,".").to_f)
|
65
|
+
end
|
66
|
+
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
def cast_to_int!(*attributes)
|
69
|
+
attributes.each do |attr|
|
70
|
+
instance_variable_set("@#{attr}", send(attr).to_i)
|
71
|
+
end
|
72
|
+
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
def cast_to_boolean!(*attributes)
|
75
|
+
attributes.each do |attr|
|
76
|
+
instance_variable_set("@#{attr}", send(attr) == "S")
|
77
|
+
end
|
78
|
+
end
|
75
79
|
end
|
76
80
|
end
|
77
81
|
end
|
@@ -2,36 +2,55 @@
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'uri'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module Correios
|
6
|
+
module Frete
|
7
|
+
class WebService
|
8
|
+
URL = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx"
|
9
|
+
FORMATS = { :caixa_pacote => 1, :rolo_prisma => 2 }
|
10
|
+
CONDITIONS = { true => "S", false => "N" }
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def request(frete, service_types)
|
13
|
+
@url = "#{URL}?#{params_for(frete, service_types)}"
|
14
|
+
with_log { Net::HTTP.get_response URI.parse(@url) }
|
15
|
+
end
|
13
16
|
|
14
|
-
|
17
|
+
private
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
def params_for(frete, service_types)
|
20
|
+
"sCepOrigem=#{frete.cep_origem}&" +
|
21
|
+
"sCepDestino=#{frete.cep_destino}&" +
|
22
|
+
"nVlPeso=#{frete.peso}&" +
|
23
|
+
"nVlComprimento=#{frete.comprimento}&" +
|
24
|
+
"nVlAltura=#{frete.altura}&" +
|
25
|
+
"nVlLargura=#{frete.largura}&" +
|
26
|
+
"nVlDiametro=#{frete.diametro}&" +
|
27
|
+
"nCdFormato=#{FORMATS[frete.formato]}&" +
|
28
|
+
"sCdMaoPropria=#{CONDITIONS[frete.mao_propria]}&" +
|
29
|
+
"sCdAvisoRecebimento=#{CONDITIONS[frete.aviso_recebimento]}&" +
|
30
|
+
"nVlValorDeclarado=#{frete.valor_declarado}&" +
|
31
|
+
"nCdServico=#{service_codes_for(service_types)}&" +
|
32
|
+
"nCdEmpresa=#{frete.codigo_empresa}&" +
|
33
|
+
"sDsSenha=#{frete.senha}&" +
|
34
|
+
"StrRetorno=xml"
|
35
|
+
end
|
36
|
+
|
37
|
+
def service_codes_for(service_types)
|
38
|
+
service_types.map { |type| Correios::Frete::Servico.code_from_type(type) }.join(",")
|
39
|
+
end
|
40
|
+
|
41
|
+
def with_log
|
42
|
+
Correios::Frete.log "Correios-Frete Request:\n#{@url}"
|
43
|
+
response = yield
|
44
|
+
Correios::Frete.log format_response_message(response)
|
45
|
+
response.body
|
46
|
+
end
|
33
47
|
|
34
|
-
|
35
|
-
|
48
|
+
def format_response_message(response)
|
49
|
+
message = "Correios-Frete Response:\n"
|
50
|
+
message << "HTTP/#{response.http_version} #{response.code} #{response.message}\n"
|
51
|
+
response.each_header { |header| message << "#{header}: #{response[header]}\n" }
|
52
|
+
message << response.body
|
53
|
+
end
|
54
|
+
end
|
36
55
|
end
|
37
56
|
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Correios::Frete::Calculador do
|
5
|
+
describe ".new" do
|
6
|
+
context "create with default value of" do
|
7
|
+
before(:each) { @frete = Correios::Frete::Calculador.new }
|
8
|
+
|
9
|
+
{ :peso => 0.0,
|
10
|
+
:comprimento => 0.0,
|
11
|
+
:altura => 0.0,
|
12
|
+
:largura => 0.0,
|
13
|
+
:diametro => 0.0,
|
14
|
+
:formato => :caixa_pacote,
|
15
|
+
:mao_propria => false,
|
16
|
+
:aviso_recebimento => false,
|
17
|
+
:valor_declarado => 0.0
|
18
|
+
}.each do |attr, value|
|
19
|
+
it attr do
|
20
|
+
@frete.send(attr).should == value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
{ :cep_origem => "01000-000",
|
26
|
+
:cep_destino => "021222-222",
|
27
|
+
:peso => 0.321,
|
28
|
+
:comprimento => 12.5,
|
29
|
+
:altura => 1.4,
|
30
|
+
:largura => 4.6,
|
31
|
+
:diametro => 5.0,
|
32
|
+
:formato => :rolo_prisma,
|
33
|
+
:mao_propria => true,
|
34
|
+
:aviso_recebimento => true,
|
35
|
+
:valor_declarado => 1.99,
|
36
|
+
:codigo_empresa => "1234567890",
|
37
|
+
:senha => "senha",
|
38
|
+
:web_service => Correios::Frete::WebService.new,
|
39
|
+
:parser => Correios::Frete::Parser.new
|
40
|
+
}.each do |attr, value|
|
41
|
+
context "when #{attr} is supplied" do
|
42
|
+
it "sets #{attr}" do
|
43
|
+
@frete = Correios::Frete::Calculador.new(attr => value)
|
44
|
+
@frete.send(attr).should == value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when #{attr} is supplied in a block" do
|
49
|
+
it "sets #{attr}" do
|
50
|
+
@frete = Correios::Frete::Calculador.new { |f| f.send("#{attr}=", value) }
|
51
|
+
@frete.send(attr).should == value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#calcular" do
|
58
|
+
before :each do
|
59
|
+
@web_service = Correios::Frete::WebService.new
|
60
|
+
@parser = Correios::Frete::Parser.new
|
61
|
+
@frete = Correios::Frete::Calculador.new(:web_service => @web_service, :parser => @parser)
|
62
|
+
end
|
63
|
+
|
64
|
+
context "to many services" do
|
65
|
+
before :each do
|
66
|
+
@xml = '<?xml version="1.0" encoding="ISO-8859-1" ?><Servicos><cServico><Codigo>41106</Codigo><Valor>15,70</Valor><PrazoEntrega>3</PrazoEntrega><ValorMaoPropria>3,70</ValorMaoPropria><ValorAvisoRecebimento>0,00</ValorAvisoRecebimento><ValorValorDeclarado>1,50</ValorValorDeclarado><EntregaDomiciliar>S</EntregaDomiciliar><EntregaSabado>N</EntregaSabado><Erro>0</Erro><MsgErro></MsgErro></cServico><cServico><Codigo>40010</Codigo><Valor>17,80</Valor><PrazoEntrega>1</PrazoEntrega><ValorMaoPropria>3,70</ValorMaoPropria><ValorAvisoRecebimento>0,00</ValorAvisoRecebimento><ValorValorDeclarado>1,50</ValorValorDeclarado><EntregaDomiciliar>S</EntregaDomiciliar><EntregaSabado>S</EntregaSabado><Erro>0</Erro><MsgErro></MsgErro></cServico></Servicos>'
|
67
|
+
@servicos = { :pac => Correios::Frete::Servico.new, :sedex => Correios::Frete::Servico.new }
|
68
|
+
|
69
|
+
@parser.stub(:servicos).and_return(@servicos)
|
70
|
+
@web_service.stub(:request).with(@frete, [:pac, :sedex]).and_return(@xml)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns all services" do
|
74
|
+
@frete.calcular(:pac, :sedex).should == @servicos
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "to one service" do
|
79
|
+
before :each do
|
80
|
+
@xml = '<?xml version="1.0" encoding="ISO-8859-1" ?><cServico><Codigo>40010</Codigo><Valor>17,80</Valor><PrazoEntrega>1</PrazoEntrega><ValorMaoPropria>3,70</ValorMaoPropria><ValorAvisoRecebimento>0,00</ValorAvisoRecebimento><ValorValorDeclarado>1,50</ValorValorDeclarado><EntregaDomiciliar>S</EntregaDomiciliar><EntregaSabado>S</EntregaSabado><Erro>0</Erro><MsgErro></MsgErro></cServico></Servicos>'
|
81
|
+
@servico = Correios::Frete::Servico.new
|
82
|
+
|
83
|
+
@parser.stub(:servicos).and_return(:sedex => @servico)
|
84
|
+
@web_service.stub(:request).with(@frete, [:sedex]).and_return(@xml)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns only one service" do
|
88
|
+
@frete.calcular(:sedex).should == @servico
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
["calcular", "calculate"].each do |method_name|
|
94
|
+
Correios::Frete::Servico::AVAILABLE_SERVICES.each do |key, service|
|
95
|
+
describe "##{method_name}_#{service[:type]}" do
|
96
|
+
before :each do
|
97
|
+
web_service = Correios::Frete::WebService.new
|
98
|
+
parser = Correios::Frete::Parser.new
|
99
|
+
@frete = Correios::Frete::Calculador.new(:web_service => web_service, :parser => parser)
|
100
|
+
@servico = Correios::Frete::Servico.new
|
101
|
+
|
102
|
+
parser.stub(:servicos).and_return(service[:type] => @servico)
|
103
|
+
web_service.stub(:request).with(@frete, [service[:type]]).and_return("XML")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "calculates #{service[:name]}" do
|
107
|
+
@frete.send("#{method_name}_#{service[:type]}").should == @servico
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "##{method_name}_servico_que_nao_existe" do
|
113
|
+
before(:each) { @frete = Correios::Frete::Calculador.new }
|
114
|
+
|
115
|
+
it "raises NoMethodError" do
|
116
|
+
expect { @frete.send("#{method_name}_servico_que_nao_existe") }.to raise_error(NoMethodError)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -4,19 +4,20 @@ require 'spec_helper'
|
|
4
4
|
describe Correios::Frete::WebService do
|
5
5
|
describe "#request" do
|
6
6
|
before :each do
|
7
|
-
@frete = Correios::Frete.new :cep_origem => "01000-000",
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
@frete = Correios::Frete::Calculador.new :cep_origem => "01000-000",
|
8
|
+
:cep_destino => "021222-222",
|
9
|
+
:peso => 0.321,
|
10
|
+
:comprimento => 12.5,
|
11
|
+
:altura => 1.4,
|
12
|
+
:largura => 4.6,
|
13
|
+
:diametro => 5.0,
|
14
|
+
:formato => :rolo_prisma,
|
15
|
+
:mao_propria => true,
|
16
|
+
:aviso_recebimento => false,
|
17
|
+
:valor_declarado => 1.99,
|
18
|
+
:codigo_empresa => "1234567890",
|
19
|
+
:senha => "senha"
|
20
|
+
|
20
21
|
url = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?" +
|
21
22
|
"sCepOrigem=01000-000&" +
|
22
23
|
"sCepDestino=021222-222&" +
|
@@ -33,10 +34,20 @@ describe Correios::Frete::WebService do
|
|
33
34
|
"nCdEmpresa=1234567890&" +
|
34
35
|
"sDsSenha=senha&" +
|
35
36
|
"StrRetorno=xml"
|
36
|
-
|
37
|
+
|
38
|
+
response = Net::HTTPOK.new nil, 200, "OK"
|
39
|
+
response.stub(:body).and_return("<xml><fake></fake>")
|
40
|
+
Net::HTTP.stub(:get_response).with(URI.parse(url)).and_return(response)
|
41
|
+
|
37
42
|
@web_service = Correios::Frete::WebService.new
|
38
43
|
end
|
39
44
|
|
45
|
+
around do |example|
|
46
|
+
Correios::Frete.configure { |config| config.log_enabled = false }
|
47
|
+
example.run
|
48
|
+
Correios::Frete.configure { |config| config.log_enabled = true }
|
49
|
+
end
|
50
|
+
|
40
51
|
it "returns XML response" do
|
41
52
|
@web_service.request(@frete, [:pac, :sedex]).should == "<xml><fake></fake>"
|
42
53
|
end
|
data/spec/correios/frete_spec.rb
CHANGED
@@ -2,118 +2,61 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Correios::Frete do
|
5
|
-
describe "
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
{ :peso => 0.0,
|
10
|
-
:comprimento => 0.0,
|
11
|
-
:altura => 0.0,
|
12
|
-
:largura => 0.0,
|
13
|
-
:diametro => 0.0,
|
14
|
-
:formato => :caixa_pacote,
|
15
|
-
:mao_propria => false,
|
16
|
-
:aviso_recebimento => false,
|
17
|
-
:valor_declarado => 0.0
|
18
|
-
}.each do |attr, value|
|
19
|
-
it attr do
|
20
|
-
@frete.send(attr).should == value
|
21
|
-
end
|
22
|
-
end
|
5
|
+
describe "#log_enabled?" do
|
6
|
+
it "default is true" do
|
7
|
+
Correios::Frete.log_enabled?.should be_true
|
23
8
|
end
|
24
9
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
:largura => 4.6,
|
31
|
-
:diametro => 5.0,
|
32
|
-
:formato => :rolo_prisma,
|
33
|
-
:mao_propria => true,
|
34
|
-
:aviso_recebimento => true,
|
35
|
-
:valor_declarado => 1.99,
|
36
|
-
:codigo_empresa => "1234567890",
|
37
|
-
:senha => "senha",
|
38
|
-
:web_service => Correios::Frete::WebService.new,
|
39
|
-
:parser => Correios::Frete::Parser.new
|
40
|
-
}.each do |attr, value|
|
41
|
-
context "when #{attr} is supplied" do
|
42
|
-
it "sets #{attr}" do
|
43
|
-
@frete = Correios::Frete.new(attr => value)
|
44
|
-
@frete.send(attr).should == value
|
45
|
-
end
|
10
|
+
context "when disable log" do
|
11
|
+
around do |example|
|
12
|
+
Correios::Frete.configure { |config| config.log_enabled = false }
|
13
|
+
example.run
|
14
|
+
Correios::Frete.configure { |config| config.log_enabled = true }
|
46
15
|
end
|
47
16
|
|
48
|
-
|
49
|
-
|
50
|
-
@frete = Correios::Frete.new { |f| f.send("#{attr}=", value) }
|
51
|
-
@frete.send(attr).should == value
|
52
|
-
end
|
17
|
+
it "returns false" do
|
18
|
+
Correios::Frete.log_enabled?.should be_false
|
53
19
|
end
|
54
20
|
end
|
55
21
|
end
|
56
22
|
|
57
|
-
describe "#
|
58
|
-
|
59
|
-
|
60
|
-
@parser = Correios::Frete::Parser.new
|
61
|
-
@frete = Correios::Frete.new(:web_service => @web_service, :parser => @parser)
|
62
|
-
end
|
63
|
-
|
64
|
-
context "to many services" do
|
65
|
-
before :each do
|
66
|
-
@xml = '<?xml version="1.0" encoding="ISO-8859-1" ?><Servicos><cServico><Codigo>41106</Codigo><Valor>15,70</Valor><PrazoEntrega>3</PrazoEntrega><ValorMaoPropria>3,70</ValorMaoPropria><ValorAvisoRecebimento>0,00</ValorAvisoRecebimento><ValorValorDeclarado>1,50</ValorValorDeclarado><EntregaDomiciliar>S</EntregaDomiciliar><EntregaSabado>N</EntregaSabado><Erro>0</Erro><MsgErro></MsgErro></cServico><cServico><Codigo>40010</Codigo><Valor>17,80</Valor><PrazoEntrega>1</PrazoEntrega><ValorMaoPropria>3,70</ValorMaoPropria><ValorAvisoRecebimento>0,00</ValorAvisoRecebimento><ValorValorDeclarado>1,50</ValorValorDeclarado><EntregaDomiciliar>S</EntregaDomiciliar><EntregaSabado>S</EntregaSabado><Erro>0</Erro><MsgErro></MsgErro></cServico></Servicos>'
|
67
|
-
@servicos = { :pac => Correios::Frete::Servico.new, :sedex => Correios::Frete::Servico.new }
|
68
|
-
|
69
|
-
@parser.stub(:servicos).and_return(@servicos)
|
70
|
-
@web_service.stub(:request).with(@frete, [:pac, :sedex]).and_return(@xml)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns all services" do
|
74
|
-
@frete.calcular(:pac, :sedex).should == @servicos
|
75
|
-
end
|
23
|
+
describe "#logger" do
|
24
|
+
it "default is Logger" do
|
25
|
+
Correios::Frete.logger.should be_a(Logger)
|
76
26
|
end
|
77
27
|
|
78
|
-
context "
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
@parser.stub(:servicos).and_return(:sedex => @servico)
|
84
|
-
@web_service.stub(:request).with(@frete, [:sedex]).and_return(@xml)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns only one service" do
|
88
|
-
@frete.calcular(:sedex).should == @servico
|
28
|
+
context "when set logger" do
|
29
|
+
it "returns set logger" do
|
30
|
+
fake_logger = Class.new
|
31
|
+
Correios::Frete.configure { |config| config.logger = fake_logger }
|
32
|
+
Correios::Frete.logger.should == fake_logger
|
89
33
|
end
|
90
34
|
end
|
91
35
|
end
|
92
36
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
parser = Correios::Frete::Parser.new
|
99
|
-
@frete = Correios::Frete.new(:web_service => web_service, :parser => parser)
|
100
|
-
@servico = Correios::Frete::Servico.new
|
101
|
-
|
102
|
-
parser.stub(:servicos).and_return(service[:type] => @servico)
|
103
|
-
web_service.stub(:request).with(@frete, [service[:type]]).and_return("XML")
|
104
|
-
end
|
37
|
+
describe "#log" do
|
38
|
+
before :each do
|
39
|
+
@log_stream = StringIO.new
|
40
|
+
Correios::Frete.configure { |config| config.logger = Logger.new(@log_stream) }
|
41
|
+
end
|
105
42
|
|
106
|
-
|
107
|
-
|
108
|
-
|
43
|
+
context "when log is enabled" do
|
44
|
+
it "logs the message" do
|
45
|
+
Correios::Frete.log("Some message to log.")
|
46
|
+
@log_stream.string.should include("Some message to log.")
|
109
47
|
end
|
110
48
|
end
|
111
49
|
|
112
|
-
|
113
|
-
|
50
|
+
context "when log is disabled" do
|
51
|
+
around do |example|
|
52
|
+
Correios::Frete.configure { |config| config.log_enabled = false }
|
53
|
+
example.run
|
54
|
+
Correios::Frete.configure { |config| config.log_enabled = true }
|
55
|
+
end
|
114
56
|
|
115
|
-
it "
|
116
|
-
|
57
|
+
it "does not log the message" do
|
58
|
+
Correios::Frete.log("Some message to log.")
|
59
|
+
@log_stream.string.should be_empty
|
117
60
|
end
|
118
61
|
end
|
119
62
|
end
|
metadata
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
name: correios-frete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 1.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Prodis a.k.a. Fernando Hamasaki
|
8
|
+
- Prodis a.k.a. Fernando Hamasaki
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-10 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -76,6 +76,7 @@ extensions: []
|
|
76
76
|
|
77
77
|
extra_rdoc_files:
|
78
78
|
- README.rdoc
|
79
|
+
- README_v0.3.0.rdoc
|
79
80
|
files:
|
80
81
|
- .document
|
81
82
|
- .rspec
|
@@ -83,14 +84,18 @@ files:
|
|
83
84
|
- Gemfile
|
84
85
|
- Gemfile.lock
|
85
86
|
- README.rdoc
|
87
|
+
- README_v0.3.0.rdoc
|
86
88
|
- Rakefile
|
87
89
|
- correios-frete.gemspec
|
88
90
|
- lib/correios-frete.rb
|
89
91
|
- lib/correios/frete.rb
|
92
|
+
- lib/correios/frete/calculador.rb
|
93
|
+
- lib/correios/frete/logger.rb
|
90
94
|
- lib/correios/frete/parser.rb
|
91
95
|
- lib/correios/frete/servico.rb
|
92
96
|
- lib/correios/frete/version.rb
|
93
97
|
- lib/correios/frete/web_service.rb
|
98
|
+
- spec/correios/frete/calculador_spec.rb
|
94
99
|
- spec/correios/frete/parser_spec.rb
|
95
100
|
- spec/correios/frete/servico_spec.rb
|
96
101
|
- spec/correios/frete/web_service_spec.rb
|
@@ -110,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
115
|
requirements:
|
111
116
|
- - ">="
|
112
117
|
- !ruby/object:Gem::Version
|
113
|
-
hash:
|
118
|
+
hash: 829032559
|
114
119
|
segments:
|
115
120
|
- 0
|
116
121
|
version: "0"
|