paypal-frete-facil 1.0.0 → 1.1.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 +27 -4
- data/lib/paypal-frete-facil.rb +1 -0
- data/lib/paypal/fretefacil/frete.rb +5 -1
- data/lib/paypal/fretefacil/parser.rb +1 -2
- data/lib/paypal/fretefacil/resultado.rb +35 -0
- data/lib/paypal/fretefacil/version.rb +1 -1
- data/lib/paypal/fretefacil/web_service.rb +3 -3
- data/paypal-frete-facil.gemspec +4 -2
- data/spec/paypal/fretefacil/frete_spec.rb +4 -2
- data/spec/paypal/fretefacil/parser_spec.rb +2 -9
- data/spec/paypal/fretefacil/resultado_spec.rb +57 -0
- metadata +18 -16
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ Cálculo de frete através do PayPal Frete Fácil (http://www.paypal-brasil.com.
|
|
5
5
|
== Instalando
|
6
6
|
|
7
7
|
=== Gemfile
|
8
|
-
gem 'paypal-frete-facil'
|
8
|
+
gem 'paypal-frete-facil'
|
9
9
|
|
10
10
|
=== Instalação direta
|
11
11
|
$ gem install paypal-frete-facil
|
@@ -22,8 +22,25 @@ Cálculo de frete através do PayPal Frete Fácil (http://www.paypal-brasil.com.
|
|
22
22
|
:profundidade => 30,
|
23
23
|
:peso => 0.3
|
24
24
|
|
25
|
-
frete.calcular
|
26
|
-
|
25
|
+
resultado = frete.calcular
|
26
|
+
resultado.valor # => 14.77
|
27
|
+
|
28
|
+
Verificação de sucesso e erro:
|
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 # => ""
|
27
44
|
|
28
45
|
|
29
46
|
== Log
|
@@ -94,10 +111,16 @@ Para desabilitar o log, mudar o nível do log ou configurar um outro mecanismo d
|
|
94
111
|
==== String
|
95
112
|
cep_origem, cep_destino
|
96
113
|
==== Fixnum
|
97
|
-
largura, altura, profundidade
|
114
|
+
largura, altura, profundidade (comprimento)
|
98
115
|
==== Float
|
99
116
|
peso
|
100
117
|
|
118
|
+
|
119
|
+
=== Outros detalhes da classe PayPal::FreteFacil::Frete
|
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.
|
122
|
+
|
123
|
+
|
101
124
|
== Copyright
|
102
125
|
|
103
126
|
(The MIT License)
|
data/lib/paypal-frete-facil.rb
CHANGED
@@ -6,6 +6,9 @@ module PayPal
|
|
6
6
|
attr_accessor :largura, :altura, :profundidade
|
7
7
|
attr_accessor :peso
|
8
8
|
|
9
|
+
alias comprimento profundidade
|
10
|
+
alias comprimento= profundidade=
|
11
|
+
|
9
12
|
DEFAULT_OPTIONS = {
|
10
13
|
:largura => 0,
|
11
14
|
:altura => 0,
|
@@ -31,7 +34,8 @@ module PayPal
|
|
31
34
|
|
32
35
|
def calcular
|
33
36
|
response = web_service.request!
|
34
|
-
parser.parse(response)
|
37
|
+
value = parser.parse(response)
|
38
|
+
PayPal::FreteFacil::Resultado.new(value)
|
35
39
|
end
|
36
40
|
|
37
41
|
alias calculate calcular
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -48,9 +48,9 @@ module PayPal
|
|
48
48
|
"<frete:getPreco>" +
|
49
49
|
"<cepOrigem>#{@frete.cep_origem}</cepOrigem>" +
|
50
50
|
"<cepDestino>#{@frete.cep_destino}</cepDestino>" +
|
51
|
-
"<largura>#{@frete.largura}</largura>" +
|
52
|
-
"<altura>#{@frete.altura}</altura>" +
|
53
|
-
"<profundidade>#{@frete.profundidade}</profundidade>" +
|
51
|
+
"<largura>#{@frete.largura.round}</largura>" +
|
52
|
+
"<altura>#{@frete.altura.round}</altura>" +
|
53
|
+
"<profundidade>#{@frete.profundidade.round}</profundidade>" +
|
54
54
|
"<peso>#{@frete.peso}</peso>" +
|
55
55
|
"</frete:getPreco>" +
|
56
56
|
"</soapenv:Body>" +
|
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.1.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-10"
|
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 = [
|
@@ -26,11 +26,13 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/paypal/fretefacil.rb",
|
27
27
|
"lib/paypal/fretefacil/frete.rb",
|
28
28
|
"lib/paypal/fretefacil/parser.rb",
|
29
|
+
"lib/paypal/fretefacil/resultado.rb",
|
29
30
|
"lib/paypal/fretefacil/version.rb",
|
30
31
|
"lib/paypal/fretefacil/web_service.rb",
|
31
32
|
"paypal-frete-facil.gemspec",
|
32
33
|
"spec/paypal/fretefacil/frete_spec.rb",
|
33
34
|
"spec/paypal/fretefacil/parser_spec.rb",
|
35
|
+
"spec/paypal/fretefacil/resultado_spec.rb",
|
34
36
|
"spec/spec_helper.rb",
|
35
37
|
"spec/support/fake_request.rb",
|
36
38
|
"spec/support/responses/success_response.xml"
|
@@ -9,6 +9,7 @@ describe PayPal::FreteFacil::Frete do
|
|
9
9
|
{ :largura => 0,
|
10
10
|
:altura => 0,
|
11
11
|
:profundidade => 0,
|
12
|
+
:comprimento => 0,
|
12
13
|
:peso => 0.0
|
13
14
|
}.each do |attr, value|
|
14
15
|
it attr do
|
@@ -22,6 +23,7 @@ describe PayPal::FreteFacil::Frete do
|
|
22
23
|
:largura => 15,
|
23
24
|
:altura => 2,
|
24
25
|
:profundidade => 30,
|
26
|
+
:comprimento => 30,
|
25
27
|
:peso => 0.321
|
26
28
|
}.each do |attr, value|
|
27
29
|
context "when #{attr} is supplied" do
|
@@ -48,10 +50,10 @@ describe PayPal::FreteFacil::Frete do
|
|
48
50
|
PayPal::FreteFacil.configure { |config| config.log_enabled = true }
|
49
51
|
end
|
50
52
|
|
51
|
-
it "returns shipping price" do
|
53
|
+
it "returns shipping price result" do
|
52
54
|
fake_request(10.23)
|
53
55
|
frete = PayPal::FreteFacil::Frete.new
|
54
|
-
frete.send(method_name).should == 10.23
|
56
|
+
frete.send(method_name).valor.should == 10.23
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -7,15 +7,8 @@ describe PayPal::FreteFacil::Parser do
|
|
7
7
|
|
8
8
|
context "when XML is correct" do
|
9
9
|
it "returns shipping price" do
|
10
|
-
xml = response_body(8.
|
11
|
-
parser.parse(xml).should == 8.
|
12
|
-
end
|
13
|
-
|
14
|
-
context "and shipping price has more then two decimal places" do
|
15
|
-
it "returns shipping price rounded to two decimal places" do
|
16
|
-
xml = response_body(8.2261234567)
|
17
|
-
parser.parse(xml).should == 8.23
|
18
|
-
end
|
10
|
+
xml = response_body(8.2261234567)
|
11
|
+
parser.parse(xml).should == 8.2261234567
|
19
12
|
end
|
20
13
|
end
|
21
14
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PayPal::FreteFacil::Resultado do
|
5
|
+
describe ".new" do
|
6
|
+
context "when shipping value is valid" do
|
7
|
+
let(:resultado) { PayPal::FreteFacil::Resultado.new(13.87) }
|
8
|
+
|
9
|
+
it "shipping value is the valid value" do
|
10
|
+
resultado.valor.should == 13.87
|
11
|
+
end
|
12
|
+
|
13
|
+
it "result is successful" do
|
14
|
+
resultado.sucesso?.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "there is not error" do
|
18
|
+
resultado.erro?.should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "there is not error message" do
|
22
|
+
resultado.msg_erro.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
|
+
resultado = PayPal::FreteFacil::Resultado.new(8.2261234567)
|
28
|
+
resultado.valor.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(:resultado) { PayPal::FreteFacil::Resultado.new(value) }
|
37
|
+
|
38
|
+
it "valor is zero" do
|
39
|
+
resultado.valor.should be_zero
|
40
|
+
end
|
41
|
+
|
42
|
+
it "result is not successful" do
|
43
|
+
resultado.sucesso?.should be_false
|
44
|
+
end
|
45
|
+
|
46
|
+
it "there is error" do
|
47
|
+
resultado.erro?.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "there is error message" do
|
51
|
+
resultado.msg_erro.should == "Não foi possível calcular o frete."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
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.1.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-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: log-me
|
16
|
-
requirement: &
|
16
|
+
requirement: &11805370 !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: *11805370
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &11805130 !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: *11805130
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fakeweb
|
38
|
-
requirement: &
|
38
|
+
requirement: &11804890 !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: *11804890
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &11821020 !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: *11821020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &11820780 !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: *11820780
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ruby-debug
|
71
|
-
requirement: &
|
71
|
+
requirement: &11820540 !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: *11820540
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: ruby-debug19
|
82
|
-
requirement: &
|
82
|
+
requirement: &11820300 !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: *11820300
|
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: []
|
@@ -105,11 +105,13 @@ files:
|
|
105
105
|
- lib/paypal/fretefacil.rb
|
106
106
|
- lib/paypal/fretefacil/frete.rb
|
107
107
|
- lib/paypal/fretefacil/parser.rb
|
108
|
+
- lib/paypal/fretefacil/resultado.rb
|
108
109
|
- lib/paypal/fretefacil/version.rb
|
109
110
|
- lib/paypal/fretefacil/web_service.rb
|
110
111
|
- paypal-frete-facil.gemspec
|
111
112
|
- spec/paypal/fretefacil/frete_spec.rb
|
112
113
|
- spec/paypal/fretefacil/parser_spec.rb
|
114
|
+
- spec/paypal/fretefacil/resultado_spec.rb
|
113
115
|
- spec/spec_helper.rb
|
114
116
|
- spec/support/fake_request.rb
|
115
117
|
- spec/support/responses/success_response.xml
|