janio_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: aa093e0f5ad7e07588aaf0c058fea09ef6ee4fbfa7e44044557e0fa313dc15cd
4
- data.tar.gz: da73f1b6206dc12d175a71fbf6c73b43562eb4ec0c99b36dd5579c8bebf35863
3
+ metadata.gz: 7ead05593ce47d76a8f18f547f61d7c84783554909b4eb4f1d80b5c9d21f29dc
4
+ data.tar.gz: 4db668fd55a9019167d52534243578802eda8ee2766a1a589abe139162bdfe15
5
5
  SHA512:
6
- metadata.gz: 934f2a7a98afd7dec8d84212fb4233484c7f31521812e4b2ca2e91060dff3f87a35f49c35e60b73f103de6257accaaafab0f079978f3809534f19fad2a4b3f3f
7
- data.tar.gz: 569852e237c4db83f14c3092604ecfd27f1edd01aef5ac72ec93ed3021c810c816167c19bb2bf3bb25aeb7f4bd867afa7a86e463bcc85ced8696343f94f1fbe1
6
+ metadata.gz: a67d8337c5d5e0ddcc4b45ba0a299eacae6010cab7fb4c4e7654b04f5116b62a111c0c9e77f6bbbdf16b22b1f7c12c5b1e9284ae93da8c609a541dd280cc094c
7
+ data.tar.gz: ced2968fb2fbf5b4dc438c8543d3e8cc342a349d5db65c61b6c3d4db7cbc9131896b1931c6c03c4f727b3f805f9ae1ed3542b58e80183a8e641b2777fc011fdb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- janio_api (0.2.1)
4
+ janio_api (0.3.2)
5
5
  activeresource
6
6
  countries
7
7
  phonelib
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # JanioAPI
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/janio_api.svg)](https://badge.fury.io/rb/janio_api)
4
+
3
5
  ## Installation
4
6
 
5
7
  Add this line to your application's Gemfile:
@@ -22,10 +24,18 @@ Or install it yourself as:
22
24
 
23
25
  1. Create a file under the `initializers` folder.
24
26
  2. Set the `api_host` and `api_token` as following sample:
27
+
25
28
  ```ruby
26
29
  JanioAPI.configure do |config|
27
30
  config.api_host = ENV["API_HOST"]
31
+
28
32
  config.api_token = ENV["API_TOKEN"]
33
+ # or
34
+ # api_tokens will take over api_token if set in config
35
+ config.api_tokens = {
36
+ MY: ENV["MALAYSIA_JANIO_API_TOKEN"],
37
+ SG: ENV["SINGAPORE_JANIO_API_TOKEN"],
38
+ }
29
39
  end
30
40
  ```
31
41
 
data/lib/dev/config.rb CHANGED
@@ -3,6 +3,10 @@ require "dotenv/load"
3
3
  def set_config
4
4
  JanioAPI.configure do |config|
5
5
  config.api_host = ENV["API_HOST"]
6
- config.api_token = ENV["API_TOKEN"]
6
+ # config.api_token = ENV["API_TOKEN"]
7
+ config.api_tokens = {
8
+ MY: ENV["MY_API_TOKEN"],
9
+ SG: ENV["SG_API_TOKEN"]
10
+ }
7
11
  end
8
12
  end
@@ -1,6 +1,6 @@
1
1
  module JanioAPI
2
2
  class Configuration
3
- attr_accessor :api_host, :api_token
3
+ attr_accessor :api_host, :api_token, :api_tokens
4
4
  end
5
5
 
6
6
  def self.config
@@ -3,5 +3,17 @@ module JanioAPI
3
3
  self.include_root_in_json = false
4
4
  self.include_format_in_path = false
5
5
  self.connection_class = JanioAPI::Connection
6
+
7
+ class << self
8
+ def headers
9
+ if _headers_defined?
10
+ _headers
11
+ elsif superclass != Object && superclass.headers
12
+ superclass.headers
13
+ else
14
+ _headers ||= {}
15
+ end
16
+ end
17
+ end
6
18
  end
7
19
  end
@@ -220,13 +220,24 @@ module JanioAPI
220
220
  def reformat_before_save(blocking)
221
221
  attributes = @attributes.dup
222
222
  @attributes.clear
223
- @attributes[:secret_key] = JanioAPI.config.api_token
223
+ @attributes[:secret_key] = retrieve_api_token
224
224
  # set blocking until label generated
225
225
  @attributes[:blocking] = blocking
226
226
  # reformat attributes
227
227
  @attributes[:orders] = [attributes]
228
228
  end
229
229
 
230
+ def retrieve_api_token
231
+ if JanioAPI.config.api_tokens
232
+ country_code_sym = ISO3166::Country.find_country_by_name(@attributes[:pickup_country])&.alpha2&.to_sym
233
+ JanioAPI.config.api_tokens[country_code_sym]
234
+ elsif JanioAPI.config.api_token
235
+ JanioAPI.config.api_token
236
+ else
237
+ throw ArgumentError.new("JanioAPI api_token is missing, please set it in the config.")
238
+ end
239
+ end
240
+
230
241
  def reset_attributes_format
231
242
  attributes = @attributes.dup
232
243
  @attributes.clear
@@ -1,3 +1,3 @@
1
1
  module JanioAPI
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janio_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
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-03 00:00:00.000000000 Z
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubygems_version: 3.1.2
180
+ rubygems_version: 3.0.3
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: Ruby object based Janio API wrapper.