mooamba 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -1
- data/Rakefile +2 -1
- data/lib/mooamba/exceptions.rb +2 -1
- data/lib/mooamba/sedex.rb +9 -3
- data/mooamba.gemspec +7 -3
- data/spec/data/{invalid_weight.xml → excessive_weight.xml} +0 -0
- data/spec/data/invalid.xml +2 -2
- data/spec/data/unavailable_pricing_service_for_area.xml +15 -0
- data/spec/mooamba/sedex_spec.rb +29 -3
- metadata +23 -7
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -7,11 +7,12 @@ begin
|
|
7
7
|
require 'jeweler'
|
8
8
|
Jeweler::Tasks.new do |gemspec|
|
9
9
|
gemspec.name = "mooamba"
|
10
|
-
gemspec.version = "0.0.
|
10
|
+
gemspec.version = "0.0.2"
|
11
11
|
gemspec.summary = ""
|
12
12
|
gemspec.description = ""
|
13
13
|
gemspec.homepage = "http://github.com/gonow/mooamba"
|
14
14
|
gemspec.authors = ["GoNow"]
|
15
|
+
gemspec.add_dependency("sax-machine", ">= 0.0.15")
|
15
16
|
end
|
16
17
|
rescue LoadError
|
17
18
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
data/lib/mooamba/exceptions.rb
CHANGED
@@ -2,7 +2,7 @@ module Mooamba
|
|
2
2
|
module Correios
|
3
3
|
class InvalidOriginZipCode < StandardError; end
|
4
4
|
class InvalidDestinyZipCode < StandardError; end
|
5
|
-
class
|
5
|
+
class ExcessiveWeight < StandardError; end
|
6
6
|
class UnavailableServiceForArea < StandardError; end
|
7
7
|
class UnavailableService < StandardError; end
|
8
8
|
class UnknownError < StandardError; end
|
@@ -10,5 +10,6 @@ module Mooamba
|
|
10
10
|
|
11
11
|
class InvalidDestinationZipCode < StandardError; end
|
12
12
|
class InvalidOriginZipCode < StandardError; end
|
13
|
+
class InvalidWeight < StandardError; end
|
13
14
|
class UnavailableAPI < StandardError; end
|
14
15
|
end
|
data/lib/mooamba/sedex.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Mooamba
|
1
|
+
module Mooamba
|
2
2
|
module Correios
|
3
3
|
API_URL = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?"
|
4
4
|
end
|
@@ -20,6 +20,7 @@ module Mooamba
|
|
20
20
|
def self.calculate(options={})
|
21
21
|
raise InvalidOriginZipCode if invalid_cep?(options[:from])
|
22
22
|
raise InvalidDestinationZipCode if invalid_cep?(options[:to])
|
23
|
+
raise InvalidWeight if invalid_weight?(options[:weight])
|
23
24
|
response = response_for options
|
24
25
|
error?(response) ? (raise exception(response)) : response
|
25
26
|
end
|
@@ -42,13 +43,14 @@ module Mooamba
|
|
42
43
|
|
43
44
|
def self.exception(response)
|
44
45
|
if response.service.nil?
|
45
|
-
Mooamba::UnavailableAPI
|
46
|
+
Mooamba::UnavailableAPI
|
46
47
|
else
|
47
48
|
case response.error
|
48
49
|
when "-2"; Mooamba::Correios::InvalidOriginZipCode
|
49
50
|
when "-3"; Mooamba::Correios::InvalidDestinyZipCode
|
50
|
-
when "-4"; Mooamba::Correios::
|
51
|
+
when "-4"; Mooamba::Correios::ExcessiveWeight
|
51
52
|
when "-6"; Mooamba::Correios::UnavailableServiceForArea
|
53
|
+
when "-10"; Mooamba::Correios::UnavailableServiceForArea
|
52
54
|
when "7"; Mooamba::Correios::UnavailableService
|
53
55
|
else; Mooamba::Correios::UnknownError
|
54
56
|
end
|
@@ -62,5 +64,9 @@ module Mooamba
|
|
62
64
|
def self.invalid_cep?(cep)
|
63
65
|
cep.blank? or cep.invalid?
|
64
66
|
end
|
67
|
+
|
68
|
+
def self.invalid_weight?(weight)
|
69
|
+
weight.blank? or weight.to_i <= 0
|
70
|
+
end
|
65
71
|
end
|
66
72
|
end
|
data/mooamba.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mooamba}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["GoNow"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-24}
|
13
13
|
s.description = %q{}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
@@ -26,11 +26,12 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/mooamba/exceptions.rb",
|
27
27
|
"lib/mooamba/sedex.rb",
|
28
28
|
"mooamba.gemspec",
|
29
|
+
"spec/data/excessive_weight.xml",
|
29
30
|
"spec/data/invalid.xml",
|
30
31
|
"spec/data/invalid_destiny.xml",
|
31
32
|
"spec/data/invalid_origin.xml",
|
32
|
-
"spec/data/invalid_weight.xml",
|
33
33
|
"spec/data/malformed.xml",
|
34
|
+
"spec/data/unavailable_pricing_service_for_area.xml",
|
34
35
|
"spec/data/unavailable_service.xml",
|
35
36
|
"spec/data/unavailable_service_for_area.xml",
|
36
37
|
"spec/data/valid.xml",
|
@@ -53,9 +54,12 @@ Gem::Specification.new do |s|
|
|
53
54
|
s.specification_version = 3
|
54
55
|
|
55
56
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<sax-machine>, [">= 0.0.15"])
|
56
58
|
else
|
59
|
+
s.add_dependency(%q<sax-machine>, [">= 0.0.15"])
|
57
60
|
end
|
58
61
|
else
|
62
|
+
s.add_dependency(%q<sax-machine>, [">= 0.0.15"])
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
File without changes
|
data/spec/data/invalid.xml
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
<ValorValorDeclarado>0,00</ValorValorDeclarado>
|
10
10
|
<EntregaDomiciliar></EntregaDomiciliar>
|
11
11
|
<EntregaSabado></EntregaSabado>
|
12
|
-
<Erro
|
13
|
-
<MsgErro>
|
12
|
+
<Erro>99</Erro>
|
13
|
+
<MsgErro>Outros erros diversos do .Net.</MsgErro>
|
14
14
|
</cServico>
|
15
15
|
</Servicos>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
2
|
+
<Servicos>
|
3
|
+
<cServico>
|
4
|
+
<Codigo>40010</Codigo>
|
5
|
+
<Valor>0,00</Valor>
|
6
|
+
<PrazoEntrega>0</PrazoEntrega>
|
7
|
+
<ValorMaoPropria>0,00</ValorMaoPropria>
|
8
|
+
<ValorAvisoRecebimento>0,00</ValorAvisoRecebimento>
|
9
|
+
<ValorValorDeclarado>0,00</ValorValorDeclarado>
|
10
|
+
<EntregaDomiciliar></EntregaDomiciliar>
|
11
|
+
<EntregaSabado></EntregaSabado>
|
12
|
+
<Erro>-10</Erro>
|
13
|
+
<MsgErro>Precificação indisponível para o trecho informado.</MsgErro>
|
14
|
+
</cServico>
|
15
|
+
</Servicos>
|
data/spec/mooamba/sedex_spec.rb
CHANGED
@@ -26,6 +26,10 @@ describe Mooamba::Sedex do
|
|
26
26
|
lambda { Mooamba::Sedex.calculate(@default_parameters.except(:to)) }.should raise_error(Mooamba::InvalidDestinationZipCode)
|
27
27
|
end
|
28
28
|
|
29
|
+
it "should raise Mooamba::InvalidWeight when there's no weight" do
|
30
|
+
lambda { Mooamba::Sedex.calculate(@default_parameters.except(:weight)) }.should raise_error(Mooamba::InvalidWeight)
|
31
|
+
end
|
32
|
+
|
29
33
|
it "should raise Mooamba::InvalidOriginZipCode when the origin zip code is blank" do
|
30
34
|
lambda { Mooamba::Sedex.calculate(@default_parameters.merge(:from => "")) }.should raise_error(Mooamba::InvalidOriginZipCode)
|
31
35
|
end
|
@@ -34,6 +38,10 @@ describe Mooamba::Sedex do
|
|
34
38
|
lambda { Mooamba::Sedex.calculate(@default_parameters.merge(:to => "")) }.should raise_error(Mooamba::InvalidDestinationZipCode)
|
35
39
|
end
|
36
40
|
|
41
|
+
it "should raise Mooamba::InvalidWeight when the weight is blank" do
|
42
|
+
lambda { Mooamba::Sedex.calculate(@default_parameters.merge(:weight => "")) }.should raise_error(Mooamba::InvalidWeight)
|
43
|
+
end
|
44
|
+
|
37
45
|
it "should raise Mooamba::InvalidOriginZipCode when the origin zip code is invalid" do
|
38
46
|
lambda { Mooamba::Sedex.calculate(@default_parameters.merge(:from => INVALID_ZIP_CODES.last)) }.should raise_error(Mooamba::InvalidOriginZipCode)
|
39
47
|
end
|
@@ -42,6 +50,14 @@ describe Mooamba::Sedex do
|
|
42
50
|
lambda { Mooamba::Sedex.calculate(@default_parameters.merge(:to => INVALID_ZIP_CODES.first)) }.should raise_error(Mooamba::InvalidDestinationZipCode)
|
43
51
|
end
|
44
52
|
|
53
|
+
it "should raise Mooamba::InvalidWeight when the weight is 0" do
|
54
|
+
lambda { Mooamba::Sedex.calculate(@default_parameters.merge(:weight => 0)) }.should raise_error(Mooamba::InvalidWeight)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should raise Mooamba::InvalidWeight when the weight is negative" do
|
58
|
+
lambda { Mooamba::Sedex.calculate(@default_parameters.merge(:weight => -4)) }.should raise_error(Mooamba::InvalidWeight)
|
59
|
+
end
|
60
|
+
|
45
61
|
it "should raise Mooamba::UnavailableAPI when api returns unexpected content" do
|
46
62
|
map_parameters_to_file(@default_parameters, "malformed")
|
47
63
|
lambda { Mooamba::Sedex.calculate(@default_parameters) }.should raise_error(Mooamba::UnavailableAPI)
|
@@ -62,9 +78,19 @@ describe Mooamba::Sedex do
|
|
62
78
|
lambda { Mooamba::Sedex.calculate(@default_parameters) }.should raise_error(Mooamba::Correios::InvalidDestinyZipCode)
|
63
79
|
end
|
64
80
|
|
65
|
-
it "should raise Mooamba::Correios::
|
66
|
-
map_parameters_to_file(@default_parameters, "
|
67
|
-
lambda { Mooamba::Sedex.calculate(@default_parameters) }.should raise_error(Mooamba::Correios::
|
81
|
+
it "should raise Mooamba::Correios::ExcessiveWeight when the weight if excessive" do
|
82
|
+
map_parameters_to_file(@default_parameters, "excessive_weight")
|
83
|
+
lambda { Mooamba::Sedex.calculate(@default_parameters) }.should raise_error(Mooamba::Correios::ExcessiveWeight)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should raise Mooamba::Correios::UnavailableServiceForArea when the service is unavailable for the current area" do
|
87
|
+
map_parameters_to_file(@default_parameters, "unavailable_service_for_area")
|
88
|
+
lambda { Mooamba::Sedex.calculate(@default_parameters) }.should raise_error(Mooamba::Correios::UnavailableServiceForArea)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should raise Mooamba::Correios::UnavailableServiceForArea when the pricing service is unavailable for the current area" do
|
92
|
+
map_parameters_to_file(@default_parameters, "unavailable_pricing_service_for_area")
|
93
|
+
lambda { Mooamba::Sedex.calculate(@default_parameters) }.should raise_error(Mooamba::Correios::UnavailableServiceForArea)
|
68
94
|
end
|
69
95
|
|
70
96
|
it "should raise Mooamba::Correios::UnavailableServiceForArea when the service is unavailable for the current area" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mooamba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- GoNow
|
@@ -15,10 +15,25 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-24 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: sax-machine
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
- 15
|
34
|
+
version: 0.0.15
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
22
37
|
description: ""
|
23
38
|
email:
|
24
39
|
executables: []
|
@@ -39,11 +54,12 @@ files:
|
|
39
54
|
- lib/mooamba/exceptions.rb
|
40
55
|
- lib/mooamba/sedex.rb
|
41
56
|
- mooamba.gemspec
|
57
|
+
- spec/data/excessive_weight.xml
|
42
58
|
- spec/data/invalid.xml
|
43
59
|
- spec/data/invalid_destiny.xml
|
44
60
|
- spec/data/invalid_origin.xml
|
45
|
-
- spec/data/invalid_weight.xml
|
46
61
|
- spec/data/malformed.xml
|
62
|
+
- spec/data/unavailable_pricing_service_for_area.xml
|
47
63
|
- spec/data/unavailable_service.xml
|
48
64
|
- spec/data/unavailable_service_for_area.xml
|
49
65
|
- spec/data/valid.xml
|