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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1c811102c68dfc955dd2112501b5700813aa421
4
- data.tar.gz: 3097c12695b024281744938f1f731a8562e31e92
3
+ metadata.gz: 6417ca32463b2238feac9aa24170c153021e633e
4
+ data.tar.gz: a4564955bfddf1646bbfc568b5f9c42bcd278577
5
5
  SHA512:
6
- metadata.gz: 4df5316d9e47de63f9ca8df6f57386563d8457502e705c3e559961f2a766d9fdf5204d09a76f4d7021931ff012826e088f4811f9e3976dea24777febd134ba78
7
- data.tar.gz: d7d972e07e2b2f0b9a524a7c4e94295331c567f02f6a247bc49ff839a9ec3d8e4195b25035a3b67b90333be68f4615d974802c333f511bba4188f9374f42b887
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
@@ -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}"
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Corraios
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
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.8
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-20 00:00:00.000000000 Z
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