nz_post_api 0.2.0 → 0.3.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 +4 -4
- data/README.md +50 -1
- data/lib/nz_post_api/client.rb +4 -0
- data/lib/nz_post_api/objects/parcel_track.rb +8 -0
- data/lib/nz_post_api/objects/parcel_track_subscription.rb +8 -0
- data/lib/nz_post_api/resources/parcel_track.rb +47 -0
- data/lib/nz_post_api/version.rb +1 -1
- data/lib/nz_post_api.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd7725f76d54c6a212beecd45f4ffc568ae7b0ab010d69ecf0f92d3dcbe57149
|
|
4
|
+
data.tar.gz: 7298abe8f2dae29e17f9525839b405e5c88a6be22f9072021002cdc1e3a8c957
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 233660b133767bfc37a494719f344be5882d5d1093cbd92fc51b835e25481e0ba2d31ac4f5f4991622a9d3f3cae389350580e635bb99e35f55fdd4bce2efad9e
|
|
7
|
+
data.tar.gz: '08319bcd20474c2bccbc4f69b14bb57ccbe648e9ef95c186b3bc719067259baa4e8e7bd8840acfdd62d79d7564d0283e986be1cafe1cb87eb3f3775892a85070'
|
data/README.md
CHANGED
|
@@ -168,7 +168,7 @@ file.unlink # deletes the temp file
|
|
|
168
168
|
|
|
169
169
|
List available shipping options based on package details.
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
````ruby
|
|
172
172
|
shipping_client = client.shipping_options
|
|
173
173
|
|
|
174
174
|
params = {
|
|
@@ -182,10 +182,56 @@ params = {
|
|
|
182
182
|
|
|
183
183
|
response = shipping_client.list(params)
|
|
184
184
|
response.services.each do |service|
|
|
185
|
+
puts service.service_code
|
|
185
186
|
puts service.service_code
|
|
186
187
|
puts service.description
|
|
187
188
|
end
|
|
188
189
|
|
|
190
|
+
### Parcel Track
|
|
191
|
+
|
|
192
|
+
#### Track Parcel
|
|
193
|
+
|
|
194
|
+
Retrieve tracking events for a parcel.
|
|
195
|
+
|
|
196
|
+
```ruby
|
|
197
|
+
track_client = client.parcel_track
|
|
198
|
+
tracking = track_client.track("TRACKING_NUMBER")
|
|
199
|
+
|
|
200
|
+
puts tracking.tracking_reference
|
|
201
|
+
tracking.tracking_events.each do |event|
|
|
202
|
+
puts "#{event.event_datetime}: #{event.event_description}"
|
|
203
|
+
end
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Subscribe to Updates
|
|
207
|
+
|
|
208
|
+
Subscribe to tracking updates for a parcel via webhook.
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
track_client = client.parcel_track
|
|
212
|
+
subscription = track_client.subscribe(
|
|
213
|
+
tracking_reference: "TRACKING_NUMBER",
|
|
214
|
+
notification_endpoint: "https://my.endpoint.com/nz_post_tracking"
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
puts subscription.subscription_guid
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### Unsubscribe
|
|
221
|
+
|
|
222
|
+
Unsubscribe from tracking updates.
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
225
|
+
track_client = client.parcel_track
|
|
226
|
+
success = track_client.unsubscribe(subscription_guid: "SUBSCRIPTION_GUID")
|
|
227
|
+
|
|
228
|
+
if success
|
|
229
|
+
puts "Unsubscribed successfully"
|
|
230
|
+
else
|
|
231
|
+
puts "Failed to unsubscribe"
|
|
232
|
+
end
|
|
233
|
+
````
|
|
234
|
+
|
|
189
235
|
## Development
|
|
190
236
|
|
|
191
237
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -203,4 +249,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
203
249
|
## Code of Conduct
|
|
204
250
|
|
|
205
251
|
Everyone interacting in the NzPostApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nz_post_api/blob/main/CODE_OF_CONDUCT.md).
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
|
|
206
255
|
```
|
data/lib/nz_post_api/client.rb
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NzPostApi
|
|
4
|
+
module Resources
|
|
5
|
+
class ParcelTrack
|
|
6
|
+
BASE_URL = "https://api.uat.nzpost.co.nz/parceltrack/3.0/parcels"
|
|
7
|
+
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def track(tracking_reference)
|
|
13
|
+
response = @client.connection.get("#{BASE_URL}/#{tracking_reference}")
|
|
14
|
+
|
|
15
|
+
if response.success?
|
|
16
|
+
Objects::ParcelTrack.new(response.body["results"])
|
|
17
|
+
else
|
|
18
|
+
raise NzPostApi::Error, "Failed to track parcel: #{response.status} - #{response.body}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def subscribe(tracking_reference:, notification_endpoint:)
|
|
23
|
+
payload = {
|
|
24
|
+
tracking_reference: tracking_reference,
|
|
25
|
+
notification_endpoint: notification_endpoint
|
|
26
|
+
}
|
|
27
|
+
response = @client.connection.post("#{BASE_URL.sub('parcels', 'subscription/webhook/')}", payload)
|
|
28
|
+
|
|
29
|
+
if response.success?
|
|
30
|
+
Objects::ParcelTrackSubscription.new(response.body)
|
|
31
|
+
else
|
|
32
|
+
raise NzPostApi::Error, "Failed to subscribe to parcel: #{response.status} - #{response.body}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def unsubscribe(subscription_guid:)
|
|
37
|
+
response = @client.connection.delete("#{BASE_URL.sub('parcels', 'subscription/webhook')}/#{subscription_guid}")
|
|
38
|
+
|
|
39
|
+
if response.success?
|
|
40
|
+
true
|
|
41
|
+
else
|
|
42
|
+
raise NzPostApi::Error, "Failed to unsubscribe from parcel: #{response.status} - #{response.body}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/nz_post_api/version.rb
CHANGED
data/lib/nz_post_api.rb
CHANGED
|
@@ -5,11 +5,14 @@ require_relative "nz_post_api/objects/base"
|
|
|
5
5
|
require_relative "nz_post_api/objects/address"
|
|
6
6
|
require_relative "nz_post_api/objects/label"
|
|
7
7
|
require_relative "nz_post_api/objects/shipping_option"
|
|
8
|
+
require_relative "nz_post_api/objects/parcel_track"
|
|
9
|
+
require_relative "nz_post_api/objects/parcel_track_subscription"
|
|
8
10
|
require_relative "nz_post_api/auth"
|
|
9
11
|
require_relative "nz_post_api/client"
|
|
10
12
|
require_relative "nz_post_api/resources/parcel_address"
|
|
11
13
|
require_relative "nz_post_api/resources/parcel_label"
|
|
12
14
|
require_relative "nz_post_api/resources/shipping_option"
|
|
15
|
+
require_relative "nz_post_api/resources/parcel_track"
|
|
13
16
|
|
|
14
17
|
module NzPostApi
|
|
15
18
|
class Error < StandardError; end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nz_post_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Chong
|
|
@@ -73,9 +73,12 @@ files:
|
|
|
73
73
|
- lib/nz_post_api/objects/address.rb
|
|
74
74
|
- lib/nz_post_api/objects/base.rb
|
|
75
75
|
- lib/nz_post_api/objects/label.rb
|
|
76
|
+
- lib/nz_post_api/objects/parcel_track.rb
|
|
77
|
+
- lib/nz_post_api/objects/parcel_track_subscription.rb
|
|
76
78
|
- lib/nz_post_api/objects/shipping_option.rb
|
|
77
79
|
- lib/nz_post_api/resources/parcel_address.rb
|
|
78
80
|
- lib/nz_post_api/resources/parcel_label.rb
|
|
81
|
+
- lib/nz_post_api/resources/parcel_track.rb
|
|
79
82
|
- lib/nz_post_api/resources/shipping_option.rb
|
|
80
83
|
- lib/nz_post_api/version.rb
|
|
81
84
|
- sig/nz_post_api.rbs
|