ninja_van_api 0.2.15 → 0.2.17
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 +6 -6
- data/app/controllers/ninja_van_api/webhooks_controller.rb +4 -4
- data/config/routes.rb +2 -2
- data/lib/ninja_van_api/client.rb +5 -5
- data/lib/ninja_van_api/configuration.rb +3 -3
- data/lib/ninja_van_api/error.rb +7 -4
- data/lib/ninja_van_api/objects/base.rb +1 -1
- data/lib/ninja_van_api/objects/order.rb +1 -1
- data/lib/ninja_van_api/resources/base_resource.rb +1 -1
- data/lib/ninja_van_api/resources/order_resource.rb +1 -1
- data/lib/ninja_van_api/version.rb +2 -2
- data/lib/ninja_van_api.rb +2 -10
- metadata +1 -2
- data/sig/ninja_van_api.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f61d7ee64789b5bce77c5b77d9629d107f01313bbaf98f0d5952db30df56e04c
|
4
|
+
data.tar.gz: 8991713182b2cca84124761cf63d7c9033dfc8f5a8caa56da428e186958db2d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eae8b56e95d08a71fda05be20339f0a654bf0799465dc964a889544584d0b978628dad98c826cd86271f8ccec78d685bc5d37ff56b648f2395ba5744c156873b
|
7
|
+
data.tar.gz: 3b5327db2277c16ae352247b06e782e15348efbe363652a519932df4ed30d5cadc8a5960aa1210d0589131a38d7feaa56d182ce7b9c5f897da3b8bf7bac389dc
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# NinjaVanApi
|
2
2
|
|
3
3
|
A Ruby gem for integrating with NinjaVan's API and handling webhooks in Rails applications.
|
4
4
|
|
@@ -23,9 +23,9 @@ In your Rails application's `config/routes.rb`, mount the webhook engine. You ca
|
|
23
23
|
```ruby
|
24
24
|
Rails.application.routes.draw do
|
25
25
|
# Mount multiple endpoints for different countries
|
26
|
-
mount
|
27
|
-
mount
|
28
|
-
mount
|
26
|
+
mount NinjaVanApi::Engine => '/ninja_van/my'
|
27
|
+
mount NinjaVanApi::Engine => '/ninja_van/sg'
|
28
|
+
mount NinjaVanApi::Engine => '/ninja_van/id'
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
@@ -34,7 +34,7 @@ end
|
|
34
34
|
Create an initializer in `config/initializers/ninja_van_api.rb`. When configuring webhook secrets, you'll need to provide a hash where each key is a country code that corresponds to your mounting paths:
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
|
37
|
+
NinjaVanApi.configure do |config|
|
38
38
|
# Set your webhook job class to process incoming webhooks
|
39
39
|
config.webhook_job_class = "NinjaVanWebhookJob"
|
40
40
|
|
@@ -56,7 +56,7 @@ Note: The country code from your mounting path (e.g., '/ninja_van/my' uses 'MY')
|
|
56
56
|
First, initialize the NinjaVan API client:
|
57
57
|
|
58
58
|
```ruby
|
59
|
-
client =
|
59
|
+
client = NinjaVanApi::Client.new(
|
60
60
|
client_id: 'your-client-id',
|
61
61
|
client_secret: 'your-client-secret',
|
62
62
|
test_mode: false # Set to true for sandbox environment
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module NinjaVanApi
|
2
2
|
class WebhooksController < ActionController::Base
|
3
3
|
protect_from_forgery with: :null_session
|
4
4
|
before_action :verify_webhook_signature
|
5
5
|
|
6
6
|
def create
|
7
|
-
if
|
8
|
-
|
7
|
+
if NinjaVanApi.configuration.webhook_job_class
|
8
|
+
NinjaVanApi.configuration.webhook_job_class.perform_later(webhook_params.to_h)
|
9
9
|
head :ok
|
10
10
|
else
|
11
11
|
head :unprocessable_entity
|
@@ -24,7 +24,7 @@ module NinjaVanAPI
|
|
24
24
|
country_code = request.path.split("/")[2]&.downcase
|
25
25
|
return head :unauthorized unless country_code.present?
|
26
26
|
|
27
|
-
webhook_secret =
|
27
|
+
webhook_secret = NinjaVanApi.configuration.get_webhook_secret(country_code)
|
28
28
|
return head :unauthorized unless webhook_secret
|
29
29
|
|
30
30
|
signature = request.headers["X-Ninjavan-Hmac-Sha256"]
|
data/config/routes.rb
CHANGED
data/lib/ninja_van_api/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "faraday"
|
2
2
|
require "faraday/net_http"
|
3
3
|
|
4
|
-
module
|
4
|
+
module NinjaVanApi
|
5
5
|
class Client
|
6
6
|
BASE_URL = "https://api.ninjavan.co".freeze
|
7
7
|
SANDBOX_BASE_URL = "https://api-sandbox.ninjavan.co".freeze
|
@@ -43,11 +43,11 @@ module NinjaVanAPI
|
|
43
43
|
def validate_country_code
|
44
44
|
if test_mode
|
45
45
|
if country_code != "SG"
|
46
|
-
raise
|
46
|
+
raise NinjaVanApi::UnsupportedCountryCodeError, "#{country_code} is not supported on test mode"
|
47
47
|
end
|
48
48
|
else
|
49
49
|
unless SUPPORTED_COUNTRY_CODES.include? country_code
|
50
|
-
raise
|
50
|
+
raise NinjaVanApi::UnsupportedCountryCodeError, "#{country_code} is not supported"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -82,7 +82,7 @@ module NinjaVanAPI
|
|
82
82
|
}.to_json
|
83
83
|
end
|
84
84
|
|
85
|
-
raise
|
85
|
+
raise NinjaVanApi::AuthenticationError, response.body unless response.success?
|
86
86
|
|
87
87
|
JSON.parse(response.body)["access_token"]
|
88
88
|
|
@@ -121,7 +121,7 @@ module NinjaVanAPI
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def handle_access_token_response(response)
|
124
|
-
raise
|
124
|
+
raise NinjaVanApi::AuthenticationError unless response.success?
|
125
125
|
|
126
126
|
token_info = JSON.parse(response.body)
|
127
127
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# NinjaVanApi.configure do |config|
|
3
3
|
# config.webhook_job_class = MyWebhookJob
|
4
4
|
# config.webhook_secret = 'your-webhook-secret'
|
5
5
|
# end
|
6
6
|
#
|
7
|
-
module
|
7
|
+
module NinjaVanApi
|
8
8
|
class Configuration
|
9
9
|
attr_accessor :webhook_job_class
|
10
10
|
attr_reader :webhook_secrets
|
@@ -27,7 +27,7 @@ module NinjaVanAPI
|
|
27
27
|
|
28
28
|
klass = job_class.is_a?(String) ? job_class.constantize : job_class
|
29
29
|
unless klass.is_a?(Class) && klass.respond_to?(:perform_later)
|
30
|
-
raise ArgumentError,
|
30
|
+
raise ArgumentError, "webhook_job_class must be an ActiveJob class name or class that responds to perform_later"
|
31
31
|
end
|
32
32
|
@webhook_job_class = klass
|
33
33
|
end
|
data/lib/ninja_van_api/error.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
module
|
2
|
-
class Error < StandardError
|
1
|
+
module NinjaVanApi
|
2
|
+
class Error < StandardError
|
3
|
+
end
|
3
4
|
|
4
|
-
class UnsupportedCountryCodeError < Error
|
5
|
-
|
5
|
+
class UnsupportedCountryCodeError < Error
|
6
|
+
end
|
7
|
+
class AuthenticationError < Error
|
8
|
+
end
|
6
9
|
end
|
data/lib/ninja_van_api.rb
CHANGED
@@ -3,15 +3,10 @@
|
|
3
3
|
require "rails"
|
4
4
|
require_relative "ninja_van_api/version"
|
5
5
|
|
6
|
-
module
|
6
|
+
module NinjaVanApi
|
7
7
|
class Engine < ::Rails::Engine
|
8
8
|
engine_name "ninja_van_api"
|
9
|
-
isolate_namespace
|
10
|
-
|
11
|
-
initializer "ninja_van_api.inflections" do
|
12
|
-
ActiveSupport::Inflector.inflections(:en) { |inflect| inflect.acronym "NinjaVanAPI" }
|
13
|
-
Rails.autoloaders.main.inflector.inflect("ninja_van_api" => "NinjaVanAPI")
|
14
|
-
end
|
9
|
+
isolate_namespace NinjaVanApi
|
15
10
|
end
|
16
11
|
|
17
12
|
# Objects
|
@@ -22,9 +17,6 @@ module NinjaVanAPI
|
|
22
17
|
autoload :BaseResource, "ninja_van_api/resources/base_resource"
|
23
18
|
autoload :OrderResource, "ninja_van_api/resources/order_resource"
|
24
19
|
|
25
|
-
# Controllers
|
26
|
-
autoload :WebhooksController, "../app/controllers/ninja_van_api/webhooks_controller"
|
27
|
-
|
28
20
|
# Core components
|
29
21
|
autoload :Client, "ninja_van_api/client"
|
30
22
|
autoload :Error, "ninja_van_api/error"
|
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.2.
|
4
|
+
version: 0.2.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jane Trang Mai Nguyen
|
@@ -147,7 +147,6 @@ files:
|
|
147
147
|
- lib/ninja_van_api/resources/base_resource.rb
|
148
148
|
- lib/ninja_van_api/resources/order_resource.rb
|
149
149
|
- lib/ninja_van_api/version.rb
|
150
|
-
- sig/ninja_van_api.rbs
|
151
150
|
homepage: https://github.com/Postco/ninja_van_api
|
152
151
|
licenses:
|
153
152
|
- MIT
|
data/sig/ninja_van_api.rbs
DELETED