tml 5.7.6 → 5.7.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b283d0f1375ff5f0609d372a147b301c6c1e900e29e5dbdd13e930c5a6bc69f
4
- data.tar.gz: 11c154e67d9dcfb337839abecc69ba98fe55746851b8be45aaf0908901a7e606
3
+ metadata.gz: 8b9103c519573b8c2e5521a0c6726684354acd63be39c97f1f55f2bc88505aa3
4
+ data.tar.gz: 1775589ab5765b5c4769de3b1c12b5b4cec2aba287f77069970e2f92d7523c3c
5
5
  SHA512:
6
- metadata.gz: '03965562121f10a108a594cd59368960c9ecb091b38b1bf95dd187ef58f7ae26d60cfcd73d02dd45ff76753c08eb41db3c53ccfa12671f3787df621358b5fa4b'
7
- data.tar.gz: 9efdb8e5fefc0074477a054170d6127d5830e4700114909700f441d9c974276c08c0a568eb53d2162acdd7a8adabc4653e0aa792d1669a470464a53b3afe503f
6
+ metadata.gz: ab9924e386768e595b72062a577c06f3b26dc5cfed4bde4c29b13997fb8f90d2c113d53685250035cc0759080f3c271993e1b6b7a03c1ae1599bbda6facdb95f
7
+ data.tar.gz: c1b3aedb8700b9e7442fa371bb54b0b4cda8f0c1f521f682a0cf42e929d7350ab28ae2991ae7dede16e1add417bfabaa06ff2b96224730f9e857a075df33b3f4
@@ -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 host
74
- application.host
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 => host) do |faraday|
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 => application.cdn_host)) do
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
- compressed_data = response.body
164
- return if compressed_data.nil? or compressed_data == ''
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 = Zlib::GzipReader.new(StringIO.new(compressed_data.to_s)).read
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
- "/#{clean_path}"
279
+ join_uri(api_uri.path, clean_path)
257
280
  else
258
- "#{API_PATH}/#{clean_path}"
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 => host)) do
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
- compressed_data = response.body
319
- return if compressed_data.nil? or compressed_data == ''
343
+ return if data.nil? or data == ''
320
344
 
321
- data = Zlib::GzipReader.new(StringIO.new(compressed_data.to_s)).read
322
- Tml.logger.debug("Compressed: #{compressed_data.length} Uncompressed: #{data.length}")
323
- else
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]
@@ -31,7 +31,7 @@
31
31
  #++
32
32
 
33
33
  module Tml
34
- VERSION = '5.7.6'
34
+ VERSION = '5.7.7'
35
35
 
36
36
  def self.full_version
37
37
  "tml-ruby v#{Tml::VERSION} (Faraday v#{Faraday::VERSION})"
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.6
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-02-01 00:00:00.000000000 Z
11
+ date: 2018-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday