pratka 0.1.1 → 0.1.2
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/CHANGELOG.md +6 -0
- data/README.md +4 -5
- data/lib/pratka/speedy/client.rb +3 -3
- data/lib/pratka/speedy/errors.rb +1 -0
- data/lib/pratka/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7940c2073d0fbeec909b2f5f545729474e26f1113c4d9dd154046ae7f8e7780f
|
|
4
|
+
data.tar.gz: 58293d9ab43d5addb4e84208bff655d76db9fd84c14a74acb43d50cd3376c6ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe7b5484ea064bc9ff8dc3e42b31fe24c6bfcab9231c7f6e35140beba7b7dd2a2c43c85f4087e52af6684167aa80c093ab0f6386f3b167293523ad1b079b1e02
|
|
7
|
+
data.tar.gz: 7e1b7237afd97ef8d001e861953b55b7e6bb6c55888f22f4a285c5db531475b9d3f9103e806c83cb39950e8d9e89ed31da15fcb46fc2d10a532662b0128a4cea
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -258,7 +258,7 @@ Returns raw PDF or ZPL bytes if the request is successful and the parcel exists
|
|
|
258
258
|
|
|
259
259
|
If the parcels don't exist in Speedy, `print_label` raises `Pratka::Speedy::Error` with the message `Speedy returned an empty label; check the parcel IDs`
|
|
260
260
|
|
|
261
|
-
If you send empty parcels, `print_label` raises `
|
|
261
|
+
If you send empty parcels, `print_label` raises `Pratka::Speedy::InvalidParamsError` with the message `Missing params: parcels`
|
|
262
262
|
|
|
263
263
|
#### Fetch payment details
|
|
264
264
|
|
|
@@ -427,7 +427,7 @@ Returns the parsed JSON response with one tracked parcel per matched parcel. A `
|
|
|
427
427
|
|
|
428
428
|
A parcel Speedy can't find comes back with its own `error` object instead of operations. `track` doesn't raise for it, so check each parcel
|
|
429
429
|
|
|
430
|
-
Speedy enforces 10 parcels limit per request. If you send more than 10 parcels it raises `
|
|
430
|
+
Speedy enforces 10 parcels limit per request. If you send more than 10 parcels it raises `Pratka::Speedy::InvalidParamsError` with the message `Speedy tracks at most 10 parcels per call`. Split larger lists into batches, for example with `each_slice(10)`
|
|
431
431
|
|
|
432
432
|
Example response:
|
|
433
433
|
|
|
@@ -445,18 +445,17 @@ Example response:
|
|
|
445
445
|
|
|
446
446
|
### Errors
|
|
447
447
|
|
|
448
|
-
Every
|
|
448
|
+
Every failure raises a subclass of `Pratka::Speedy::Error`, which inherits from `Pratka::Error`, so `rescue Pratka::Error` covers them all
|
|
449
449
|
|
|
450
450
|
| Error | Raised when | Extra attributes |
|
|
451
451
|
| --- | --- | --- |
|
|
452
|
+
| `Pratka::Speedy::InvalidParamsError` | A param is unknown, missing or over a limit. Raised before any request is sent | |
|
|
452
453
|
| `Pratka::Speedy::TimeoutError` | The connection or read times out | |
|
|
453
454
|
| `Pratka::Speedy::ConnectionError` | DNS, socket or SSL failure | |
|
|
454
455
|
| `Pratka::Speedy::HTTPError` | Speedy returns a non-2xx status | `status`, `body` |
|
|
455
456
|
| `Pratka::Speedy::APIError` | Speedy returns 2xx with an `error` object in the body | `code`, `context`, `id` |
|
|
456
457
|
| `Pratka::Speedy::Error` | The response is malformed, has invalid JSON, or has an unexpected format | |
|
|
457
458
|
|
|
458
|
-
Bad arguments raise `ArgumentError` before any request is sent, for example an unknown option or a missing `site_id`
|
|
459
|
-
|
|
460
459
|
```ruby
|
|
461
460
|
begin
|
|
462
461
|
client.fetch_streets(site_id: 36124, name: "Алеко")
|
data/lib/pratka/speedy/client.rb
CHANGED
|
@@ -191,7 +191,7 @@ module Pratka
|
|
|
191
191
|
# Returns one tracked parcel per matched parcel. A ref can match up to 10. Each tracked parcel carries its own error if Speedy can't track it
|
|
192
192
|
def track(**options)
|
|
193
193
|
params = map_params(options, TRACK_PARAMS, required: [:parcels])
|
|
194
|
-
raise
|
|
194
|
+
raise InvalidParamsError, "Speedy tracks at most #{TRACK_MAX_PARCELS} parcels per call" if params[:parcels].size > TRACK_MAX_PARCELS
|
|
195
195
|
|
|
196
196
|
call(TRACK_ENDPOINT, params)
|
|
197
197
|
end
|
|
@@ -204,10 +204,10 @@ module Pratka
|
|
|
204
204
|
|
|
205
205
|
def map_params(options, mapping, required: [])
|
|
206
206
|
unknown = options.keys - mapping.keys
|
|
207
|
-
raise
|
|
207
|
+
raise InvalidParamsError, "Unknown params: #{unknown.join(", ")}" if unknown.any?
|
|
208
208
|
|
|
209
209
|
missing = required.select { |key| blank?(options[key]) }
|
|
210
|
-
raise
|
|
210
|
+
raise InvalidParamsError, "Missing params: #{missing.join(", ")}" if missing.any?
|
|
211
211
|
|
|
212
212
|
options.transform_keys(mapping)
|
|
213
213
|
end
|
data/lib/pratka/speedy/errors.rb
CHANGED
data/lib/pratka/version.rb
CHANGED