ninja_van_api 0.2.15 → 0.2.16

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: 22bbcaf9ec38f198b70b4ee63e39ed4ca9a9ae3038aa0b7b4d6cb3a729f5a4cd
4
- data.tar.gz: cbf30a99dbb1b27361538a097e698871b479a5610755609d943dbda587873076
3
+ metadata.gz: 522c1d827f1bad4a219d4739cc6dbccba0823c8368a749ed4efdeafcb483ff1d
4
+ data.tar.gz: 89ecae3353c8abd57b8d9ad646274e6405ddc6d59f02966b66d74861a14d9175
5
5
  SHA512:
6
- metadata.gz: 9bfa43c7cdefa0f5b349890e224fe8e8d6de6ca84c1ff17b5846fcbdaa28a4f433637d9490d6a4025ba0cb4dbeae6b662d4953deb08d40bcd7822d339698a19a
7
- data.tar.gz: febbc7b0ac391aad186d38ebefe6de2c5238e587da68f6d24b8703c61cc46f48a74b0c79b53ac2f426105698038b29459433695b518dc9bbf06a79f53639ae45
6
+ metadata.gz: b5d99c58fff0518cbc813a4b1e072c16a72dc64dc1985f4e34a2dfec3f1d3511ff5bfa9de0ce8d5f6bde61812f6deefddb695df08c15d6977266f3fe73e7b907
7
+ data.tar.gz: a756d041adce6311c0ef92c6b7927d45810bcfb37ead167ad3ad808ee8de1d83dd727d7707516dfb1a6c22194f3a0dc2741fc94d2229a18778e5e478ffdd263e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # NinjaVanAPI
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 NinjaVanAPI::Engine => '/ninja_van/my'
27
- mount NinjaVanAPI::Engine => '/ninja_van/sg'
28
- mount NinjaVanAPI::Engine => '/ninja_van/id'
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
- NinjaVanAPI.configure do |config|
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 = NinjaVanAPI::Client.new(
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 NinjaVanAPI
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 NinjaVanAPI.configuration.webhook_job_class
8
- NinjaVanAPI.configuration.webhook_job_class.perform_later(webhook_params.to_h)
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 = NinjaVanAPI.configuration.get_webhook_secret(country_code)
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
@@ -1,5 +1 @@
1
- NinjaVanAPI::Engine.routes.draw do
2
- controller :webhooks do
3
- post "/" => :create
4
- end
5
- end
1
+ NinjaVanApi::Engine.routes.draw { post "/" => "webhooks/create" }
@@ -1,7 +1,7 @@
1
1
  require "faraday"
2
2
  require "faraday/net_http"
3
3
 
4
- module NinjaVanAPI
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 NinjaVanAPI::UnsupportedCountryCodeError, "#{country_code} is not supported on test mode"
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 NinjaVanAPI::UnsupportedCountryCodeError, "#{country_code} is not supported"
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 NinjaVanAPI::AuthenticationError, response.body unless response.success?
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 NinjaVanAPI::AuthenticationError unless response.success?
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
- # NinjaVanAPI.configure do |config|
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 NinjaVanAPI
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, 'webhook_job_class must be an ActiveJob class name or class that responds to perform_later'
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
@@ -1,6 +1,9 @@
1
- module NinjaVanAPI
2
- class Error < StandardError; end
1
+ module NinjaVanApi
2
+ class Error < StandardError
3
+ end
3
4
 
4
- class UnsupportedCountryCodeError < Error; end
5
- class AuthenticationError < Error; end
5
+ class UnsupportedCountryCodeError < Error
6
+ end
7
+ class AuthenticationError < Error
8
+ end
6
9
  end
@@ -4,7 +4,7 @@ require "active_support"
4
4
  require "active_support/core_ext/string"
5
5
  require "ostruct"
6
6
 
7
- module NinjaVanAPI
7
+ module NinjaVanApi
8
8
  class Base < OpenStruct
9
9
  def initialize(attributes)
10
10
  super to_ostruct(attributes)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module NinjaVanAPI
3
+ module NinjaVanApi
4
4
  class Order < Base
5
5
  end
6
6
  end
@@ -3,7 +3,7 @@
3
3
  require "active_support"
4
4
  require "active_support/core_ext/string"
5
5
 
6
- module NinjaVanAPI
6
+ module NinjaVanApi
7
7
  class BaseResource
8
8
  attr_reader :client
9
9
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module NinjaVanAPI
3
+ module NinjaVanApi
4
4
  class OrderResource < BaseResource
5
5
  def create(params = {})
6
6
  response = post_request("4.2/orders", body: params)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module NinjaVanAPI
4
- VERSION = '0.2.15'
3
+ module NinjaVanApi
4
+ VERSION = "0.2.16"
5
5
  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 NinjaVanAPI
6
+ module NinjaVanApi
7
7
  class Engine < ::Rails::Engine
8
8
  engine_name "ninja_van_api"
9
- isolate_namespace NinjaVanAPI
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.15
4
+ version: 0.2.16
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
@@ -1,4 +0,0 @@
1
- module NinjaVanApi
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end