ninja_van_api 0.3.0 → 0.3.2

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: 5e6a9d85bc63b39d39466165b3f1e624a5afb3bf208e60483f17538b471399ea
4
- data.tar.gz: 4edfbb6bbe5ea7eabe620e7b4377668a0b253c42a511f9a1e90673a2afb3cf17
3
+ metadata.gz: 3c0500f6e4ff9f487125e31177607ea5540d449090baaf969074343652c3f685
4
+ data.tar.gz: 0d4df61f525236b14a729e2e28cd10a5bdfc05774c0e86db5a0c19226048739b
5
5
  SHA512:
6
- metadata.gz: e4767540c46c7e8947f184ee6d42cd54c661a51a70b34480506c982f1072cbac189fdd4b669225f3c0776f436a883b91302d58e51a4761a95fa123a8133d5db0
7
- data.tar.gz: 6138eecf473a4a40bb03bf510d0db2abd24efe559e474d95eec26f468fc321c29adcbe37e7523e3b7cce0f9f192f624896bf8295f9afeaab7a08783571b1924e
6
+ metadata.gz: 75d348ca0a519c74708855d372cb96a117caa233026eda42c6cb6a8c97051315de8dbc3f51d1fb86f96b12504b7fa48ceb59255f0ca6c4927b074ceb6aff0f95
7
+ data.tar.gz: cd320d7a2d2dc7c8bf7b4452f83c23ceebd26fae8f82cf8cb7fa9b7dfa8a0fb92930667a52f02ec2e9cfe5697f7228c70734db922ec35adf4a4c065e3ed49e84
data/README.md CHANGED
@@ -16,6 +16,38 @@ And then execute:
16
16
 
17
17
  ## Usage
18
18
 
19
+ ### Retrieving Waybills
20
+
21
+ ```ruby
22
+ # Initialize the client
23
+ client = NinjaVanApi::Client.new(
24
+ client_id: "your_client_id",
25
+ client_secret: "your_client_secret",
26
+ country_code: "SG",
27
+ test_mode: true
28
+ )
29
+
30
+ # Basic waybill retrieval
31
+ waybill = client.waybills.get("TRACKING123")
32
+
33
+ # Get waybill with optional parameters
34
+ waybill = client.waybills.get(
35
+ "TRACKING123",
36
+ hide_shipper_details: true, # Hide shipper's details in the waybill
37
+ orientation: "landscape" # Set waybill orientation to landscape
38
+ )
39
+
40
+ # Access the PDF content
41
+ pdf_content = waybill.pdf
42
+
43
+ # Error handling
44
+ begin
45
+ waybill = client.waybills.get("INVALID_TRACKING")
46
+ rescue NinjaVanApi::Error => e
47
+ puts "Error retrieving waybill: #{e.message}"
48
+ end
49
+ ```
50
+
19
51
  ### Mounting the Engine
20
52
 
21
53
  In your Rails application's `config/routes.rb`, mount the webhook engine. You can mount it multiple times with different country paths. For example:
@@ -7,11 +7,12 @@ module NinjaVanApi
7
7
  if NinjaVanApi.configuration.webhook_job_class
8
8
  klass =
9
9
  begin
10
- job_class.constantize
10
+ NinjaVanApi.configuration.webhook_job_class.constantize
11
11
  rescue NameError
12
12
  raise ArgumentError,
13
13
  "webhook_job_class must be an ActiveJob class name or class that responds to perform_later"
14
14
  end
15
+
15
16
  klass.perform_later(webhook_params.to_h)
16
17
  head :ok
17
18
  else
@@ -27,8 +28,8 @@ module NinjaVanApi
27
28
 
28
29
  def verify_webhook_signature
29
30
  # Extract country code from the request path
30
- # Example: /ninjavan/sg/webhooks -> 'sg'
31
- country_code = request.path.split("/")[2]&.downcase
31
+ # Example: /sg -> 'sg'
32
+ country_code = request.path.split("/")[-1]&.downcase
32
33
  return head :unauthorized unless country_code.present?
33
34
 
34
35
  webhook_secret = NinjaVanApi.configuration.get_webhook_secret(country_code)
@@ -86,17 +86,6 @@ module NinjaVanApi
86
86
  }.to_json
87
87
  end
88
88
 
89
- raise NinjaVanApi::AuthenticationError, response.body unless response.success?
90
-
91
- JSON.parse(response.body)["access_token"]
92
-
93
- response =
94
- Faraday.post(endpoint) do |req|
95
- req.headers["Content-Type"] = "application/json"
96
- req.headers["Accept"] = "application/json"
97
- req.body = { client_id: @client_id, client_secret: @client_secret, grant_type: "client_credentials" }.to_json
98
- end
99
-
100
89
  handle_access_token_response(response)
101
90
  end
102
91
 
@@ -10,11 +10,11 @@ module NinjaVanApi
10
10
  attr_accessor :webhook_job_class
11
11
 
12
12
  def webhook_secrets=(secrets)
13
- @webhook_secrets = secrets.transform_keys(&:downcase)
13
+ @webhook_secrets = secrets.transform_keys { |key| key.to_sym.downcase }
14
14
  end
15
15
 
16
16
  def get_webhook_secret(country_code)
17
- @webhook_secrets[country_code.to_s.downcase]
17
+ @webhook_secrets[country_code.to_sym.downcase]
18
18
  end
19
19
  end
20
20
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NinjaVanApi
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninja_van_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jane Trang Mai Nguyen