ninja_van_api 0.2.19 → 0.3.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: e99318275edf40b8bb4577ba8cf3fdcfe12f74c890ec8b19c7b1fdab0e5d9a39
4
- data.tar.gz: c3a1ca3eae3aa687bdc7e825ebf5351fba4fdc73f3b7f9239e6200def042f2b3
3
+ metadata.gz: 5e6a9d85bc63b39d39466165b3f1e624a5afb3bf208e60483f17538b471399ea
4
+ data.tar.gz: 4edfbb6bbe5ea7eabe620e7b4377668a0b253c42a511f9a1e90673a2afb3cf17
5
5
  SHA512:
6
- metadata.gz: 46058f70e565a6ceb2c4346e094f275d4f9b63f3ab8d965b8515e4ceb2bb6190a25ef4b31af89735fff9b22d34d4bfe7c572d386fa91e1639c05fe2768b52f30
7
- data.tar.gz: 245cab12372c1ca615167487feef6088107c5355099adc61b6574af38b533117b9c97ed1827f419596dec704b268f9856d540db11f160a06b50162f9db5e4968
6
+ metadata.gz: e4767540c46c7e8947f184ee6d42cd54c661a51a70b34480506c982f1072cbac189fdd4b669225f3c0776f436a883b91302d58e51a4761a95fa123a8133d5db0
7
+ data.tar.gz: 6138eecf473a4a40bb03bf510d0db2abd24efe559e474d95eec26f468fc321c29adcbe37e7523e3b7cce0f9f192f624896bf8295f9afeaab7a08783571b1924e
@@ -5,7 +5,14 @@ module NinjaVanApi
5
5
 
6
6
  def create
7
7
  if NinjaVanApi.configuration.webhook_job_class
8
- NinjaVanApi.configuration.webhook_job_class.perform_later(webhook_params.to_h)
8
+ klass =
9
+ begin
10
+ job_class.constantize
11
+ rescue NameError
12
+ raise ArgumentError,
13
+ "webhook_job_class must be an ActiveJob class name or class that responds to perform_later"
14
+ end
15
+ klass.perform_later(webhook_params.to_h)
9
16
  head :ok
10
17
  else
11
18
  head :unprocessable_entity
@@ -38,6 +38,10 @@ module NinjaVanApi
38
38
  @orders ||= OrderResource.new(self)
39
39
  end
40
40
 
41
+ def waybills
42
+ @waybills ||= WaybillResource.new(self)
43
+ end
44
+
41
45
  private
42
46
 
43
47
  def validate_country_code
@@ -55,7 +59,7 @@ module NinjaVanApi
55
59
  def access_token
56
60
  fetch_access_token if token_expired?
57
61
 
58
- if defined?(Rails) && Rails.respond_to?(:cache)
62
+ if defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache
59
63
  Rails.cache.read(cache_key)["access_token"]
60
64
  else
61
65
  @token_info["access_token"]
@@ -64,7 +68,7 @@ module NinjaVanApi
64
68
 
65
69
  def refresh_access_token
66
70
  @token_info = nil
67
- Rails.cache.delete(cache_key) if defined?(Rails) && Rails.respond_to?(:cache)
71
+ Rails.cache.delete(cache_key) if defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache
68
72
  fetch_access_token
69
73
  end
70
74
 
@@ -99,7 +103,7 @@ module NinjaVanApi
99
103
  def access_token
100
104
  fetch_access_token if token_expired?
101
105
 
102
- if defined?(Rails) && Rails.respond_to?(:cache)
106
+ if defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache
103
107
  Rails.cache.read(cache_key)["access_token"]
104
108
  else
105
109
  @token_info["access_token"]
@@ -108,7 +112,7 @@ module NinjaVanApi
108
112
 
109
113
  def token_expired?
110
114
  token_info =
111
- if defined?(Rails) && Rails.respond_to?(:cache)
115
+ if defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache
112
116
  Rails.cache.read(cache_key)
113
117
  else
114
118
  @token_info
@@ -125,7 +129,7 @@ module NinjaVanApi
125
129
 
126
130
  token_info = JSON.parse(response.body)
127
131
 
