nz_post_api 0.3.0 → 0.4.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: fd7725f76d54c6a212beecd45f4ffc568ae7b0ab010d69ecf0f92d3dcbe57149
4
- data.tar.gz: 7298abe8f2dae29e17f9525839b405e5c88a6be22f9072021002cdc1e3a8c957
3
+ metadata.gz: db4c2d341925855b00d54c677d88820dfcb183e16bf3a92e12c284bbdc665f80
4
+ data.tar.gz: 6ffccabb911d0b5683984b45c75b5aea2392771452794c0572a65bae0fea8350
5
5
  SHA512:
6
- metadata.gz: 233660b133767bfc37a494719f344be5882d5d1093cbd92fc51b835e25481e0ba2d31ac4f5f4991622a9d3f3cae389350580e635bb99e35f55fdd4bce2efad9e
7
- data.tar.gz: '08319bcd20474c2bccbc4f69b14bb57ccbe648e9ef95c186b3bc719067259baa4e8e7bd8840acfdd62d79d7564d0283e986be1cafe1cb87eb3f3775892a85070'
6
+ metadata.gz: 4d66466023a5ae7a3d341218fe006cf25d022747bfc7dbf08be4a2026629982507cba8837b884609c68f1b11a3ca270484c13b50f4e43fb02e72683420ada83b
7
+ data.tar.gz: 2dac646484e52891d15da15f731625fb28a8fc1a389f54b2f3b66302f5f9b4f111fc8a5727a6ae516c90d51dba0c659944d67c3804a79290c4a4cec4e884a5b2
data/AGENTS.md CHANGED
@@ -15,6 +15,7 @@ This project is a Ruby gem wrapper for the NZ Post API.
15
15
  2. Implement the test case.
16
16
  3. Implement the code to pass the test.
17
17
  4. Refactor.
18
+ 5. **Documentation**: Update README.md if there are any changes to the public API or configuration.
18
19
 
19
20
  ## API Documentation
20
21
 
data/README.md CHANGED
@@ -37,6 +37,16 @@ Then, initialize the client with the access token.
37
37
  client = NzPostApi::Client.new(client_id: "YOUR_CLIENT_ID", access_token: access_token)
