nz_post_api 0.4.0 → 0.5.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 +16 -8
- data/lib/nz_post_api/auth.rb +5 -2
- data/lib/nz_post_api/client.rb +8 -4
- data/lib/nz_post_api/configuration.rb +3 -1
- data/lib/nz_post_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8ec46eab576b5d457acc5ba5476a9b31140871f1a67018946abe82e72e6bd6e
|
|
4
|
+
data.tar.gz: e21a327af35cebc7933043c19546a7496b7ff079f07166e24d790a0320d0112c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34298ff6a6da402e7eeb864b725d536ff1379db1105e7fc97d8a39e0de961775ff0fa6ab99202cee7a5fa834e5af57025987ccfcb712d05230937bfb7c50be5f
|
|
7
|
+
data.tar.gz: c28df5d11dee6594d65da67e00261b972c1bdf87d73d4ecae3d033f6791929fbc13db0d536eb42bf5c3c7683fba2c4fd34c4b97c1f707d8e8a3be43175f6911b
|
data/README.md
CHANGED
|
@@ -31,21 +31,25 @@ expires_in = token_response["expires_in"]
|
|
|
31
31
|
> [!IMPORTANT]
|
|
32
32
|
> The access token expires after a certain period (indicated by `expires_in`). It is highly recommended to cache the `access_token` and reuse it until it expires to avoid unnecessary API calls and potential rate limiting.
|
|
33
33
|
|
|
34
|
-
Then,
|
|
34
|
+
Then, configure the gem and initialize the client.
|
|
35
35
|
|
|
36
36
|
```ruby
|
|
37
|
-
|
|
37
|
+
NzPostApi.configure do |config|
|
|
38
|
+
config.client_id = "YOUR_CLIENT_ID"
|
|
39
|
+
config.access_token = access_token
|
|
40
|
+
config.prod = true # set to true for production, defaults to false (UAT)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
client = NzPostApi::Client.new
|
|
38
44
|
```
|
|
39
45
|
|
|
40
46
|
### Configuration
|
|
41
47
|
|
|
42
|
-
By default, the gem uses the UAT environment.
|
|
48
|
+
By default, the gem uses the UAT environment. Configuration options:
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
NzPostApi.
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
```
|
|
50
|
+
- `client_id` – Your NZ Post API client ID (required for API calls)
|
|
51
|
+
- `access_token` – Bearer token from `NzPostApi::Auth.fetch_token` (required for API calls)
|
|
52
|
+
- `prod` – Set to `true` for production, `false` for UAT (default)
|
|
49
53
|
|
|
50
54
|
### Parcel Address
|
|
51
55
|
|
|
@@ -69,6 +73,10 @@ end
|
|
|
69
73
|
|
|
70
74
|
Create a new parcel label.
|
|
71
75
|
|
|
76
|
+
- **NZ Post rates**: To use your own NZ Post rates, include `account_number` and `site_code` in the payload.
|
|
77
|
+
- **Notification endpoint**: The `notification_endpoint` is a webhook URL. NZ Post will send HTTP requests to this endpoint when the parcel label status is updated.
|
|
78
|
+
- **Service codes** (in `parcel_details`): `CPOLP` is Overnight Returns (supports pickup); `EROLE` is Economy Returns (only drop off, the pickup address street must have the prefix "PO Box" or "Private Bag" followed by digits).
|
|
79
|
+
|
|
72
80
|
```ruby
|
|
73
81
|
label_client = client.parcel_label
|
|
74
82
|
|
data/lib/nz_post_api/auth.rb
CHANGED
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
require "faraday"
|
|
4
4
|
require "json"
|
|
5
|
+
require "uri"
|
|
5
6
|
|
|
6
7
|
module NzPostApi
|
|
7
8
|
class Auth
|
|
8
9
|
TOKEN_URL = "https://oauth.nzpost.co.nz/as/token.oauth2"
|
|
9
10
|
|
|
10
11
|
def self.fetch_token(client_id, client_secret)
|
|
11
|
-
|
|
12
|
+
params = {
|
|
12
13
|
client_id: client_id,
|
|
13
14
|
client_secret: client_secret,
|
|
14
15
|
grant_type: "client_credentials"
|
|
15
|
-
}
|
|
16
|
+
}
|
|
17
|
+
url_with_params = "#{TOKEN_URL}?#{URI.encode_www_form(params)}"
|
|
18
|
+
response = Faraday.post(url_with_params, nil)
|
|
16
19
|
|
|
17
20
|
if response.success?
|
|
18
21
|
JSON.parse(response.body)
|
data/lib/nz_post_api/client.rb
CHANGED
|
@@ -4,11 +4,15 @@ require "faraday"
|
|
|
4
4
|
|
|
5
5
|
module NzPostApi
|
|
6
6
|
class Client
|
|
7
|
-
|
|
7
|
+
def initialize
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def client_id
|
|
11
|
+
NzPostApi.configuration.client_id
|
|
12
|
+
end
|
|
8
13
|
|
|
9
|
-
def
|
|
10
|
-
|
|
11
|
-
@access_token = access_token
|
|
14
|
+
def access_token
|
|
15
|
+
NzPostApi.configuration.access_token
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
def connection
|
data/lib/nz_post_api/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.5.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-
|
|
11
|
+
date: 2026-02-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|