correios_api 0.5.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: cf169db04d4e23814996679218d7a62c3ee448cc1476750bafeae980a594d1a2
4
- data.tar.gz: c31ddcde2e7119e13ae706b05750c86442bde3eb58bf8947fee00d25ca493721
3
+ metadata.gz: b1b4f48a2104d6ac49417b563e78fee09c9a9380f60e7caa96a6581cd3302124
4
+ data.tar.gz: 9e807f3939fc92c0e0735da58c50448703608572dfddf3e26dca92e84e94d98f
5
5
  SHA512:
6
- metadata.gz: 3e580eb615143becb078949ef5b8b83397ab36e1640c5444f6da2794a3399c1806c012b83a369be5458d568d238ea4aca8fccea57b69734df80bc2106e1d9f41
7
- data.tar.gz: 5cd2059ff69c566df95037cb6b3f7f4c9c03d72804b5295849d63ff3b5b1615b9408df14889e93a9cc34ea7915c7ee6ed90ae737bda640e7bb3c7fb8d6e6106a
6
+ metadata.gz: 9e8ace9e32df4e85270152bce9c6fa9082b8356f94b817f77ecdccc30d6b7d3e5d58db92d3a6c78c608d2d5dd39b9a3f19d52feb107b06eedcd9452c0e2cb8b2
7
+ data.tar.gz: 36a13664dd9abba3339cd2a9fa3032ecc43e942f83fa88fa167bf74cf2701f35d06686a8b75f7e7e54ba7aa7f20617a99c68ccf4719773f5bc3c94d569e0af1a
@@ -159,9 +159,11 @@ module CorreiosApi
159
159
  end
160
160
 
161
161
  def delivery_time zipcode_from, zipcode_to
162
+ zipcode_from_digits = CodigoPostal.new(zipcode_from).cep_digits
163
+ zipcode_to_digits = CodigoPostal.new(zipcode_to).cep_digits
162
164
  body = {
163
165
  idLote: "1",
164
- parametrosPrazo: SERVICES.map { |service| {coProduto: service[:code], nuRequisicao: 1, cepOrigem: zipcode_from, cepDestino: zipcode_to} }
166
+ parametrosPrazo: SERVICES.map { |service| {coProduto: service[:code], nuRequisicao: 1, cepOrigem: zipcode_from_digits, cepDestino: zipcode_to_digits} }
165
167
  }
166
168
  response = post(
167
169
  "/prazo/v1/nacional",
@@ -172,12 +174,14 @@ module CorreiosApi
172
174
  end
173
175
 
174
176
  def delivery_cost zipcode_from, zipcode_to, weight_g, height_cm, width_cm, length_cm
177
+ zipcode_from_digits = CodigoPostal.new(zipcode_from).cep_digits
178
+ zipcode_to_digits = CodigoPostal.new(zipcode_to).cep_digits
175
179
  params_produto = SERVICES.map do |service|
176
180
  {
177
181
  coProduto: service[:code],
178
182
  nuRequisicao: "1",
179
- cepOrigem: zipcode_from,
180
- cepDestino: zipcode_to,
183
+ cepOrigem: zipcode_from_digits,
184
+ cepDestino: zipcode_to_digits,
181
185
  psObjeto: weight_g,
182
186
  altura: height_cm,
183
187
  largura: width_cm,
@@ -1,6 +1,5 @@
1
1
  module CorreiosApi
2
2
  class PreShipping
3
-
4
3
  attr_reader :response, :external_id, :tracking_code, :service_code, :payment_method_id, :price, :items, :post_prevision, :posting_deadline, :status, :status_detail, :label_type, :package_type
5
4
  def initialize response
6
5
  @response = response
@@ -15,7 +15,7 @@ module CorreiosApi
15
15
 
16
16
  def transform_price price
17
17
  return 0.0 unless price
18
- price.gsub(",", ".").to_f
18
+ price.tr(",", ".").to_f
19
19
  end
20
20
 
21
21
  def transform_date date
@@ -1,17 +1,16 @@
1
1
  module CorreiosApi
2
2
  class ShippingQuotes
3
-
4
3
  attr_reader :rates
5
4
  def initialize rates
6
5
  @rates = rates
7
6
  end
8
7
 
9
8
  def cheaper_rate
10
- valid_rates.sort_by(&:price).first
9
+ valid_rates.min_by(&:price)
11
10
  end
12
11
 
13
12
  def faster_rate
14
- valid_rates.sort_by(&:delivery_time_in_days).first
13
+ valid_rates.min_by(&:delivery_time_in_days)
15
14
  end
16
15
 
17
16
  def valid_rates
@@ -1,6 +1,5 @@
1
1
  module CorreiosApi
2
2
  class Tracking
3
-
4
3
  attr_reader :response, :tracking_code, :sigla, :descricao, :categoria, :data_prevista, :weight_g, :height_cm, :width_cm, :length_cm, :formato, :modalidade, :eventos
5
4
  def initialize response
6
5
  @tracking_code = response.dig("objetos", 0, "codObjeto")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CorreiosApi
4
- VERSION = "0.5.0"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/correios_api.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative "correios_api/version"
2
2
 
3
+ require "codigo_postal"
3
4
  require "base64"
4
5
  require "ac"
5
6
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: correios_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todas Essas Coisas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-08 00:00:00.000000000 Z
11
+ date: 2024-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codigo_postal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: base64
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +81,7 @@ metadata:
67
81
  homepage_uri: https://github.com/todasessascoisas/correios_api
68
82
  source_code_uri: https://github.com/todasessascoisas/correios_api
69
83
  changelog_uri: https://github.com/todasessascoisas/correios_api
70
- post_install_message:
84
+ post_install_message:
71
85
  rdoc_options: []
72
86
  require_paths:
73
87
  - lib
@@ -82,8 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
96
  - !ruby/object:Gem::Version
83
97
  version: '0'
84
98
  requirements: []
85
- rubygems_version: 3.5.10
86
- signing_key:
99
+ rubygems_version: 3.5.11
100
+ signing_key:
87
101
  specification_version: 4
88
102
  summary: ''
89
103
  test_files: []