nz_post_api 0.6.0 → 0.7.0

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: 79fc7d9823bc2ee076dd26982aad65e2ec9cd2354403ffd0afd6414f0a1b9f49
4
- data.tar.gz: 22a970d9bba8db00bf083b2a586d024a1e8905c8430af12218bfce287926ebb1
3
+ metadata.gz: 959f7bc78fae9b31231d76977d9cbba085cf400a0f2c474a836aef47c05560d1
4
+ data.tar.gz: 8d588514158a3f0dc4e2b2b2157228cf4af180bd1fe74a20e8d3165f9fd077db
5
5
  SHA512:
6
- metadata.gz: c6f21391ee069bcb2e08742f2b7c4e6aec58703063c5ed76c0e3bded858e6d4f6fa6180bafbaeb45178661997c826fcb8af40520532713f5e7d30c5e13acde78
7
- data.tar.gz: f5c356b9498efcacfdc383b2f9333c936cfea3a1603cd724b3dccb812ae50c39176e18d847fc8e82f4c1b0b98e02590b1e68a8ba2fd434ddaa538b0c8ccd3cee
6
+ metadata.gz: 552186803f84a8dc134d297a5059d7ecbc1fd6d61ecc42cb823250c50765081efba4ddf1e6e9587a772de787e9378c37fa9b473d239c42ccb642099430e946c3
7
+ data.tar.gz: deadece3e518de6e102bafbba15f2c3a6ddf055a3a245365694a493160d4fde3ed9bce9d5ec332c8667fefce8e24b8e1827e84a8386681c123e31956b2e6af88
data/README.md CHANGED
@@ -47,6 +47,20 @@ client = NzPostApi::Client.new(
47
47
  - `access_token` – Bearer token from `NzPostApi::Auth.fetch_token` (required)
48
48
  - `prod:` – Set to `true` for production (`https://api.nzpost.co.nz`), `false` for UAT (`https://api.uat.nzpost.co.nz`). Defaults to `false`.
49
49
 
50
+ ### Error Handling
51
+
52
+ API request failures raise `NzPostApi::Error`. The error object exposes both HTTP status code and response body:
53
+
54
+ ```ruby
55
+ begin
56
+ client.parcel_address.search(q: "Invalid")
57
+ rescue NzPostApi::Error => error
58
+ puts error.message
59
+ puts error.response_http_code
60
+ puts error.response_body
61
+ end
62
+ ```
63
+
50
64
  ### Parcel Address
51
65
 
52
66
  #### Search
@@ -20,7 +20,11 @@ module NzPostApi
20
20
  if response.success?
21
21
  JSON.parse(response.body)
22
22
  else
23
- raise NzPostApi::Error, "Failed to fetch token: #{response.status} - #{response.body}"
23
+ raise NzPostApi::Error.new(
24
+ "Failed to fetch token: #{response.status} - #{response.body}",
25
+ response_http_code: response.status,
26
+ response_body: response.body
27
+ )
24
28
  end
25
29
  end
26
30
  end
@@ -17,7 +17,11 @@ module NzPostApi
17
17
  if response.success?
18
18
  response.body["addresses"].map { |addr| Objects::Address.new(addr) }
19
19
  else
20
- raise NzPostApi::Error, "Failed to search addresses: #{response.status} - #{response.body}"
20
+ raise NzPostApi::Error.new(
21
+ "Failed to search addresses: #{response.status} - #{response.body}",
22
+ response_http_code: response.status,
23
+ response_body: response.body
24
+ )
21
25
  end
22
26
  end
23
27
  end
@@ -26,7 +26,11 @@ module NzPostApi
26
26
  if response.success?
27
27
  response.body
28
28
  else
29
- raise NzPostApi::Error, "Failed to download label: #{response.status} - #{response.body}"
29
+ raise NzPostApi::Error.new(
30
+ "Failed to download label: #{response.status} - #{response.body}",
31
+ response_http_code: response.status,
32
+ response_body: response.body
33
+ )
30
34
  end
31
35
  end
32
36
 
@@ -36,7 +40,11 @@ module NzPostApi
36
40
  if response.success?
37
41
  Objects::Label.new(response.body)
38
42
  else
39
- raise NzPostApi::Error, "Failed to create/get label: #{response.status} - #{response.body}"
43
+ raise NzPostApi::Error.new(
44
+ "Failed to create/get label: #{response.status} - #{response.body}",
45
+ response_http_code: response.status,
46
+ response_body: response.body
47
+ )
40
48
  end
41
49
  end
42
50
  end
@@ -17,7 +17,11 @@ module NzPostApi
17
17
  if response.success?
18
18
  Objects::ParcelTrack.new(response.body["results"])
19
19
  else
20
- raise NzPostApi::Error, "Failed to track parcel: #{response.status} - #{response.body}"
20
+ raise NzPostApi::Error.new(
21
+ "Failed to track parcel: #{response.status} - #{response.body}",
22
+ response_http_code: response.status,
23
+ response_body: response.body
24
+ )
21
25
  end
22
26
  end
23
27
 
@@ -31,7 +35,11 @@ module NzPostApi
31
35
  if response.success?
32
36
  Objects::ParcelTrackSubscription.new(response.body)
33
37
  else
34
- raise NzPostApi::Error, "Failed to subscribe to parcel: #{response.status} - #{response.body}"
38
+ raise NzPostApi::Error.new(
39
+ "Failed to subscribe to parcel: #{response.status} - #{response.body}",
40
+ response_http_code: response.status,
41
+ response_body: response.body
42
+ )
35
43
  end
36
44
  end
37
45
 
@@ -41,7 +49,11 @@ module NzPostApi
41
49
  if response.success?
42
50
  true
43
51
  else
44
- raise NzPostApi::Error, "Failed to unsubscribe from parcel: #{response.status} - #{response.body}"
52
+ raise NzPostApi::Error.new(
53
+ "Failed to unsubscribe from parcel: #{response.status} - #{response.body}",
54
+ response_http_code: response.status,
55
+ response_body: response.body
56
+ )
45
57
  end
46
58
  end
47
59
  end
@@ -17,7 +17,11 @@ module NzPostApi
17
17
  if response.success?
18
18
  Objects::ShippingOption.new(response.body)
19
19
  else
20
- raise NzPostApi::Error, "Failed to list options: #{response.status} - #{response.body}"
20
+ raise NzPostApi::Error.new(
21
+ "Failed to list options: #{response.status} - #{response.body}",
22
+ response_http_code: response.status,
23
+ response_body: response.body
24
+ )
21
25
  end
22
26
  end
23
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NzPostApi
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/nz_post_api.rb CHANGED
@@ -15,5 +15,13 @@ require_relative "nz_post_api/resources/shipping_option"
15
15
  require_relative "nz_post_api/resources/parcel_track"
16
16
 
17
17
  module NzPostApi
18
- class Error < StandardError; end
18
+ class Error < StandardError
19
+ attr_reader :response_http_code, :response_body
20
+
21
+ def initialize(message = nil, response_http_code: nil, response_body: nil)
22
+ @response_http_code = response_http_code
23
+ @response_body = response_body
24
+ super(message)
25
+ end
26
+ end
19
27
  end
data/sig/nz_post_api.rbs CHANGED
@@ -1,4 +1,9 @@
1
1
  module NzPostApi
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+ class Error < ::StandardError
4
+ attr_reader response_http_code: Integer?
5
+ attr_reader response_body: untyped
6
+
7
+ def initialize: (?String message, ?response_http_code: Integer, ?response_body: untyped) -> void
8
+ end
4
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nz_post_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-02-05 00:00:00.000000000 Z
11
+ date: 2026-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday