paypal-frete-facil 1.1.0 → 1.2.0
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/README.rdoc +55 -37
- data/lib/paypal-frete-facil.rb +3 -1
- data/lib/paypal/fretefacil/frete.rb +25 -26
- data/lib/paypal/fretefacil/frete_resultado.rb +22 -0
- data/lib/paypal/fretefacil/shipping.rb +45 -0
- data/lib/paypal/fretefacil/shipping_result.rb +31 -0
- data/lib/paypal/fretefacil/version.rb +1 -1
- data/lib/paypal/fretefacil/web_service.rb +11 -11
- data/paypal-frete-facil.gemspec +8 -4
- data/spec/paypal/fretefacil/{resultado_spec.rb → frete_resultado_spec.rb} +6 -6
- data/spec/paypal/fretefacil/frete_spec.rb +11 -15
- data/spec/paypal/fretefacil/shipping_result_spec.rb +57 -0
- data/spec/paypal/fretefacil/shipping_spec.rb +56 -0
- metadata +22 -18
- data/lib/paypal/fretefacil/resultado.rb +0 -35
data/README.rdoc
CHANGED
@@ -15,32 +15,40 @@ Cálculo de frete através do PayPal Frete Fácil (http://www.paypal-brasil.com.
|
|
15
15
|
|
16
16
|
require 'paypal-frete-facil'
|
17
17
|
|
18
|
+
shipping = PayPal::FreteFacil::Shipping.new :from_zip => "04094-050",
|
19
|
+
:to_zip => "90619-900",
|
20
|
+
:width => 15,
|
21
|
+
:height => 2,
|
22
|
+
:length => 30,
|
23
|
+
:weight => 0.3
|
24
|
+
|
25
|
+
result = shipping.calculate
|
26
|
+
result.value # => 14.77
|
27
|
+
|
28
|
+
Verificação de sucesso e erro:
|
29
|
+
|
30
|
+
shipping.height = 200
|
31
|
+
|
32
|
+
result = shipping.calculate
|
33
|
+
result.success? # => false
|
34
|
+
result.error? # => true
|
35
|
+
result.error_message # => "Não foi possível calcular o frete."
|
36
|
+
result.value # => 0
|
37
|
+
|
38
|
+
Usando a interface pública em português:
|
39
|
+
|
18
40
|
frete = PayPal::FreteFacil::Frete.new :cep_origem => "04094-050",
|
19
41
|
:cep_destino => "90619-900",
|
20
42
|
:largura => 15,
|
21
43
|
:altura => 2,
|
22
|
-
:
|
44
|
+
:comprimento => 30,
|
23
45
|
:peso => 0.3
|
24
46
|
|
25
47
|
resultado = frete.calcular
|
26
48
|
resultado.valor # => 14.77
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
frete.altura = 200
|
31
|
-
|
32
|
-
resultado = frete.calcular
|
33
|
-
resultado.sucesso? # => false
|
34
|
-
resultado.erro? # => true
|
35
|
-
resultado.msg_erro # => "Não foi possível calcular o frete."
|
36
|
-
|
37
|
-
Usando a interface pública em inglês:
|
38
|
-
|
39
|
-
result = frete.calculate
|
40
|
-
result.value # => 14.77
|
41
|
-
result.success? # => true
|
42
|
-
result.error? # => false
|
43
|
-
result.error_msg # => ""
|
49
|
+
resultado.sucesso? # => true
|
50
|
+
resultado.erro? # => false
|
51
|
+
resultado.mensagem_erro # => ""
|
44
52
|
|
45
53
|
|
46
54
|
== Log
|
@@ -85,40 +93,50 @@ Para desabilitar o log, mudar o nível do log ou configurar um outro mecanismo d
|
|
85
93
|
|
86
94
|
== Informações adicionais
|
87
95
|
|
88
|
-
=== Maneiras de configurar atributos no construtor de PayPal::FreteFacil::Frete
|
96
|
+
=== Maneiras de configurar atributos no construtor de PayPal::FreteFacil::Shipping (o mesmo vale para a classe PayPal::FreteFacil::Frete)
|
89
97
|
|
90
98
|
==== Com um hash
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
99
|
+
shipping = PayPal::FreteFacil::Shipping.new :from_zip => "04094-050",
|
100
|
+
:to_zip => "90619-900",
|
101
|
+
:width => 15,
|
102
|
+
:height => 2,
|
103
|
+
:length => 30,
|
104
|
+
:weight => 0.3
|
97
105
|
|
98
106
|
==== Com um bloco
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
107
|
+
shipping = PayPal::FreteFacil::Shipping.new do |s|
|
108
|
+
s.from_zip = "04094-050"
|
109
|
+
s.to_zip = "90619-900"
|
110
|
+
s.width = 15
|
111
|
+
s.height = 2
|
112
|
+
s.length = 30
|
113
|
+
s.weight = 0.3
|
106
114
|
end
|
107
115
|
|
116
|
+
=== Atributos de PayPal::FreteFacil::Shipping
|
117
|
+
|
118
|
+
==== String
|
119
|
+
from_zip, to_zip
|
120
|
+
==== Fixnum
|
121
|
+
width, height, length
|
122
|
+
==== Float
|
123
|
+
weight
|
124
|
+
|
125
|
+
=== Observações da classe PayPal::FreteFacil::Shipping
|
126
|
+
* Os atributos *width*, *height* e *length* também aceitam valores com casas decimais (<em>float</em>), mas para fazer o cálculo do frete será feito um <em>round</em> de seus valores.
|
127
|
+
|
108
128
|
|
109
129
|
=== Atributos de PayPal::FreteFacil::Frete
|
110
130
|
|
111
131
|
==== String
|
112
132
|
cep_origem, cep_destino
|
113
133
|
==== Fixnum
|
114
|
-
largura, altura,
|
134
|
+
largura, altura, comprimento
|
115
135
|
==== Float
|
116
136
|
peso
|
117
137
|
|
118
|
-
|
119
|
-
|
120
|
-
* Os atributos *profundidade* e *comprimento* são a mesma coisa, configurando um irá configurar também o outro.
|
121
|
-
* Os atributos *largura*, *altura* e *profundidade* também aceitam valores com casas decimais (<em>float</em>), mas para fazer o cálculo será feito um <em>round</em> de seus valores.
|
138
|
+
=== Observações da classe PayPal::FreteFacil::Frete
|
139
|
+
* Os atributos *largura*, *altura* e *comprimento* também aceitam valores com casas decimais (<em>float</em>), mas para fazer o cálculo do frete será feito um <em>round</em> de seus valores.
|
122
140
|
|
123
141
|
|
124
142
|
== Copyright
|
data/lib/paypal-frete-facil.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'paypal/fretefacil'
|
4
4
|
require 'paypal/fretefacil/frete'
|
5
|
+
require 'paypal/fretefacil/frete_resultado'
|
5
6
|
require 'paypal/fretefacil/parser'
|
6
|
-
require 'paypal/fretefacil/
|
7
|
+
require 'paypal/fretefacil/shipping'
|
8
|
+
require 'paypal/fretefacil/shipping_result'
|
7
9
|
require 'paypal/fretefacil/web_service'
|
@@ -1,44 +1,43 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
require 'forwardable'
|
3
|
+
|
2
4
|
module PayPal
|
3
5
|
module FreteFacil
|
4
6
|
class Frete
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
# Attribute delegates
|
10
|
+
{ :from_zip => :cep_origem,
|
11
|
+
:to_zip => :cep_destino,
|
12
|
+
:width => :largura,
|
13
|
+
:height => :altura,
|
14
|
+
:length => :comprimento,
|
15
|
+
:weight => :peso
|
16
|
+
}.each do |original, delegate|
|
17
|
+
def_delegator :@shipping, original, delegate
|
18
|
+
def_delegator :@shipping, "#{original}=".to_sym, "#{delegate}=".to_sym
|
19
|
+
end
|
11
20
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
:profundidade => 0,
|
16
|
-
:peso => 0.0
|
17
|
-
}
|
21
|
+
# Method delegates
|
22
|
+
def_delegator :@shipping, :calculate, :calcular
|
23
|
+
def_delegators :@shipping, :web_service, :parser
|
18
24
|
|
19
25
|
def initialize(options = {})
|
20
|
-
|
26
|
+
create_shipping
|
27
|
+
|
28
|
+
options.each do |attr, value|
|
21
29
|
self.send("#{attr}=", value)
|
22
30
|
end
|
23
31
|
|
24
32
|
yield self if block_given?
|
25
33
|
end
|
26
34
|
|
27
|
-
|
28
|
-
PayPal::FreteFacil::WebService.new(self)
|
29
|
-
end
|
30
|
-
|
31
|
-
def parser
|
32
|
-
@parser ||= PayPal::FreteFacil::Parser.new
|
33
|
-
end
|
35
|
+
private
|
34
36
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
PayPal::FreteFacil::Resultado.new(value)
|
37
|
+
def create_shipping
|
38
|
+
@shipping = PayPal::FreteFacil::Shipping.new
|
39
|
+
@shipping.result_class = PayPal::FreteFacil::FreteResultado
|
39
40
|
end
|
40
|
-
|
41
|
-
alias calculate calcular
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module PayPal
|
5
|
+
module FreteFacil
|
6
|
+
class FreteResultado
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
{ :value => :valor,
|
10
|
+
:success? => :sucesso?,
|
11
|
+
:error? => :erro?,
|
12
|
+
:error_message => :mensagem_erro
|
13
|
+
}.each do |original, delegate|
|
14
|
+
def_delegator :@shipping_result, original, delegate
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(value)
|
18
|
+
@shipping_result = PayPal::FreteFacil::ShippingResult.new(value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module PayPal
|
3
|
+
module FreteFacil
|
4
|
+
class Shipping
|
5
|
+
attr_accessor :from_zip, :to_zip
|
6
|
+
attr_accessor :width, :height, :length, :weight
|
7
|
+
attr_writer :result_class
|
8
|
+
|
9
|
+
DEFAULT_OPTIONS = {
|
10
|
+
:width => 0,
|
11
|
+
:height => 0,
|
12
|
+
:length => 0,
|
13
|
+
:weight => 0.0
|
14
|
+
}
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
DEFAULT_OPTIONS.merge(options).each do |attr, value|
|
18
|
+
self.send("#{attr}=", value)
|
19
|
+
end
|
20
|
+
|
21
|
+
yield self if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def calculate
|
25
|
+
response = web_service.request!
|
26
|
+
value = parser.parse(response)
|
27
|
+
result_class.new(value)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def web_service
|
33
|
+
PayPal::FreteFacil::WebService.new(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def parser
|
37
|
+
@parser ||= PayPal::FreteFacil::Parser.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def result_class
|
41
|
+
@result_class ||= PayPal::FreteFacil::ShippingResult
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module PayPal
|
3
|
+
module FreteFacil
|
4
|
+
class ShippingResult
|
5
|
+
attr_reader :value
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
if value > 0
|
9
|
+
# Ruby 1.8.7 compatibility.
|
10
|
+
@value = Float.instance_method(:round).arity.zero? ? value : value.round(2)
|
11
|
+
else
|
12
|
+
@value = 0
|
13
|
+
@error = true
|
14
|
+
@error_message = "Não foi possível calcular o frete."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def success?
|
19
|
+
!error?
|
20
|
+
end
|
21
|
+
|
22
|
+
def error?
|
23
|
+
@error ||= false
|
24
|
+
end
|
25
|
+
|
26
|
+
def error_message
|
27
|
+
@error_message ||= ""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -7,9 +7,9 @@ module PayPal
|
|
7
7
|
class WebService
|
8
8
|
URL = "https://ff.paypal-brasil.com.br/FretesPayPalWS/WSFretesPayPal"
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(shipping)
|
11
11
|
@uri = URI.parse(URL)
|
12
|
-
@
|
12
|
+
@shipping = shipping
|
13
13
|
end
|
14
14
|
|
15
15
|
def request!
|
@@ -42,17 +42,17 @@ module PayPal
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def request_body
|
45
|
-
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:
|
45
|
+
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:shipping=\"https://ff.paypal-brasil.com.br/FretesPayPalWS\">" +
|
46
46
|
"<soapenv:Header />" +
|
47
47
|
"<soapenv:Body>" +
|
48
|
-
"<
|
49
|
-
"<cepOrigem>#{@
|
50
|
-
"<cepDestino>#{@
|
51
|
-
"<largura>#{@
|
52
|
-
"<altura>#{@
|
53
|
-
"<profundidade>#{@
|
54
|
-
"<peso>#{@
|
55
|
-
"</
|
48
|
+
"<shipping:getPreco>" +
|
49
|
+
"<cepOrigem>#{@shipping.from_zip}</cepOrigem>" +
|
50
|
+
"<cepDestino>#{@shipping.to_zip}</cepDestino>" +
|
51
|
+
"<largura>#{@shipping.width.round}</largura>" +
|
52
|
+
"<altura>#{@shipping.height.round}</altura>" +
|
53
|
+
"<profundidade>#{@shipping.length.round}</profundidade>" +
|
54
|
+
"<peso>#{@shipping.weight}</peso>" +
|
55
|
+
"</shipping:getPreco>" +
|
56
56
|
"</soapenv:Body>" +
|
57
57
|
"</soapenv:Envelope>"
|
58
58
|
end
|
data/paypal-frete-facil.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "paypal-frete-facil"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-27"
|
13
13
|
s.description = "Calculo de frete atraves do PayPal Frete Facil (http://www.paypal-brasil.com.br/fretefacil)."
|
14
14
|
s.email = "prodis@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,14 +25,18 @@ Gem::Specification.new do |s|
|
|
25
25
|
"lib/paypal-frete-facil.rb",
|
26
26
|
"lib/paypal/fretefacil.rb",
|
27
27
|
"lib/paypal/fretefacil/frete.rb",
|
28
|
+
"lib/paypal/fretefacil/frete_resultado.rb",
|
28
29
|
"lib/paypal/fretefacil/parser.rb",
|
29
|
-
"lib/paypal/fretefacil/
|
30
|
+
"lib/paypal/fretefacil/shipping.rb",
|
31
|
+
"lib/paypal/fretefacil/shipping_result.rb",
|
30
32
|
"lib/paypal/fretefacil/version.rb",
|
31
33
|
"lib/paypal/fretefacil/web_service.rb",
|
32
34
|
"paypal-frete-facil.gemspec",
|
35
|
+
"spec/paypal/fretefacil/frete_resultado_spec.rb",
|
33
36
|
"spec/paypal/fretefacil/frete_spec.rb",
|
34
37
|
"spec/paypal/fretefacil/parser_spec.rb",
|
35
|
-
"spec/paypal/fretefacil/
|
38
|
+
"spec/paypal/fretefacil/shipping_result_spec.rb",
|
39
|
+
"spec/paypal/fretefacil/shipping_spec.rb",
|
36
40
|
"spec/spec_helper.rb",
|
37
41
|
"spec/support/fake_request.rb",
|
38
42
|
"spec/support/responses/success_response.xml"
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe PayPal::FreteFacil::
|
4
|
+
describe PayPal::FreteFacil::FreteResultado do
|
5
5
|
describe ".new" do
|
6
6
|
context "when shipping value is valid" do
|
7
|
-
let(:resultado) { PayPal::FreteFacil::
|
7
|
+
let(:resultado) { PayPal::FreteFacil::FreteResultado.new(13.87) }
|
8
8
|
|
9
9
|
it "shipping value is the valid value" do
|
10
10
|
resultado.valor.should == 13.87
|
@@ -19,12 +19,12 @@ describe PayPal::FreteFacil::Resultado do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "there is not error message" do
|
22
|
-
resultado.
|
22
|
+
resultado.mensagem_erro.should be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
context "and has more than two decimal places" do
|
26
26
|
it "rounds shipping value to two decimal places" do
|
27
|
-
resultado = PayPal::FreteFacil::
|
27
|
+
resultado = PayPal::FreteFacil::FreteResultado.new(8.2261234567)
|
28
28
|
resultado.valor.should == 8.23
|
29
29
|
end
|
30
30
|
end
|
@@ -33,7 +33,7 @@ describe PayPal::FreteFacil::Resultado do
|
|
33
33
|
context "when value is not valid" do
|
34
34
|
[0, -12, -15.8].each do |value|
|
35
35
|
context "as #{value}" do
|
36
|
-
let(:resultado) { PayPal::FreteFacil::
|
36
|
+
let(:resultado) { PayPal::FreteFacil::FreteResultado.new(value) }
|
37
37
|
|
38
38
|
it "valor is zero" do
|
39
39
|
resultado.valor.should be_zero
|
@@ -48,7 +48,7 @@ describe PayPal::FreteFacil::Resultado do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "there is error message" do
|
51
|
-
resultado.
|
51
|
+
resultado.mensagem_erro.should == "Não foi possível calcular o frete."
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -8,7 +8,6 @@ describe PayPal::FreteFacil::Frete do
|
|
8
8
|
|
9
9
|
{ :largura => 0,
|
10
10
|
:altura => 0,
|
11
|
-
:profundidade => 0,
|
12
11
|
:comprimento => 0,
|
13
12
|
:peso => 0.0
|
14
13
|
}.each do |attr, value|
|
@@ -22,7 +21,6 @@ describe PayPal::FreteFacil::Frete do
|
|
22
21
|
:cep_destino => "021222-222",
|
23
22
|
:largura => 15,
|
24
23
|
:altura => 2,
|
25
|
-
:profundidade => 30,
|
26
24
|
:comprimento => 30,
|
27
25
|
:peso => 0.321
|
28
26
|
}.each do |attr, value|
|
@@ -42,19 +40,17 @@ describe PayPal::FreteFacil::Frete do
|
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
frete.send(method_name).valor.should == 10.23
|
57
|
-
end
|
43
|
+
describe "#calcular" do
|
44
|
+
around do |example|
|
45
|
+
PayPal::FreteFacil.configure { |config| config.log_enabled = false }
|
46
|
+
example.run
|
47
|
+
PayPal::FreteFacil.configure { |config| config.log_enabled = true }
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns shipping price result" do
|
51
|
+
fake_request(10.23)
|
52
|
+
frete = PayPal::FreteFacil::Frete.new
|
53
|
+
frete.calcular.valor.should == 10.23
|
58
54
|
end
|
59
55
|
end
|
60
56
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PayPal::FreteFacil::ShippingResult do
|
5
|
+
describe ".new" do
|
6
|
+
context "when shipping value is valid" do
|
7
|
+
let(:result) { PayPal::FreteFacil::ShippingResult.new(13.87) }
|
8
|
+
|
9
|
+
it "shipping value is the valid value" do
|
10
|
+
result.value.should == 13.87
|
11
|
+
end
|
12
|
+
|
13
|
+
it "result is successful" do
|
14
|
+
result.success?.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "there is not error" do
|
18
|
+
result.error?.should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "there is not error message" do
|
22
|
+
result.error_message.should be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
context "and has more than two decimal places" do
|
26
|
+
it "rounds shipping value to two decimal places" do
|
27
|
+
result = PayPal::FreteFacil::ShippingResult.new(8.2261234567)
|
28
|
+
result.value.should == 8.23
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when value is not valid" do
|
34
|
+
[0, -12, -15.8].each do |value|
|
35
|
+
context "as #{value}" do
|
36
|
+
let(:result) { PayPal::FreteFacil::ShippingResult.new(value) }
|
37
|
+
|
38
|
+
it "value is zero" do
|
39
|
+
result.value.should be_zero
|
40
|
+
end
|
41
|
+
|
42
|
+
it "result is not successful" do
|
43
|
+
result.success?.should be_false
|
44
|
+
end
|
45
|
+
|
46
|
+
it "there is error" do
|
47
|
+
result.error?.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "there is error message" do
|
51
|
+
result.error_message.should == "Não foi possível calcular o frete."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PayPal::FreteFacil::Shipping do
|
5
|
+
describe ".new" do
|
6
|
+
context "create with default value of" do
|
7
|
+
before(:each) { @shipping = PayPal::FreteFacil::Shipping.new }
|
8
|
+
|
9
|
+
{ :width => 0,
|
10
|
+
:height => 0,
|
11
|
+
:length => 0,
|
12
|
+
:weight => 0.0
|
13
|
+
}.each do |attr, value|
|
14
|
+
it attr do
|
15
|
+
@shipping.send(attr).should == value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
{ :from_zip => "01000-000",
|
21
|
+
:to_zip => "021222-222",
|
22
|
+
:width => 15,
|
23
|
+
:height => 2,
|
24
|
+
:length => 30,
|
25
|
+
:weight => 0.321
|
26
|
+
}.each do |attr, value|
|
27
|
+
context "when #{attr} is supplied" do
|
28
|
+
it "sets #{attr}" do
|
29
|
+
@shipping = PayPal::FreteFacil::Shipping.new(attr => value)
|
30
|
+
@shipping.send(attr).should == value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when #{attr} is supplied in a block" do
|
35
|
+
it "sets #{attr}" do
|
36
|
+
@shipping = PayPal::FreteFacil::Shipping.new { |f| f.send("#{attr}=", value) }
|
37
|
+
@shipping.send(attr).should == value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#calculate" do
|
44
|
+
around do |example|
|
45
|
+
PayPal::FreteFacil.configure { |config| config.log_enabled = false }
|
46
|
+
example.run
|
47
|
+
PayPal::FreteFacil.configure { |config| config.log_enabled = true }
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns shipping price result" do
|
51
|
+
fake_request(10.23)
|
52
|
+
shipping = PayPal::FreteFacil::Shipping.new
|
53
|
+
shipping.calculate.value.should == 10.23
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal-frete-facil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: log-me
|
16
|
-
requirement: &
|
16
|
+
requirement: &11298260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.0.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11298260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &11297530 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.5'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11297530
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fakeweb
|
38
|
-
requirement: &
|
38
|
+
requirement: &11312990 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *11312990
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &11312120 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.8'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *11312120
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &11311190 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '2.10'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *11311190
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ruby-debug
|
71
|
-
requirement: &
|
71
|
+
requirement: &11309920 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *11309920
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: ruby-debug19
|
82
|
-
requirement: &
|
82
|
+
requirement: &11308600 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *11308600
|
91
91
|
description: Calculo de frete atraves do PayPal Frete Facil (http://www.paypal-brasil.com.br/fretefacil).
|
92
92
|
email: prodis@gmail.com
|
93
93
|
executables: []
|
@@ -104,14 +104,18 @@ files:
|
|
104
104
|
- lib/paypal-frete-facil.rb
|
105
105
|
- lib/paypal/fretefacil.rb
|
106
106
|
- lib/paypal/fretefacil/frete.rb
|
107
|
+
- lib/paypal/fretefacil/frete_resultado.rb
|
107
108
|
- lib/paypal/fretefacil/parser.rb
|
108
|
-
- lib/paypal/fretefacil/
|
109
|
+
- lib/paypal/fretefacil/shipping.rb
|
110
|
+
- lib/paypal/fretefacil/shipping_result.rb
|
109
111
|
- lib/paypal/fretefacil/version.rb
|
110
112
|
- lib/paypal/fretefacil/web_service.rb
|
111
113
|
- paypal-frete-facil.gemspec
|
114
|
+
- spec/paypal/fretefacil/frete_resultado_spec.rb
|
112
115
|
- spec/paypal/fretefacil/frete_spec.rb
|
113
116
|
- spec/paypal/fretefacil/parser_spec.rb
|
114
|
-
- spec/paypal/fretefacil/
|
117
|
+
- spec/paypal/fretefacil/shipping_result_spec.rb
|
118
|
+
- spec/paypal/fretefacil/shipping_spec.rb
|
115
119
|
- spec/spec_helper.rb
|
116
120
|
- spec/support/fake_request.rb
|
117
121
|
- spec/support/responses/success_response.xml
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module PayPal
|
3
|
-
module FreteFacil
|
4
|
-
class Resultado
|
5
|
-
attr_reader :valor
|
6
|
-
alias value valor
|
7
|
-
|
8
|
-
def initialize(valor)
|
9
|
-
if valor > 0
|
10
|
-
# Ruby 1.8.7 compatibility.
|
11
|
-
@valor = Float.instance_method(:round).arity.zero? ? valor : valor.round(2)
|
12
|
-
else
|
13
|
-
@valor = 0
|
14
|
-
@erro = true
|
15
|
-
@msg_erro = "Não foi possível calcular o frete."
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def sucesso?
|
20
|
-
!erro?
|
21
|
-
end
|
22
|
-
alias success? sucesso?
|
23
|
-
|
24
|
-
def erro?
|
25
|
-
@erro ||= false
|
26
|
-
end
|
27
|
-
alias error? erro?
|
28
|
-
|
29
|
-
def msg_erro
|
30
|
-
@msg_erro ||= ""
|
31
|
-
end
|
32
|
-
alias error_msg msg_erro
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|