nz_post_api 0.5.0 → 0.6.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 +10 -18
- data/lib/nz_post_api/client.rb +12 -9
- data/lib/nz_post_api/resources/parcel_address.rb +1 -1
- data/lib/nz_post_api/resources/parcel_label.rb +1 -1
- data/lib/nz_post_api/resources/parcel_track.rb +1 -1
- data/lib/nz_post_api/resources/shipping_option.rb +1 -1
- data/lib/nz_post_api/version.rb +1 -1
- data/lib/nz_post_api.rb +0 -11
- metadata +2 -3
- data/lib/nz_post_api/configuration.rb +0 -21
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79fc7d9823bc2ee076dd26982aad65e2ec9cd2354403ffd0afd6414f0a1b9f49
|
|
4
|
+
data.tar.gz: 22a970d9bba8db00bf083b2a586d024a1e8905c8430af12218bfce287926ebb1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6f21391ee069bcb2e08742f2b7c4e6aec58703063c5ed76c0e3bded858e6d4f6fa6180bafbaeb45178661997c826fcb8af40520532713f5e7d30c5e13acde78
|
|
7
|
+
data.tar.gz: f5c356b9498efcacfdc383b2f9333c936cfea3a1603cd724b3dccb812ae50c39176e18d847fc8e82f4c1b0b98e02590b1e68a8ba2fd434ddaa538b0c8ccd3cee
|
data/README.md
CHANGED
|
@@ -31,25 +31,21 @@ 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, initialize the client with your credentials:
|
|
35
35
|
|
|
36
36
|
```ruby
|
|
37
|
-
NzPostApi.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
client = NzPostApi::Client.new
|
|
37
|
+
client = NzPostApi::Client.new(
|
|
38
|
+
"YOUR_CLIENT_ID",
|
|
39
|
+
access_token,
|
|
40
|
+
prod: true # set to true for production, false for UAT (default)
|
|
41
|
+
)
|
|
44
42
|
```
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
By default, the gem uses the UAT environment. Configuration options:
|
|
44
|
+
**Client constructor:**
|
|
49
45
|
|
|
50
|
-
- `client_id` – Your NZ Post API client ID (required
|
|
51
|
-
- `access_token` – Bearer token from `NzPostApi::Auth.fetch_token` (required
|
|
52
|
-
- `prod
|
|
46
|
+
- `client_id` – Your NZ Post API client ID (required)
|
|
47
|
+
- `access_token` – Bearer token from `NzPostApi::Auth.fetch_token` (required)
|
|
48
|
+
- `prod:` – Set to `true` for production (`https://api.nzpost.co.nz`), `false` for UAT (`https://api.uat.nzpost.co.nz`). Defaults to `false`.
|
|
53
49
|
|
|
54
50
|
### Parcel Address
|
|
55
51
|
|
|
@@ -267,7 +263,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
267
263
|
## Code of Conduct
|
|
268
264
|
|
|
269
265
|
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).
|
|
270
|
-
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
```
|
data/lib/nz_post_api/client.rb
CHANGED
|
@@ -4,23 +4,26 @@ require "faraday"
|
|
|
4
4
|
|
|
5
5
|
module NzPostApi
|
|
6
6
|
class Client
|
|
7
|
-
def initialize
|
|
7
|
+
def initialize(client_id, access_token, prod: false)
|
|
8
|
+
@client_id = client_id
|
|
9
|
+
@access_token = access_token
|
|
10
|
+
@prod = prod
|
|
8
11
|
end
|
|
9
12
|
|
|
10
|
-
def
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
def base_url
|
|
14
|
+
if @prod
|
|
15
|
+
"https://api.nzpost.co.nz"
|
|
16
|
+
else
|
|
17
|
+
"https://api.uat.nzpost.co.nz"
|
|
18
|
+
end
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def connection
|
|
19
22
|
@connection ||= Faraday.new do |f|
|
|
20
23
|
f.request :json
|
|
21
24
|
f.response :json
|
|
22
|
-
f.headers["client_id"] = client_id
|
|
23
|
-
f.headers["Authorization"] = "Bearer #{access_token}"
|
|
25
|
+
f.headers["client_id"] = @client_id
|
|
26
|
+
f.headers["Authorization"] = "Bearer #{@access_token}"
|
|
24
27
|
f.headers["Content-Type"] = "application/json"
|
|
25
28
|
end
|
|
26
29
|
end
|
data/lib/nz_post_api/version.rb
CHANGED
data/lib/nz_post_api.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "nz_post_api/version"
|
|
4
|
-
require_relative "nz_post_api/configuration"
|
|
5
4
|
require_relative "nz_post_api/objects/base"
|
|
6
5
|
require_relative "nz_post_api/objects/address"
|
|
7
6
|
require_relative "nz_post_api/objects/label"
|
|
@@ -17,14 +16,4 @@ require_relative "nz_post_api/resources/parcel_track"
|
|
|
17
16
|
|
|
18
17
|
module NzPostApi
|
|
19
18
|
class Error < StandardError; end
|
|
20
|
-
|
|
21
|
-
class << self
|
|
22
|
-
def configuration
|
|
23
|
-
@configuration ||= Configuration.new
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def configure
|
|
27
|
-
yield(configuration)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
19
|
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.
|
|
4
|
+
version: 0.6.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-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -70,7 +70,6 @@ files:
|
|
|
70
70
|
- lib/nz_post_api.rb
|
|
71
71
|
- lib/nz_post_api/auth.rb
|
|
72
72
|
- lib/nz_post_api/client.rb
|
|
73
|
-
- lib/nz_post_api/configuration.rb
|
|
74
73
|
- lib/nz_post_api/objects/address.rb
|
|
75
74
|
- lib/nz_post_api/objects/base.rb
|
|
76
75
|
- lib/nz_post_api/objects/label.rb
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module NzPostApi
|
|
4
|
-
class Configuration
|
|
5
|
-
attr_accessor :prod, :client_id, :access_token
|
|
6
|
-
|
|
7
|
-
def initialize
|
|
8
|
-
@prod = false
|
|
9
|
-
@client_id = nil
|
|
10
|
-
@access_token = nil
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def base_url
|
|
14
|
-
if @prod
|
|
15
|
-
"https://api.nzpost.co.nz"
|
|
16
|
-
else
|
|
17
|
-
"https://api.uat.nzpost.co.nz"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|