pratka 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '04085d85f88834e2907d322efdcf9ab8ccf3588514a5d362c19223f4cd22a790'
4
- data.tar.gz: ff5582b3d13b92cad8e7fc36de4abd1f44462c67a58ea62031b66628aafedc04
3
+ metadata.gz: 7940c2073d0fbeec909b2f5f545729474e26f1113c4d9dd154046ae7f8e7780f
4
+ data.tar.gz: 58293d9ab43d5addb4e84208bff655d76db9fd84c14a74acb43d50cd3376c6ba
5
5
  SHA512:
6
- metadata.gz: 47c29ce1d7858648f126d8f498c65232f7481e389049b469015dde5aa411a5cd83163dec1117426b97793cbb8fd5d7a146555e5617425c730e6ba52c30c05036
7
- data.tar.gz: ee5af3f162ba6c5f5a6a893e096e4bfb41bef64a72f30f43ae305ffd152daa2f21a883317dff79b7b03186f117e2c49e728fae76a730fc5bcb745a83d20343ee
6
+ metadata.gz: fe7b5484ea064bc9ff8dc3e42b31fe24c6bfcab9231c7f6e35140beba7b7dd2a2c43c85f4087e52af6684167aa80c093ab0f6386f3b167293523ad1b079b1e02
7
+ data.tar.gz: 7e1b7237afd97ef8d001e861953b55b7e6bb6c55888f22f4a285c5db531475b9d3f9103e806c83cb39950e8d9e89ed31da15fcb46fc2d10a532662b0128a4cea
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2026-10-12
4
+
5
+ ### Changed
6
+
7
+ - Invalid params raise `Pratka::Speedy::InvalidParamsError` instead of `ArgumentError`, so `rescue Pratka::Error` covers every failure
8
+
9
+ ## [0.1.1] - 2026-10-08
10
+
11
+ ### Added
12
+
13
+ - `fetch_shipment_info` returns full details of existing shipments
14
+
15
+ [0.1.1]: https://github.com/tripplesteel/pratka/releases/tag/v0.1.1
16
+
3
17
  ## [0.1.0] - 2026-10-07
4
18
 
5
19
  Initial release, with Speedy as the first supported courier.
@@ -18,5 +32,4 @@ Initial release, with Speedy as the first supported courier.
18
32
  - Validation of required params, which treats blank values as missing
19
33
  - Supports Ruby 3.3+ and JRuby
20
34
 
21
- [Unreleased]: https://github.com/tripplesteel/pratka/compare/v0.1.0...HEAD
22
35
  [0.1.0]: https://github.com/tripplesteel/pratka/releases/tag/v0.1.0
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 `ArgumentError` with the message `Missing params: parcels`
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
 
@@ -345,6 +345,30 @@ Example response:
345
345
  }
346
346
  ```
347
347
 
348
+ #### Fetch shipment info
349
+
350
+ ```ruby
351
+ client.fetch_shipment_info(shipment_ids: ["299999990", "299999991"])
352
+ ```
353
+
354
+ Allowed options:
355
+ - `shipment_ids` (Mandatory) - Array of shipment ids
356
+
357
+ Returns the parsed JSON response with one [Shipment](https://api.speedy.bg/api/docs/#href-ds-shipment) per id. Each shipment has its sender, recipient, service, content, payment, price and delivery details, plus `ref1`, `ref2`, `returnShipmentId` and `redirectShipmentId` when set
358
+
359
+ Example response:
360
+
361
+ ```ruby
362
+ {"shipments" =>
363
+ [{"id" => "299999990",
364
+ "ref1" => "ORDER-1001",
365
+ "service" => {"serviceId" => 505, "pickupDate" => "2026-10-08"},
366
+ "content" => {"parcelsCount" => 1, "totalWeight" => 1.5, "contents" => "Books"},
367
+ "price" => {"amount" => 6.2, "vat" => 1.24, "total" => 7.44, "currency" => "BGN"},
368
+ "delivery" => {"deliveryDeadline" => "2026-10-09T19:00:00+0300"}}]
369
+ }
370
+ ```
371
+
348
372
  #### Calculate
349
373
 
350
374
  ```ruby
@@ -403,7 +427,7 @@ Returns the parsed JSON response with one tracked parcel per matched parcel. A `
403
427
 
404
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
405
429
 
406
- Speedy asks clients to send at most 10 parcels per request and plans to enforce that limit. `track` enforces it already, so if you send more than 10 parcels it raises `ArgumentError` with the message `Speedy tracks at most 10 parcels per call`. Split larger lists into batches, for example with `each_slice(10)`
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)`
407
431
 
408
432
  Example response:
409
433
 
@@ -421,18 +445,17 @@ Example response:
421
445
 
422
446
  ### Errors
423
447
 
