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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8ec46eab576b5d457acc5ba5476a9b31140871f1a67018946abe82e72e6bd6e
4
- data.tar.gz: e21a327af35cebc7933043c19546a7496b7ff079f07166e24d790a0320d0112c
3
+ metadata.gz: 79fc7d9823bc2ee076dd26982aad65e2ec9cd2354403ffd0afd6414f0a1b9f49
4
+ data.tar.gz: 22a970d9bba8db00bf083b2a586d024a1e8905c8430af12218bfce287926ebb1
5
5
  SHA512:
6
- metadata.gz: 34298ff6a6da402e7eeb864b725d536ff1379db1105e7fc97d8a39e0de961775ff0fa6ab99202cee7a5fa834e5af57025987ccfcb712d05230937bfb7c50be5f
7
- data.tar.gz: c28df5d11dee6594d65da67e00261b972c1bdf87d73d4ecae3d033f6791929fbc13db0d536eb42bf5c3c7683fba2c4fd34c4b97c1f707d8e8a3be43175f6911b
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, configure the gem and initialize the client.
34
+ Then, initialize the client with your credentials:
35
35
 
36
36
  ```ruby
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
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
- ### Configuration
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 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)
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
- ```
@@ -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 client_id
11
- NzPostApi.configuration.client_id
12
- end
13
-
14
- def access_token
15
- NzPostApi.configuration.access_token
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
@@ -4,7 +4,7 @@ module NzPostApi
4
4
  module Resources
5
5
  class ParcelAddress
6
6
  def base_url
7
- "#{NzPostApi.configuration.base_url}/parceladdress/2.0/domestic/addresses"
7
+ "#{@client.base_url}/parceladdress/2.0/domestic/addresses"
8
8
  end
9
9
 
10
10
  def initialize(client)
@@ -4,7 +4,7 @@ module NzPostApi
4
4
  module Resources
5
5
  class ParcelLabel
6
6
  def base_url
7
- "#{NzPostApi.configuration.base_url}/parcellabel/v3/labels"
7
+ "#{@client.base_url}/parcellabel/v3/labels"
8
8
  end
9
9
 
10
10
  def initialize(client)
@@ -4,7 +4,7 @@ module NzPostApi
4
4
  module Resources
5
5
  class ParcelTrack
6
6
  def base_url
7
- "#{NzPostApi.configuration.base_url}/parceltrack/3.0/parcels"
7
+ "#{@client.base_url}/parceltrack/3.0/parcels"
8
8
  end
9
9
 
10
10
  def initialize(client)
@@ -4,7 +4,7 @@ module NzPostApi
4
4
  module Resources
5
5
  class ShippingOption
6
6
  def base_url
7
- "#{NzPostApi.configuration.base_url}/shippingoptions/2.0/domestic"
7
+ "#{@client.base_url}/shippingoptions/2.0/domestic"
8
8
  end
9
9
 
10
10
  def initialize(client)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NzPostApi
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
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.5.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-03 00:00:00.000000000 Z
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