Class: NinjaVanApi::Client
- Inherits:
-
Object
- Object
- NinjaVanApi::Client
- Defined in:
- lib/ninja_van_api/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.ninjavan.co".freeze
- SANDBOX_BASE_URL =
"https://api-sandbox.ninjavan.co".freeze
- SUPPORTED_COUNTRY_CODES =
%w[SG MY TH ID VN PH MM]
Instance Attribute Summary collapse
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#test_mode ⇒ Object
readonly
Returns the value of attribute test_mode.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(client_id:, client_secret:, country_code: "SG", test_mode: false, conn_opts: {}) ⇒ Client
constructor
A new instance of Client.
- #orders ⇒ Object
- #refresh_access_token ⇒ Object
- #waybills ⇒ Object
Constructor Details
#initialize(client_id:, client_secret:, country_code: "SG", test_mode: false, conn_opts: {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 |
# File 'lib/ninja_van_api/client.rb', line 12 def initialize(client_id:, client_secret:, country_code: "SG", test_mode: false, conn_opts: {}) @client_id = client_id @client_secret = client_secret @country_code = country_code @test_mode = test_mode @conn_opts = conn_opts validate_country_code end |
Instance Attribute Details
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
10 11 12 |
# File 'lib/ninja_van_api/client.rb', line 10 def country_code @country_code end |
#test_mode ⇒ Object (readonly)
Returns the value of attribute test_mode.
10 11 12 |
# File 'lib/ninja_van_api/client.rb', line 10 def test_mode @test_mode end |
Instance Method Details
#connection ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ninja_van_api/client.rb', line 22 def connection @connection ||= Faraday.new do |conn| conn.url_prefix = url_prefix conn..merge!(@conn_opts) # access_token will be evaluated on each request using proc conn.request :authorization, :Bearer, -> { access_token } conn.request :json conn.response :json, content_type: "application/json" end end |
#orders ⇒ Object
34 35 36 |
# File 'lib/ninja_van_api/client.rb', line 34 def orders @orders ||= OrderResource.new(self) end |
#refresh_access_token ⇒ Object
42 43 44 45 |
# File 'lib/ninja_van_api/client.rb', line 42 def refresh_access_token Rails.cache.delete(cache_key) fetch_access_token end |
#waybills ⇒ Object
38 39 40 |
# File 'lib/ninja_van_api/client.rb', line 38 def waybills @waybills ||= WaybillResource.new(self) end |