corraios 0.0.2 → 0.0.3

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: 196ee11a69202ae51f04d9efeec75e0cf4067161
4
- data.tar.gz: 955e149bb04da4c60e41ef1124623d83280f8410
3
+ metadata.gz: 932b1f786dbdc03735b027b948292fb53ed6a4f7
4
+ data.tar.gz: e55f75f697c551877a6e71d557562d3f3332775d
5
5
  SHA512:
6
- metadata.gz: aad9202ca9285bedfaf5e548959be8c127adc4c1584445435ce480dcc4bc3a183febaa36bd9be119fbf140b61d6b8901e7f174813961323d2fe96ac7eaddb5d1
7
- data.tar.gz: cf74d20b36ba8499c04b5f68e1cf6c28072e0fb34c5870fe4f8b08f45cb280566a2c2990ee9bd793d4141971d1a4393b986b7a608b4dc68fc023dc7e08039b0e
6
+ metadata.gz: df95d7df98e09246a252b7182effdee269644aabbb53b4c07b3c9f5ec9d989ea189e18020ea7df14492c7661e9a80a846d95127169c20b0590f14566fd7ae1af
7
+ data.tar.gz: 96a5bec912baf57e95770163964802e8eb916f398e42652b2269a2d1d47ce1f7c0a74a79139e6a990b398c61739d8b21ea316627f12b1cb62fd0706d8851734f
data/.gitignore CHANGED
@@ -13,4 +13,5 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  .ruby-*
16
- corraios-*.gem
16
+ corraios-*.gem
17
+ test_lib.rb
data/README.md CHANGED
@@ -6,7 +6,7 @@ gem que visa facilitar o cálculo do valor do frete cobrado pelo Correios para e
6
6
  simples e para entregas com multiplos itens.
7
7
 
8
8
  Essa gem é focada para aplicações de e-commerce. Assim, os únicos serviços suportados são
9
- **PAC**, **SEDEX** e **E-SEDEX**.
9
+ **PAC**, **SEDEX**, **SEDEX 10** e **E-SEDEX**.
10
10
 
11
11
  ##Motivação:
12
12
 
@@ -107,6 +107,9 @@ webservices do Correios.
107
107
 
108
108
  delivery = calculator.perform :pac #=> Delivery
109
109
 
110
+ delivery.name # :pac
111
+ delivery.code # 41106
112
+
110
113
  if delivery.success?
111
114
  delivery.deadline # 3
112
115
  delivery.value # 32.12
@@ -24,17 +24,17 @@ module Corraios
24
24
  def calculate_delivery(service)
25
25
  @packer.containers.map do |container|
26
26
  query_string = "#{to_query_params(service)}&#{container.to_query_params}"
27
- parse_delivery(calculate_container(query_string))
27
+ parse_delivery(calculate_container(query_string), service)
28
28
  end
29
29
  end
30
30
 
31
31
  def calculate_container(query_string)
32
- self.class.get("/calculador/CalcPrecoPrazo.aspx?#{query_string}")
32
+ self.class.get("/calculador/CalcPrecoPrazo.aspx?#{query_string}", timeout: 5)
33
33
  end
34
34
 
35
- def parse_delivery(response)
35
+ def parse_delivery(response, service)
36
36
  if response.code == 200
37
- Delivery.new(response.parsed_response)
37
+ Delivery.new(response.parsed_response, service, code_for_service(service))
38
38
  else
39
39
  raise ServiceUnreachable
40
40
  end
@@ -42,12 +42,16 @@ module Corraios
42
42
 
43
43
  def to_query_params(service)
44
44
  query_string = "#{default_query_params}&sCepOrigem=#{@source}&sCepDestino=#{@destination}"
45
- query_string << "&nCdServico=#{Corraios::code_for(service)}"
45
+ query_string << "&nCdServico=#{code_for_service(service)}"
46
46
  query_string << "&nCdEmpresa=#{contract_number}" if contract_number
47
47
  query_string << "&sDsSenha=#{contract_password}" if contract_password
48
48
  query_string
49
49
  end
50
50
 
51
+ def code_for_service(service)
52
+ Corraios::code_for(service)
53
+ end
54
+
51
55
  def default_query_params
52
56
  "sCdMaoPropria=N&nVlValorDeclarado=0&sCdAvisoRecebimento=N&nIndicaCalculo=3&StrRetorno=XML"
53
57
  end
@@ -1,11 +1,14 @@
1
1
  module Corraios
2
2
 
3
3
  class Delivery
4
+ attr_reader :name, :code
4
5
  attr_reader :value, :deadline, :error_message
5
6
 
6
7
  attr_reader :amount_of_posts
7
8
 
8
- def initialize(correios_response)
9
+ def initialize(correios_response, service_name, service_code)
10
+ @name = service_name
11
+ @code = service_code
9
12
  @amount_of_posts = 1
10
13
  parse_response(correios_response)
11
14
  end
@@ -1,3 +1,3 @@
1
1
  module Corraios
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/corraios.rb CHANGED
@@ -5,7 +5,8 @@ module Corraios
5
5
  SERVICES = {
6
6
  pac: 41106,
7
7
  sedex: 40010,
8
- e_sedex: 81019
8
+ e_sedex: 81019,
9
+ sedex_10: 40215
9
10
  }
10
11
 
11
12
  def self.code_for(service)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corraios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Ra
@@ -101,7 +101,6 @@ files:
101
101
  - lib/corraios/containers/roll.rb
102
102
  - lib/corraios/delivery.rb
103
103
  - lib/corraios/packer.rb
104
- - lib/corraios/services/pac.rb
105
104
  - lib/corraios/version.rb
106
105
  homepage: https://github.com/imaboldcompany/corraios
107
106
  licenses:
@@ -1,14 +0,0 @@
1
- module Corraios
2
-
3
- module Services
4
-
5
- class Pac
6
-
7
- def initialize(items)
8
- @items = items
9
- end
10
-
11
-
12
- end
13
- end
14
- end