128
- if defined?(Rails) && Rails.respond_to?(:cache)
132
+ if defined?(Rails) && Rails.respond_to?(:cache) && Rails.cache
129
133
  Rails.cache.write(cache_key, token_info, expires_in: token_info["expires_in"])
130
134
  else
131
135
  @token_info = token_info
@@ -6,7 +6,8 @@
6
6
  #
7
7
  module NinjaVanApi
8
8
  class Configuration
9
- attr_reader :webhook_secrets, :webhook_job_class
9
+ attr_reader :webhook_secrets
10
+ attr_accessor :webhook_job_class
10
11
 
11
12
  def webhook_secrets=(secrets)
12
13
  @webhook_secrets = secrets.transform_keys(&:downcase)
@@ -15,20 +16,6 @@ module NinjaVanApi
15
16
  def get_webhook_secret(country_code)
16
17
  @webhook_secrets[country_code.to_s.downcase]
17
18
  end
18
-
19
- def webhook_job_class=(job_class)
20
- return @webhook_job_class = nil if job_class.nil?
21
-
22
- begin
23
- klass = job_class.is_a?(String) ? job_class.constantize : job_class
24
- rescue NameError
25
- raise ArgumentError, "webhook_job_class must be an ActiveJob class name or class that responds to perform_later"
26
- end
27
- unless klass.is_a?(Class) && klass.respond_to?(:perform_later)
28
- raise ArgumentError, "webhook_job_class must be an ActiveJob class name or class that responds to perform_later"
29
- end
30
- @webhook_job_class = klass
31
- end
32
19
  end
33
20
 
34
21
  class << self
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NinjaVanApi
4
+ class Waybill < Base
5
+ attr_reader :pdf
6
+
7
+ def initialize(content)
8
+ @pdf = content
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NinjaVanApi
4
+ class WaybillResource < BaseResource
5
+ # Retrieves a waybill for a given tracking number
6
+ # @param tracking_number [String] The tracking number as generated by the Order API
7
+ # @param hide_shipper_details [Boolean] A flag for hiding shipper's details
8
+ # @param orientation [String] Specifies the orientation of the generated waybill ("portrait" or "landscape")
9
+ # @return [Waybill] The waybill object
10
+ def get(tracking_number, hide_shipper_details: nil, orientation: nil)
11
+ params = { tid: tracking_number }
12
+ params[:hide_shipper_details] = hide_shipper_details unless hide_shipper_details.nil?
13
+ params[:orientation] = orientation if orientation
14
+
15
+ response = get_request("2.0/reports/waybill", params: params)
16
+ Waybill.new(response.body)
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NinjaVanApi
4
- VERSION = "0.2.19"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/ninja_van_api.rb CHANGED
@@ -14,10 +14,12 @@ module NinjaVanApi
14
14
  # Objects
15
15
  autoload :Base, "ninja_van_api/objects/base"
16
16
  autoload :Order, "ninja_van_api/objects/order"
17
+ autoload :Waybill, "ninja_van_api/objects/waybill"
17
18
 
18
19
  # Resources
19
20
  autoload :BaseResource, "ninja_van_api/resources/base_resource"
20
21
  autoload :OrderResource, "ninja_van_api/resources/order_resource"
22
+ autoload :WaybillResource, "ninja_van_api/resources/waybill_resource"
21
23
 
22
24
  # Core components
23
25
  autoload :Client, "ninja_van_api/client"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninja_van_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jane Trang Mai Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-27 00:00:00.000000000 Z
11
+ date: 2025-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -144,8 +144,10 @@ files:
144
144
  - lib/ninja_van_api/error.rb
145
145
  - lib/ninja_van_api/objects/base.rb
146
146
  - lib/ninja_van_api/objects/order.rb
147
+ - lib/ninja_van_api/objects/waybill.rb
147
148
  - lib/ninja_van_api/resources/base_resource.rb
148
149
  - lib/ninja_van_api/resources/order_resource.rb
150
+ - lib/ninja_van_api/resources/waybill_resource.rb
149
151
  - lib/ninja_van_api/version.rb
150
152
  homepage: https://github.com/Postco/ninja_van_api
151
153
  licenses: