janio_api 0.3.6 → 0.3.7
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/lib/dev/zeitwerk_loader.rb +1 -1
- data/lib/janio_api/resources/base.rb +13 -0
- data/lib/janio_api/resources/order.rb +19 -6
- data/lib/janio_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eb551722b7d734da79c0c34f59c6f14c8866e2656562b0fd25bdba9bcdc3fb3
|
4
|
+
data.tar.gz: 487e7b65437e433546c116aba987176b41ad937d4c6937bcf5270c7995ab2907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8dc69b4891a6d07f6a7d78a47a518e69819bbfe6b78b86784bc557fb4433e547160da13bf355efd1e36cb9a17c8b808f8a95e09039777cb11082922e1c83329
|
7
|
+
data.tar.gz: '075582cc9cf498238a20f37a5e5107fc89644651526ab42b8c53450f5bd6e27db04e573342ba8ba3b9eb12467371b42b3c067e32c4fe4e6111862cb52f711067'
|
data/lib/dev/zeitwerk_loader.rb
CHANGED
@@ -10,7 +10,7 @@ loader.collapse("./lib/janio_api/resources")
|
|
10
10
|
loader.ignore("#{__dir__}/config.rb")
|
11
11
|
loader.ignore("./lib/janio_api/exceptions.rb")
|
12
12
|
loader.ignore("./lib/janio_api/services_list.rb")
|
13
|
-
loader.ignore("./lib/janio_api/
|
13
|
+
loader.ignore("./lib/janio_api/postal_code_regex_list.rb")
|
14
14
|
loader.enable_reloading
|
15
15
|
# loader.log!
|
16
16
|
loader.setup
|
@@ -4,6 +4,19 @@ module JanioAPI
|
|
4
4
|
self.include_format_in_path = false
|
5
5
|
self.connection_class = JanioAPI::Connection
|
6
6
|
|
7
|
+
def initialize(attributes = {}, persisted = false)
|
8
|
+
# check if config host and api token is set
|
9
|
+
unless JanioAPI.config.api_tokens || JanioAPI.config.api_token
|
10
|
+
raise ArgumentError, "JanioAPI api_token/api_tokens is missing, please set it in the config."
|
11
|
+
end
|
12
|
+
|
13
|
+
unless JanioAPI.config.api_host
|
14
|
+
raise ArgumentError, "JanioAPI api_host is missing, please set it in the config."
|
15
|
+
end
|
16
|
+
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
7
20
|
class << self
|
8
21
|
def headers
|
9
22
|
if _headers_defined?
|
@@ -117,15 +117,27 @@ module JanioAPI
|
|
117
117
|
# Track one or more tracking nos
|
118
118
|
#
|
119
119
|
# Check http://apidocs.janio.asia/track for more information
|
120
|
-
def track(tracking_nos)
|
121
|
-
raise ArgumentError, "tracking_nos
|
120
|
+
def track(tracking_nos, secret_key = nil)
|
121
|
+
raise ArgumentError, "tracking_nos must be an array" unless tracking_nos.is_a?(Array)
|
122
122
|
|
123
123
|
body = {
|
124
124
|
get_related_updates: true,
|
125
|
-
flatten_data:
|
125
|
+
flatten_data: false,
|
126
126
|
tracking_nos: tracking_nos
|
127
127
|
}
|
128
|
-
|
128
|
+
|
129
|
+
headers[:secret_key] = secret_key unless secret_key.nil?
|
130
|
+
|
131
|
+
raise ArgumentError, "secret_key can't be blank" unless headers[:secret_key].present?
|
132
|
+
|
133
|
+
retries = 0
|
134
|
+
begin
|
135
|
+
retries += 1
|
136
|
+
response = connection.post(tracking_path, body.to_json, headers)
|
137
|
+
rescue ActiveResource::ConnectionError => e
|
138
|
+
retry unless retries <= 5
|
139
|
+
raise e
|
140
|
+
end
|
129
141
|
|
130
142
|
self.format.decode(response.body)
|
131
143
|
end
|
@@ -141,7 +153,7 @@ module JanioAPI
|
|
141
153
|
end
|
142
154
|
|
143
155
|
def pickup_date=(date)
|
144
|
-
@attributes[:pickup_date] = if date.is_a?(ActiveSupport::TimeWithZone)
|
156
|
+
@attributes[:pickup_date] = if date.is_a?(ActiveSupport::TimeWithZone) || date.is_a?(Time)
|
145
157
|
date.strftime("%Y-%-m-%-d")
|
146
158
|
else
|
147
159
|
date
|
@@ -170,6 +182,7 @@ module JanioAPI
|
|
170
182
|
flatten_data: true,
|
171
183
|
tracking_nos: [@attributes[:tracking_no]]
|
172
184
|
}
|
185
|
+
|
173
186
|
response = connection.post(self.class.tracking_path, body.to_json, self.class.headers)
|
174
187
|
self.class.format.decode(response.body)[0]
|
175
188
|
end
|
@@ -268,7 +281,7 @@ module JanioAPI
|
|
268
281
|
elsif JanioAPI.config.api_token
|
269
282
|
JanioAPI.config.api_token
|
270
283
|
else
|
271
|
-
raise ArgumentError, "JanioAPI api_token is missing, please set it in the config."
|
284
|
+
raise ArgumentError, "JanioAPI api_token/api_tokens is missing, please set it in the config."
|
272
285
|
end
|
273
286
|
end
|
274
287
|
|
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.7
|
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-
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|