424
- Every network and API failure raises a subclass of `Pratka::Speedy::Error`, which inherits from `Pratka::Error`
448
+ Every failure raises a subclass of `Pratka::Speedy::Error`, which inherits from `Pratka::Error`, so `rescue Pratka::Error` covers them all
425
449
 
426
450
  | Error | Raised when | Extra attributes |
427
451
  | --- | --- | --- |
452
+ | `Pratka::Speedy::InvalidParamsError` | A param is unknown, missing or over a limit. Raised before any request is sent | |
428
453
  | `Pratka::Speedy::TimeoutError` | The connection or read times out | |
429
454
  | `Pratka::Speedy::ConnectionError` | DNS, socket or SSL failure | |
430
455
  | `Pratka::Speedy::HTTPError` | Speedy returns a non-2xx status | `status`, `body` |
431
456
  | `Pratka::Speedy::APIError` | Speedy returns 2xx with an `error` object in the body | `code`, `context`, `id` |
432
457
  | `Pratka::Speedy::Error` | The response is malformed, has invalid JSON, or has an unexpected format | |
433
458
 
434
- Bad arguments raise `ArgumentError` before any request is sent, for example an unknown option or a missing `site_id`
435
-
436
459
  ```ruby
437
460
  begin
438
461
  client.fetch_streets(site_id: 36124, name: "Алеко")
@@ -61,11 +61,13 @@ module Pratka
61
61
  payment: :payment
62
62
  }.freeze
63
63
 
64
+ SHIPMENT_INFO_ENDPOINT = "shipment/info"
65
+ SHIPMENT_INFO_PARAMS = { shipment_ids: :shipmentIds }.freeze
66
+
64
67
  TRACK_ENDPOINT = "track"
65
68
  TRACK_PARAMS = { parcels: :parcels, last_operation_only: :lastOperationOnly }.freeze
66
69
 
67
- # Speedy recommends 10 parcels per request and plans to enforce it
68
-
70
+ # Speedy allows up to 10 parcels per request
69
71
  TRACK_MAX_PARCELS = 10
70
72
 
71
73
  def initialize(username:, password:, language: nil, country_id: Speedy.configuration.country_id)
@@ -159,6 +161,15 @@ module Pratka
159
161
  call(CREATE_SHIPMENT_ENDPOINT, map_params(options, SHIPMENT_PARAMS, required: %i[recipient service content payment]))
160
162
  end
161
163
 
164
+ # Fetch full details of existing shipments
165
+ # [Shipment Information Request (ShipmentInformationRequest)](https://api.speedy.bg/api/docs/#href-shipment-info-req)
166
+ # Allowed params:
167
+ # shipment_ids (Mandatory) - String[] - Shipment ids
168
+ # Returns one Shipment per id with its sender, recipient, service, content, payment, price and delivery
169
+ def fetch_shipment_info(**options)
170
+ call(SHIPMENT_INFO_ENDPOINT, map_params(options, SHIPMENT_INFO_PARAMS, required: [:shipment_ids]))
171
+ end
172
+
162
173
  # Calculate shipment price and delivery deadline for one or more services
163
174
  # [Calculation Request (CalculationRequest)](https://api.speedy.bg/api/docs/#href-calculation-req)
164
175
  # Allowed params:
@@ -180,7 +191,7 @@ module Pratka
180
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
181
192
  def track(**options)
182
193
  params = map_params(options, TRACK_PARAMS, required: [:parcels])
183
- raise ArgumentError, "Speedy tracks at most #{TRACK_MAX_PARCELS} parcels per call" if params[:parcels].size > TRACK_MAX_PARCELS
194
+ raise InvalidParamsError, "Speedy tracks at most #{TRACK_MAX_PARCELS} parcels per call" if params[:parcels].size > TRACK_MAX_PARCELS
184
195
 
185
196
  call(TRACK_ENDPOINT, params)
186
197
  end
@@ -193,10 +204,10 @@ module Pratka
193
204
 
194
205
  def map_params(options, mapping, required: [])
195
206
  unknown = options.keys - mapping.keys
196
- raise ArgumentError, "Unknown params: #{unknown.join(", ")}" if unknown.any?
207
+ raise InvalidParamsError, "Unknown params: #{unknown.join(", ")}" if unknown.any?
197
208
 
198
209
  missing = required.select { |key| blank?(options[key]) }
199
- raise ArgumentError, "Missing params: #{missing.join(", ")}" if missing.any?
210
+ raise InvalidParamsError, "Missing params: #{missing.join(", ")}" if missing.any?
200
211
 
201
212
  options.transform_keys(mapping)
202
213
  end
@@ -7,6 +7,7 @@ module Pratka
7
7
  class Error < Pratka::Error; end
8
8
  class TimeoutError < Error; end
9
9
  class ConnectionError < Error; end
10
+ class InvalidParamsError < Error; end
10
11
 
11
12
  class HTTPError < Error
12
13
  attr_reader :status, :body
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pratka
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pratka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stilqn Bairski