td-client 0.8.32 → 0.8.33

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.
data/ChangeLog CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ == 2012-10-10 version 0.8.33
3
+
4
+ * supports import_with_id API
5
+ * supports deflate and gzip Content-Encodings and sends Accept-Encoding header
6
+
7
+
2
8
  == 2012-10-09 version 0.8.32
3
9
 
4
10
  * Added Client#swap_table
@@ -279,8 +279,8 @@ class Client
279
279
  end
280
280
 
281
281
  # => time:Flaot
282
- def import(db_name, table_name, format, stream, size)
283
- @api.import(db_name, table_name, format, stream, size)
282
+ def import(db_name, table_name, format, stream, size, unique_id=nil)
283
+ @api.import(db_name, table_name, format, stream, size, unique_id)
284
284
  end
285
285
 
286
286
  # => [Result]
@@ -408,7 +408,7 @@ class API
408
408
  raise_error("Get job result failed", res)
409
409
  end
410
410
  if io
411
- res.read_body {|fragment|
411
+ res.each_fragment {|fragment|
412
412
  io.write(fragment)
413
413
  }
414
414
  end
@@ -425,7 +425,7 @@ class API
425
425
  raise_error("Get job result failed", res)
426
426
  end
427
427
  u = MessagePack::Unpacker.new
428
- res.read_body {|fragment|
428
+ res.each_fragment {|fragment|
429
429
  u.feed_each(fragment, &block)
430
430
  }
431
431
  }
@@ -744,8 +744,13 @@ class API
744
744
  ##
745
745
 
746
746
  # => time:Float
747
- def import(db, table, format, stream, size)
748
- code, body, res = put("/v3/table/import/#{e db}/#{e table}/#{format}", stream, size)
747
+ def import(db, table, format, stream, size, unique_id=nil)
748
+ if unique_id
749
+ path = "/v3/table/import_with_id/#{e db}/#{e table}/#{unique_id}/#{format}"
750
+ else
751
+ path = "/v3/table/import/#{e db}/#{e table}/#{format}"
752
+ end
753
+ code, body, res = put(path, stream, size)
749
754
  if code[0] != ?2
750
755
  raise_error("Import failed", res)
751
756
  end
@@ -1206,6 +1211,32 @@ class API
1206
1211
 
1207
1212
 
1208
1213
  private
1214
+ module DeflateReadBodyMixin
1215
+ attr_accessor :gzip
1216
+
1217
+ def each_fragment(&block)
1218
+ if @gzip
1219
+ infl = Zlib::Inflate.new(Zlib::MAX_WBITS+16)
1220
+ else
1221
+ infl = Zlib::Inflate.new
1222
+ end
1223
+ begin
1224
+ read_body do |fragment|
1225
+ block.call infl.inflate(fragment)
1226
+ end
1227
+ ensure
1228
+ infl.close
1229
+ end
1230
+ nil
1231
+ end
1232
+ end
1233
+
1234
+ module DirectReadBodyMixin
1235
+ def each_fragment(&block)
1236
+ read_body(&block)
1237
+ end
1238
+ end
1239
+
1209
1240
  def get(url, params=nil, &block)
1210
1241
  http, header = new_http
1211
1242
 
@@ -1216,11 +1247,42 @@ class API
1216
1247
  }.join('&')
1217
1248
  end
1218
1249
 
1250
+ header['Accept-Encoding'] = 'deflate, gzip'
1219
1251
  request = Net::HTTP::Get.new(path, header)
1220
1252
 
1221
- response = http.request(request, &block)
1253
+ if block
1254
+ response = http.request(request) do |res|
1255
+ if ce = res.header['Content-Encoding']
1256
+ require 'zlib'
1257
+ res.extend(DeflateReadBodyMixin)
1258
+ res.gzip = true if ce == 'gzip'
1259
+ else
1260
+ res.extend(DirectReadBodyMixin)
1261
+ end
1262
+ block.call(res)
1263
+ end
1264
+ else
1265
+ response = http.request(request)
1266
+ end
1267
+
1268
+ body = response.body
1269
+ unless block
1270
+ if ce = response.header['content-encoding']
1271
+ require 'zlib'
1272
+ if ce == 'gzip'
1273
+ infl = Zlib::Inflate.new(Zlib::MAX_WBITS+16)
1274
+ begin
1275
+ body = infl.inflate(body)
1276
+ ensure
1277
+ infl.close
1278
+ end
1279
+ else
1280
+ body = Zlib::Inflate.inflate(body)
1281
+ end
1282
+ end
1283
+ end
1222
1284
 
1223
- return [response.code, response.body, response]
1285
+ return [response.code, body, response]
1224
1286
  end
1225
1287
 
1226
1288
  def post(url, params=nil)
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
 
3
- VERSION = '0.8.32'
3
+ VERSION = '0.8.33'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.32
4
+ version: 0.8.33
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000 Z
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack