correios_api 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/correios_api/client.rb +14 -6
- data/lib/correios_api/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d97899305ead4c4911dd1fe1c201306e26d165324531a2cb847a742b641d3ce
|
4
|
+
data.tar.gz: 3b9d62e983fde19b06f98de0274c1c72be0c8c18439df8f09c8212910b4abade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 850e4f35f98d188701c02e7b85dea38585207815b3a83ca15557ef1ad0997cbde4d50d32be7e64e07f36c69b379762ddbf0aa5d4b94ce5df6a4cb7f2660b3142
|
7
|
+
data.tar.gz: 5605ca4f3c18d54464befc09991783002c371f6b7574da142bbc443c00f1f9b6c1286ae434a027f4782abd491744a1cc3c079562f06137a8980a0528308868fc
|
data/lib/correios_api/client.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module CorreiosApi
|
2
2
|
class Client < Ac::Base
|
3
3
|
BASE_URL = "https://api.correios.com.br"
|
4
|
-
MAX_RETRIES =
|
4
|
+
MAX_RETRIES = 4
|
5
5
|
SAVE_RESPONSES = true
|
6
|
+
TIMEOUT = 4
|
6
7
|
|
7
8
|
SERVICES = [
|
8
9
|
{
|
@@ -56,7 +57,8 @@ module CorreiosApi
|
|
56
57
|
"Authorization" => "Basic #{Base64.strict_encode64("#{@username}:#{@password}")}",
|
57
58
|
"Content-Type" => "application/json"
|
58
59
|
},
|
59
|
-
body: JSON.dump(body)
|
60
|
+
body: JSON.dump(body),
|
61
|
+
timeout: TIMEOUT
|
60
62
|
) { |response| validate_response(response, "token") }
|
61
63
|
@token = response.json.dig("token")
|
62
64
|
@expires_in = Time.new(response.json.dig("expiraEm"))
|
@@ -112,7 +114,8 @@ module CorreiosApi
|
|
112
114
|
response = post(
|
113
115
|
"/prepostagem/v1/prepostagens",
|
114
116
|
headers: headers,
|
115
|
-
body: JSON.dump(body)
|
117
|
+
body: JSON.dump(body),
|
118
|
+
timeout: TIMEOUT
|
116
119
|
) { |response| validate_response(response, "id") }
|
117
120
|
PreShipping.new(response.json)
|
118
121
|
end
|
@@ -133,7 +136,8 @@ module CorreiosApi
|
|
133
136
|
response = post(
|
134
137
|
"/prepostagem/v1/prepostagens/rotulo/assincrono/pdf",
|
135
138
|
headers: headers,
|
136
|
-
body: JSON.dump(body)
|
139
|
+
body: JSON.dump(body),
|
140
|
+
timeout: TIMEOUT
|
137
141
|
) { |response| validate_response(response, "idRecibo") }
|
138
142
|
sleep(0.5) # Tem que esperar o PDF ficar pronto
|
139
143
|
get_label(response.json.dig("idRecibo"))
|
@@ -176,10 +180,12 @@ module CorreiosApi
|
|
176
180
|
idLote: "1",
|
177
181
|
parametrosPrazo: SERVICES.map { |service| {coProduto: service[:code], nuRequisicao: 1, cepOrigem: zipcode_from_digits, cepDestino: zipcode_to_digits} }
|
178
182
|
}
|
183
|
+
|
179
184
|
response = post(
|
180
185
|
"/prazo/v1/nacional",
|
181
186
|
headers: headers,
|
182
|
-
body: JSON.dump(body)
|
187
|
+
body: JSON.dump(body),
|
188
|
+
timeout: TIMEOUT
|
183
189
|
) { |response| validate_response(response, "coProduto") }
|
184
190
|
response.json
|
185
191
|
end
|
@@ -204,10 +210,12 @@ module CorreiosApi
|
|
204
210
|
idLote: "1",
|
205
211
|
parametrosProduto: params_produto
|
206
212
|
}
|
213
|
+
|
207
214
|
response = post(
|
208
215
|
"/preco/v1/nacional",
|
209
216
|
headers: headers,
|
210
|
-
body: JSON.dump(body)
|
217
|
+
body: JSON.dump(body),
|
218
|
+
timeout: TIMEOUT
|
211
219
|
) { |response| validate_response(response, "coProduto") }
|
212
220
|
response.json
|
213
221
|
end
|
data/lib/correios_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correios_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todas Essas Coisas
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: codigo_postal
|
@@ -81,7 +80,6 @@ metadata:
|
|
81
80
|
homepage_uri: https://github.com/todasessascoisas/correios_api
|
82
81
|
source_code_uri: https://github.com/todasessascoisas/correios_api
|
83
82
|
changelog_uri: https://github.com/todasessascoisas/correios_api
|
84
|
-
post_install_message:
|
85
83
|
rdoc_options: []
|
86
84
|
require_paths:
|
87
85
|
- lib
|
@@ -96,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
94
|
- !ruby/object:Gem::Version
|
97
95
|
version: '0'
|
98
96
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
100
|
-
signing_key:
|
97
|
+
rubygems_version: 3.6.2
|
101
98
|
specification_version: 4
|
102
99
|
summary: ''
|
103
100
|
test_files: []
|