corraios 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/corraios.gemspec +1 -1
- data/lib/corraios/calculator.rb +19 -3
- data/lib/corraios/delivery.rb +9 -0
- data/lib/corraios/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6417ca32463b2238feac9aa24170c153021e633e
|
4
|
+
data.tar.gz: a4564955bfddf1646bbfc568b5f9c42bcd278577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98fe66a88f401bdc96b3ea91ac978574d7ddcb36a9522b72022576918be42468d066d84816f4f72c8b258bf5427632c9e5d896abdb2d30455afbc80e473eedf1
|
7
|
+
data.tar.gz: a10caa1bd73859737e580d93e2fc200b3c086ce2a12dfa033ce07c4be084ae37565f4d7d3547ddec240bb4e01599734d920b111bca55dc21672cb682f71fb1fa
|
data/README.md
CHANGED
@@ -128,8 +128,6 @@ end
|
|
128
128
|
## TODO
|
129
129
|
|
130
130
|
- Unificar requisições para diferentes serviços (Hoje a chamada `calculator.perform :pac, :sedex` realiza duas requisiçoes ao servidor do Correios. Pode ser feita em uma)
|
131
|
-
- Unificar respostas quando mais de uma requisição é feita ao mesmo serviço (isso acontece quando o peso excede o limite de 30kg)
|
132
|
-
- Utilizar webmock nos testes
|
133
131
|
- adicionar opção mão própria
|
134
132
|
- adicionar opção aviso recebimento
|
135
133
|
- adicionar opção valor declarado
|
data/corraios.gemspec
CHANGED
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "activesupport", "~> 4.2"
|
26
26
|
spec.add_development_dependency 'minitest-reporters', '~> 1.0'
|
27
|
-
|
27
|
+
spec.add_development_dependency 'webmock', '~> 1.20'
|
28
28
|
end
|
data/lib/corraios/calculator.rb
CHANGED
@@ -13,14 +13,30 @@ module Corraios
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def perform(*services)
|
16
|
+
deliveries = calculate_services(*services)
|
17
|
+
unify_deliveries(services, deliveries)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def unify_deliveries(services, deliveries)
|
23
|
+
services.map do |service|
|
24
|
+
service_deliveries = deliveries.select { |delivery| delivery.name == service }
|
25
|
+
|
26
|
+
service_deliveries[1..-1].each do |service_delivery|
|
27
|
+
service_deliveries.first.merge!(service_delivery)
|
28
|
+
end if service_deliveries.size > 0
|
29
|
+
|
30
|
+
service_deliveries.first
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def calculate_services(*services)
|
16
35
|
services.map do |service|
|
17
36
|
calculate_delivery(service)
|
18
37
|
end.flatten
|
19
38
|
end
|
20
39
|
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
40
|
def calculate_delivery(service)
|
25
41
|
@packer.containers.map do |container|
|
26
42
|
query_string = "#{to_query_params(service)}&#{container.to_query_params}"
|
data/lib/corraios/delivery.rb
CHANGED
@@ -21,6 +21,15 @@ module Corraios
|
|
21
21
|
!error?
|
22
22
|
end
|
23
23
|
|
24
|
+
def merge!(other)
|
25
|
+
raise CorraiosError unless self == other
|
26
|
+
@value += other.value
|
27
|
+
@deadline = [@deadline, other.deadline].max
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(other)
|
31
|
+
@code == other.code
|
32
|
+
end
|
24
33
|
private
|
25
34
|
def parse_response(response)
|
26
35
|
service = validate_response(response)
|
data/lib/corraios/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corraios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Ra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.20'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.20'
|
83
97
|
description: ''
|
84
98
|
email:
|
85
99
|
- rodrigorcomp@gmail.com
|