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 +4 -4
- data/.gitignore +2 -1
- data/README.md +4 -1
- data/lib/corraios/calculator.rb +9 -5
- data/lib/corraios/delivery.rb +4 -1
- data/lib/corraios/version.rb +1 -1
- data/lib/corraios.rb +2 -1
- metadata +1 -2
- data/lib/corraios/services/pac.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 932b1f786dbdc03735b027b948292fb53ed6a4f7
|
4
|
+
data.tar.gz: e55f75f697c551877a6e71d557562d3f3332775d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df95d7df98e09246a252b7182effdee269644aabbb53b4c07b3c9f5ec9d989ea189e18020ea7df14492c7661e9a80a846d95127169c20b0590f14566fd7ae1af
|
7
|
+
data.tar.gz: 96a5bec912baf57e95770163964802e8eb916f398e42652b2269a2d1d47ce1f7c0a74a79139e6a990b398c61739d8b21ea316627f12b1cb62fd0706d8851734f
|
data/.gitignore
CHANGED
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
|
data/lib/corraios/calculator.rb
CHANGED
@@ -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=#{
|
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
|
data/lib/corraios/delivery.rb
CHANGED
@@ -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
|
data/lib/corraios/version.rb
CHANGED
data/lib/corraios.rb
CHANGED
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.
|
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:
|