td-client 0.8.71 → 0.8.72
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/td/client.rb +4 -0
- data/lib/td/client/api/job.rb +22 -6
- data/lib/td/client/model.rb +5 -0
- data/lib/td/client/version.rb +1 -1
- data/spec/td/client/job_api_spec.rb +20 -5
- data/spec/td/client/model_job_spec.rb +28 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f239495e96d72f93277ab75395f7e5f48596bd
|
4
|
+
data.tar.gz: b707ac4743e65d6bbd950a665f7889b64f1aaebd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e219700d74240c7080c8bfc6d717ea9d4efcaa027d9cecfd86c2e21c404d6d9aa4c4c4a150fb7058f8353a93492aa91500b7adc39a6dccc29eb698db1485802
|
7
|
+
data.tar.gz: 8099a83cdd1d941c350d30fd4c1f9d6eae658c799aae719d2e6477f75c22d829b23e4fd677e56d4a59da4bed511ad23342fccb7eaba27cdba92a60ce01b98a33
|
data/lib/td/client.rb
CHANGED
@@ -229,6 +229,10 @@ class Client
|
|
229
229
|
@api.job_result_format(job_id, format, io, &block)
|
230
230
|
end
|
231
231
|
|
232
|
+
def job_result_raw(job_id, format, io=nil, &block)
|
233
|
+
@api.job_result_raw(job_id, format, io, &block)
|
234
|
+
end
|
235
|
+
|
232
236
|
# @param [String] job_id
|
233
237
|
# @param [Proc] block
|
234
238
|
# @return [nil]
|
data/lib/td/client/api/job.rb
CHANGED
@@ -233,12 +233,28 @@ module Job
|
|
233
233
|
# @param [String] job_id
|
234
234
|
# @param [String] format
|
235
235
|
# @return [String]
|
236
|
-
def job_result_raw(job_id, format)
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
236
|
+
def job_result_raw(job_id, format, io = nil, &block)
|
237
|
+
body = nil
|
238
|
+
|
239
|
+
get("/v3/job/result/#{e job_id}", {'format'=>format}) {|res|
|
240
|
+
if res.code != "200"
|
241
|
+
raise_error("Get job result failed", res)
|
242
|
+
end
|
243
|
+
|
244
|
+
if io
|
245
|
+
res.extend(DirectReadBodyMixin)
|
246
|
+
|
247
|
+
total_compr_size = 0
|
248
|
+
res.each_fragment {|fragment|
|
249
|
+
total_compr_size += fragment.size
|
250
|
+
io.write(fragment)
|
251
|
+
block.call(total_compr_size) if block_given?
|
252
|
+
}
|
253
|
+
else
|
254
|
+
body = res.read_body
|
255
|
+
end
|
256
|
+
}
|
257
|
+
body
|
242
258
|
end
|
243
259
|
|
244
260
|
# @param [String] job_id
|
data/lib/td/client/model.rb
CHANGED
@@ -495,6 +495,11 @@ class Job < Model
|
|
495
495
|
@client.job_result_format(@job_id, format, io, &block)
|
496
496
|
end
|
497
497
|
|
498
|
+
def result_raw(format, io=nil, &block)
|
499
|
+
return nil unless finished?
|
500
|
+
@client.job_result_raw(@job_id, format, io, &block)
|
501
|
+
end
|
502
|
+
|
498
503
|
# @yield [result]
|
499
504
|
# @return [nil]
|
500
505
|
def result_each_with_compr_size(&block)
|
data/lib/td/client/version.rb
CHANGED
@@ -271,11 +271,26 @@ describe 'Job API' do
|
|
271
271
|
end
|
272
272
|
|
273
273
|
describe 'job_result_raw' do
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
274
|
+
context 'with io' do
|
275
|
+
let(:io) { StringIO.new }
|
276
|
+
|
277
|
+
it 'returns raw result' do
|
278
|
+
stub_api_request(:get, '/v3/job/result/12345').
|
279
|
+
with(:query => {'format' => 'json'}).
|
280
|
+
to_return(:body => 'raw binary')
|
281
|
+
api.job_result_raw(12345, 'json', io)
|
282
|
+
|
283
|
+
io.string.should == 'raw binary'
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'witout io' do
|
288
|
+
it 'returns raw result' do
|
289
|
+
stub_api_request(:get, '/v3/job/result/12345').
|
290
|
+
with(:query => {'format' => 'json'}).
|
291
|
+
to_return(:body => 'raw binary')
|
292
|
+
api.job_result_raw(12345, 'json').should == 'raw binary'
|
293
|
+
end
|
279
294
|
end
|
280
295
|
end
|
281
296
|
|
@@ -34,4 +34,32 @@ describe 'Job Model' do
|
|
34
34
|
expect(subject).to eq client
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
describe '#result_raw' do
|
39
|
+
let(:client) { Client.authenticate('user', 'password') }
|
40
|
+
let(:job_id) { 12345678 }
|
41
|
+
let(:job) { Job.new(client, job_id, nil, nil) }
|
42
|
+
let(:format) { 'json' }
|
43
|
+
let(:io) { StringIO.new }
|
44
|
+
|
45
|
+
context 'not finished?' do
|
46
|
+
before { job.stub(:finished?) { false } }
|
47
|
+
|
48
|
+
it 'do not call #job_result_raw' do
|
49
|
+
client.should_not_receive(:job_result_raw)
|
50
|
+
|
51
|
+
expect(job.result_raw(format, io)).to_not be
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'finished?' do
|
56
|
+
before { job.stub(:finished?) { true } }
|
57
|
+
|
58
|
+
it 'call #job_result_raw' do
|
59
|
+
client.should_receive(:job_result_raw).with(job_id, format, io)
|
60
|
+
|
61
|
+
job.result_raw(format, io)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
37
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.72
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Treasure Data, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 2.
|
77
|
+
version: 2.5.2
|
78
78
|
- - <
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: 2.6.0
|
@@ -84,7 +84,7 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - '>='
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: 2.
|
87
|
+
version: 2.5.2
|
88
88
|
- - <
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 2.6.0
|