janio_api 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -0
- data/lib/dev/config.rb +5 -1
- data/lib/janio_api/configuration.rb +1 -1
- data/lib/janio_api/resources/base.rb +12 -0
- data/lib/janio_api/resources/order.rb +12 -1
- data/lib/janio_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ead05593ce47d76a8f18f547f61d7c84783554909b4eb4f1d80b5c9d21f29dc
|
4
|
+
data.tar.gz: 4db668fd55a9019167d52534243578802eda8ee2766a1a589abe139162bdfe15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67d8337c5d5e0ddcc4b45ba0a299eacae6010cab7fb4c4e7654b04f5116b62a111c0c9e77f6bbbdf16b22b1f7c12c5b1e9284ae93da8c609a541dd280cc094c
|
7
|
+
data.tar.gz: ced2968fb2fbf5b4dc438c8543d3e8cc342a349d5db65c61b6c3d4db7cbc9131896b1931c6c03c4f727b3f805f9ae1ed3542b58e80183a8e641b2777fc011fdb
|
data/Gemfile.lock
CHANGED
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
|
@@ -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] =
|
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
|
data/lib/janio_api/version.rb
CHANGED
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.
|
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-
|
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.
|
180
|
+
rubygems_version: 3.0.3
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Ruby object based Janio API wrapper.
|