tml 5.7.6 → 5.7.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/tml/api/client.rb +43 -20
- data/lib/tml/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: 8b9103c519573b8c2e5521a0c6726684354acd63be39c97f1f55f2bc88505aa3
|
4
|
+
data.tar.gz: 1775589ab5765b5c4769de3b1c12b5b4cec2aba287f77069970e2f92d7523c3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9924e386768e595b72062a577c06f3b26dc5cfed4bde4c29b13997fb8f90d2c113d53685250035cc0759080f3c271993e1b6b7a03c1ae1599bbda6facdb95f
|
7
|
+
data.tar.gz: c1b3aedb8700b9e7442fa371bb54b0b4cda8f0c1f521f682a0cf42e929d7350ab28ae2991ae7dede16e1add417bfabaa06ff2b96224730f9e857a075df33b3f4
|
data/lib/tml/api/client.rb
CHANGED
@@ -69,14 +69,23 @@ class Tml::Api::Client < Tml::Base
|
|
69
69
|
not data['error'].nil?
|
70
70
|
end
|
71
71
|
|
72
|
+
def api_uri
|
73
|
+
@api_uri ||= URI::parse(application.host)
|
74
|
+
end
|
75
|
+
|
72
76
|
# API Host
|
73
|
-
def
|
74
|
-
|
77
|
+
def api_host
|
78
|
+
@api_host ||= begin
|
79
|
+
uri = api_uri.dup
|
80
|
+
uri.path = ''
|
81
|
+
uri.query = nil
|
82
|
+
uri.to_s
|
83
|
+
end
|
75
84
|
end
|
76
85
|
|
77
86
|
# API connection
|
78
87
|
def connection
|
79
|
-
@connection ||= Faraday.new(:url =>
|
88
|
+
@connection ||= Faraday.new(:url => api_host) do |faraday|
|
80
89
|
faraday.request(:url_encoded) # form-encode POST params
|
81
90
|
# faraday.response :logger # log requests to STDOUT
|
82
91
|
faraday.adapter(Faraday.default_adapter) # make requests with Net::HTTP
|
@@ -114,6 +123,10 @@ class Tml::Api::Client < Tml::Base
|
|
114
123
|
@cdn_host ||= URI.join(application.cdn_host, '/').to_s
|
115
124
|
end
|
116
125
|
|
126
|
+
def cdn_uri
|
127
|
+
@cdn_host ||= URI::parse(application.cdn_host)
|
128
|
+
end
|
129
|
+
|
117
130
|
def get_cdn_path(key, opts = {})
|
118
131
|
base_path = URI(application.cdn_host).path
|
119
132
|
base_path += '/' unless base_path.last == '/'
|
@@ -126,7 +139,6 @@ class Tml::Api::Client < Tml::Base
|
|
126
139
|
adjusted_path += "#{Tml.cache.version.to_s}/#{key}.json#{opts[:uncompressed] ? '' : '.gz'}"
|
127
140
|
end
|
128
141
|
|
129
|
-
pp adjusted_path
|
130
142
|
adjusted_path
|
131
143
|
end
|
132
144
|
|
@@ -138,6 +150,15 @@ class Tml::Api::Client < Tml::Base
|
|
138
150
|
end
|
139
151
|
end
|
140
152
|
|
153
|
+
def decompress_data(compressed_data)
|
154
|
+
data = Zlib::GzipReader.new(StringIO.new(compressed_data.to_s)).read
|
155
|
+
Tml.logger.debug("Compressed: #{compressed_data.length} Uncompressed: #{data.length}")
|
156
|
+
data
|
157
|
+
rescue => ex
|
158
|
+
Tml.logger.error("Failed to decompress data: #{ex.message[0..255]}")
|
159
|
+
compressed_data
|
160
|
+
end
|
161
|
+
|
141
162
|
# get from the CDN
|
142
163
|
def get_from_cdn(key, params = {}, opts = {})
|
143
164
|
if Tml.cache.version.invalid? and key != 'version'
|
@@ -147,7 +168,7 @@ class Tml::Api::Client < Tml::Base
|
|
147
168
|
response = nil
|
148
169
|
cdn_path = get_cdn_path(key, opts)
|
149
170
|
|
150
|
-
trace_api_call(cdn_path, params, opts.merge(:host =>
|
171
|
+
trace_api_call(cdn_path, params, opts.merge(:host => cdn_host)) do
|
151
172
|
begin
|
152
173
|
response = cdn_connection.get do |request|
|
153
174
|
prepare_request(request, cdn_path, params, opts)
|
@@ -160,19 +181,17 @@ class Tml::Api::Client < Tml::Base
|
|
160
181
|
return if response.status >= 500 and response.status < 600
|
161
182
|
return if response.body.nil? or response.body == '' or response.body.match(/xml/)
|
162
183
|
|
163
|
-
|
164
|
-
return if
|
165
|
-
|
166
|
-
data = compressed_data
|
184
|
+
data = response.body
|
185
|
+
return if data.nil? or data == ''
|
167
186
|
|
168
187
|
unless opts[:uncompressed]
|
169
|
-
data =
|
170
|
-
Tml.logger.debug("Compressed: #{compressed_data.length} Uncompressed: #{data.length}")
|
188
|
+
data = decompress_data(data)
|
171
189
|
end
|
172
190
|
|
173
191
|
begin
|
174
192
|
data = JSON.parse(data)
|
175
193
|
rescue => ex
|
194
|
+
Tml.logger.error("Failed to parse response: #{ex.message[0..255]}")
|
176
195
|
return nil
|
177
196
|
end
|
178
197
|
|
@@ -247,15 +266,19 @@ class Tml::Api::Client < Tml::Base
|
|
247
266
|
end
|
248
267
|
end
|
249
268
|
|
269
|
+
def join_uri(*string)
|
270
|
+
string.join('/').gsub(/\/+/, '/')
|
271
|
+
end
|
272
|
+
|
250
273
|
# prepares API path
|
251
274
|
def prepare_api_path(path)
|
252
275
|
return path if path.match(/^https?:\/\//)
|
253
276
|
clean_path = trim_prepending_slash(path)
|
254
277
|
|
255
278
|
if clean_path.index('v1') == 0 || clean_path.index('v2') == 0
|
256
|
-
|
279
|
+
join_uri(api_uri.path, clean_path)
|
257
280
|
else
|
258
|
-
|
281
|
+
join_uri(api_uri.path, API_PATH, clean_path)
|
259
282
|
end
|
260
283
|
end
|
261
284
|
|
@@ -286,7 +309,7 @@ class Tml::Api::Client < Tml::Base
|
|
286
309
|
|
287
310
|
opts[:method] ||= :get
|
288
311
|
|
289
|
-
trace_api_call(path, params, opts.merge(:host =>
|
312
|
+
trace_api_call(path, params, opts.merge(:host => api_host)) do
|
290
313
|
begin
|
291
314
|
if opts[:method] == :post
|
292
315
|
response = connection.post(path, params)
|
@@ -314,14 +337,14 @@ class Tml::Api::Client < Tml::Base
|
|
314
337
|
raise Tml::Exception.new("Error: #{response.body}")
|
315
338
|
end
|
316
339
|
|
340
|
+
data = response.body
|
341
|
+
|
317
342
|
if opts[:method] == :get && !opts[:uncompressed]
|
318
|
-
|
319
|
-
return if compressed_data.nil? or compressed_data == ''
|
343
|
+
return if data.nil? or data == ''
|
320
344
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
data = response.body
|
345
|
+
unless opts[:uncompressed]
|
346
|
+
data = decompress_data(data)
|
347
|
+
end
|
325
348
|
end
|
326
349
|
|
327
350
|
return data if opts[:raw]
|
data/lib/tml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.7.
|
4
|
+
version: 5.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|