38
38
  ```
39
39
 
40
+ ### Configuration
41
+
42
+ By default, the gem uses the UAT environment. To use the production environment, configure the gem as follows:
43
+
44
+ ```ruby
45
+ NzPostApi.configure do |config|
46
+ config.prod = true # set to true for production, defaults to false (UAT)
47
+ end
48
+ ```
49
+
40
50
  ### Parcel Address
41
51
 
42
52
  #### Search
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NzPostApi
4
+ class Configuration
5
+ attr_accessor :prod
6
+
7
+ def initialize
8
+ @prod = false
9
+ end
10
+
11
+ def base_url
12
+ if @prod
13
+ "https://api.nzpost.co.nz"
14
+ else
15
+ "https://api.uat.nzpost.co.nz"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,14 +3,16 @@
3
3
  module NzPostApi
4
4
  module Resources
5
5
  class ParcelAddress
6
- BASE_URL = "https://api.uat.nzpost.co.nz/parceladdress/2.0/domestic/addresses"
6
+ def base_url
7
+ "#{NzPostApi.configuration.base_url}/parceladdress/2.0/domestic/addresses"
8
+ end
7
9
 
8
10
  def initialize(client)
9
11
  @client = client
10
12
  end
11
13
 
12
14
  def search(q:, count: 10)
13
- response = @client.connection.get(BASE_URL, { q: q, count: count })
15
+ response = @client.connection.get(base_url, { q: q, count: count })
14
16
 
15
17
  if response.success?
16
18
  response.body["addresses"].map { |addr| Objects::Address.new(addr) }
@@ -3,24 +3,26 @@
3
3
  module NzPostApi
4
4
  module Resources
5
5
  class ParcelLabel
6
- BASE_URL = "https://api.uat.nzpost.co.nz/parcellabel/v3/labels"
6
+ def base_url
7
+ "#{NzPostApi.configuration.base_url}/parcellabel/v3/labels"
8
+ end
7
9
 
8
10
  def initialize(client)
9
11
  @client = client
10
12
  end
11
13
 
12
14
  def create(payload)
13
- response = @client.connection.post(BASE_URL, payload)
15
+ response = @client.connection.post(base_url, payload)
14
16
  handle_response(response)
15
17
  end
16
18
 
17
19
  def status(consignment_id)
18
- response = @client.connection.get("#{BASE_URL}/#{consignment_id}/status")
20
+ response = @client.connection.get("#{base_url}/#{consignment_id}/status")
19
21
  handle_response(response)
20
22
  end
21
23
 
22
24
  def download(consignment_id, format: "PDF")
23
- response = @client.connection.get("#{BASE_URL}/#{consignment_id}", { format: format })
25
+ response = @client.connection.get("#{base_url}/#{consignment_id}", { format: format })
24
26
  if response.success?
25
27
  response.body
26
28
  else
@@ -3,14 +3,16 @@
3
3
  module NzPostApi
4
4
  module Resources
5
5
  class ParcelTrack
6
- BASE_URL = "https://api.uat.nzpost.co.nz/parceltrack/3.0/parcels"
6
+ def base_url
7
+ "#{NzPostApi.configuration.base_url}/parceltrack/3.0/parcels"
8
+ end
7
9
 
8
10
  def initialize(client)
9
11
  @client = client
10
12
  end
11
13
 
12
14
  def track(tracking_reference)
13
- response = @client.connection.get("#{BASE_URL}/#{tracking_reference}")
15
+ response = @client.connection.get("#{base_url}/#{tracking_reference}")
14
16
 
15
17
  if response.success?
16
18
  Objects::ParcelTrack.new(response.body["results"])
@@ -24,7 +26,7 @@ module NzPostApi
24
26
  tracking_reference: tracking_reference,
25
27
  notification_endpoint: notification_endpoint
26
28
  }
27
- response = @client.connection.post("#{BASE_URL.sub('parcels', 'subscription/webhook/')}", payload)
29
+ response = @client.connection.post("#{base_url.sub('parcels', 'subscription/webhook/')}", payload)
28
30
 
29
31
  if response.success?
30
32
  Objects::ParcelTrackSubscription.new(response.body)
@@ -34,7 +36,7 @@ module NzPostApi
34
36
  end
35
37
 
36
38
  def unsubscribe(subscription_guid:)
37
- response = @client.connection.delete("#{BASE_URL.sub('parcels', 'subscription/webhook')}/#{subscription_guid}")
39
+ response = @client.connection.delete("#{base_url.sub('parcels', 'subscription/webhook')}/#{subscription_guid}")
38
40
 
39
41
  if response.success?
40
42
  true
@@ -3,14 +3,16 @@
3
3
  module NzPostApi
4
4
  module Resources
5
5
  class ShippingOption
6
- BASE_URL = "https://api.uat.nzpost.co.nz/shippingoptions/2.0/domestic"
6
+ def base_url
7
+ "#{NzPostApi.configuration.base_url}/shippingoptions/2.0/domestic"
8
+ end
7
9
 
8
10
  def initialize(client)
9
11
  @client = client
10
12
  end
11
13
 
12
14
  def list(params = {})
13
- response = @client.connection.get(BASE_URL, params)
15
+ response = @client.connection.get(base_url, params)
14
16
 
15
17
  if response.success?
16
18
  Objects::ShippingOption.new(response.body)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NzPostApi
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/nz_post_api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "nz_post_api/version"
4
+ require_relative "nz_post_api/configuration"
4
5
  require_relative "nz_post_api/objects/base"
5
6
  require_relative "nz_post_api/objects/address"
6
7
  require_relative "nz_post_api/objects/label"
@@ -16,5 +17,14 @@ require_relative "nz_post_api/resources/parcel_track"
16
17
 
17
18
  module NzPostApi
18
19
  class Error < StandardError; end
19
- # Your code goes here...
20
+
21
+ class << self
22
+ def configuration
23
+ @configuration ||= Configuration.new
24
+ end
25
+
26
+ def configure
27
+ yield(configuration)
28
+ end
29
+ end
20
30
  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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
@@ -70,6 +70,7 @@ 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
73
74
  - lib/nz_post_api/objects/address.rb
74
75
  - lib/nz_post_api/objects/base.rb
75
76
  - lib/nz_post_api/objects/label.rb