td-client 0.8.69 → 0.8.70

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
  SHA1:
3
- metadata.gz: cce938755d8baa274b4129395cc3bf025852123d
4
- data.tar.gz: 251fa5c0007d67a8bcbae03f01f31d7748a2654d
3
+ metadata.gz: 1ec9013fc056a1f4bcd364a56ca5d19c704884de
4
+ data.tar.gz: 0ec13bda51e5ea8f5d35573406bbe7386efaccb2
5
5
  SHA512:
6
- metadata.gz: ebe285884532e4683d0ca58db039433d5f53fd5cf047db0318ceb93230f0bf0b151fd1f5bd321bbfc55f23784ecd4650764fa57019ec3b6e8d8762a74b6486e1
7
- data.tar.gz: d37ce150f9a65d5d5a5231c4d277cd1867f193e0c9dec8c5920424faa67acfa75ff5e0e114130156ebc6db991af4eb58b6095784c5afc8cb0124724180ffb687
6
+ metadata.gz: 333b6b5e408515f0a0523d6c4057274232255e8c4da8904fa383eb69e7d78b5d679454317ff21efc0ebc0df0e870fdd99fe316a3a2880bbf24e3281602807260
7
+ data.tar.gz: 9f2fd6c88a7e8624aba8b89997cce43f1b88e08a3e364b5789367c823f95b10a99bfcc9787058716d68abeaa451ffe7e00f99f54b39321cf6e76fe9c23aff76f
@@ -192,9 +192,11 @@ class Client
192
192
  def jobs(from=nil, to=nil, status=nil, conditions=nil)
193
193
  results = @api.list_jobs(from, to, status, conditions)
194
194
  results.map {|job_id, type, status, query, start_at, end_at, cpu_time,
195
- result_size, result_url, priority, retry_limit, org, db|
195
+ result_size, result_url, priority, retry_limit, org, db,
196
+ duration|
196
197
  Job.new(self, job_id, type, query, status, nil, nil, start_at, end_at, cpu_time,
197
- result_size, nil, result_url, nil, priority, retry_limit, org, db)
198
+ result_size, nil, result_url, nil, priority, retry_limit, org, db,
199
+ duration)
198
200
  }
199
201
  end
200
202
 
@@ -298,9 +300,10 @@ class Client
298
300
  end
299
301
 
300
302
  # @param [String] name
303
+ # @param [Hash] opts options for API
301
304
  # @return [Job]
302
- def perform_bulk_import(name)
303
- job_id = @api.perform_bulk_import(name)
305
+ def perform_bulk_import(name, opts={})
306
+ job_id = @api.perform_bulk_import(name, opts)
304
307
  Job.new(self, job_id, :bulk_import, nil)
305
308
  end
306
309
 
@@ -1,5 +1,3 @@
1
- require 'td/client/api/to_hash_struct'
2
-
3
1
  class TreasureData::API
4
2
  module BulkLoad
5
3
 
@@ -42,65 +40,40 @@ module BulkLoad
42
40
  # "table": table_name
43
41
  # }
44
42
 
45
- ## Resource definitions
46
-
47
- class BulkLoad < ToHashStruct.new(:config, :name, :cron, :timezone, :delay, :time_column, :database, :table)
48
- class BulkLoadSessionConfig < ToHashStruct.new(:type, :access_key_id, :secret_access_key, :endpoint, :bucket, :path_prefix, :parser, :decoders)
49
- def validate_self
50
- validate_presence_of :type
51
- end
52
- end
53
-
54
- model_property :config, BulkLoadSessionConfig
55
-
56
- def validate_self
57
- validate_presence_of :config
58
- end
59
- end
60
-
61
- class BulkLoadPreview < ToHashStruct.new(:schema, :records)
62
- end
63
-
64
- class Job < ToHashStruct.new(:job_id, :account_id, :type, :status, :cpu_time, :config, :records, :schema, :database, :table, :priority, :created_at, :updated_at, :start_at, :end_at)
65
- model_property :config, BulkLoad::BulkLoadSessionConfig
66
- end
67
-
68
- ## API definitions
69
-
70
43
  LIST = '/v3/bulk_loads'
71
44
  SESSION = LIST + '/%s'
72
45
  JOB = SESSION + '/jobs'
73
46
 
74
- # job: BulkLoad -> BulkLoad
47
+ # job: Hash -> Hash
75
48
  def bulk_load_guess(job)
76
49
  # retry_request = true
77
50
  path = LIST + '/guess'
78
- res = api { post(path, job.validate.to_json) }
51
+ res = api { post(path, job.to_json) }
79
52
  unless res.ok?
80
53
  raise_error('BulkLoad configuration guess failed', res)
81
54
  end
82
- BulkLoad.from_json(res.body)
55
+ JSON.load(res.body)
83
56
  end
84
57
 
85
- # job: BulkLoad -> BulkLoadPreview
58
+ # job: Hash -> Hash
86
59
  def bulk_load_preview(job)
87
60
  # retry_request = true
88
61
  path = LIST + '/preview'
89
- res = api { post(path, job.validate.to_json) }
62
+ res = api { post(path, job.to_json) }
90
63
  unless res.ok?
91
64
  raise_error('BulkLoad job preview failed', res)
92
65
  end
93
- BulkLoadPreview.from_json(res.body)
66
+ JSON.load(res.body)
94
67
  end
95
68
 
96
- # job: BulkLoad -> String (job_id)
69
+ # job: Hash -> String (job_id)
97
70
  def bulk_load_issue(database, table, job)
98
71
  type = 'bulkload'
99
72
  job = job.dup
100
73
  job['database'] = database
101
74
  job['table'] = table
102
75
  path = "/v3/job/issue/#{e type}/#{e database}"
103
- res = api { post(path, job.validate.to_json) }
76
+ res = api { post(path, job.to_json) }
104
77
  unless res.ok?
105
78
  raise_error('BulkLoad job issuing failed', res)
106
79
  end
@@ -108,16 +81,16 @@ module BulkLoad
108
81
  js['job_id'].to_s
109
82
  end
110
83
 
111
- # nil -> [BulkLoad]
84
+ # nil -> [Hash]
112
85
  def bulk_load_list
113
86
  res = api { get(LIST) }
114
87
  unless res.ok?
115
88
  raise_error("BulkLoadSession list retrieve failed", res)
116
89
  end
117
- to_ary(res, BulkLoad)
90
+ JSON.load(res.body)
118
91
  end
119
92
 
120
- # name: String, database: String, table: String, job: BulkLoad -> BulkLoad
93
+ # name: String, database: String, table: String, job: Hash -> Hash
121
94
  def bulk_load_create(name, database, table, job, opts = {})
122
95
  job = job.dup
123
96
  job['name'] = name
@@ -126,51 +99,51 @@ module BulkLoad
126
99
  end
127
100
  job['database'] = database
128
101
  job['table'] = table
129
- res = api { post(LIST, job.validate.to_json) }
102
+ res = api { post(LIST, job.to_json) }
130
103
  unless res.ok?
131
104
  raise_error("BulkLoadSession: #{name} create failed", res)
132
105
  end
133
- BulkLoad.from_json(res.body)
106
+ JSON.load(res.body)
134
107
  end
135
108
 
136
- # name: String -> BulkLoad
109
+ # name: String -> Hash
137
110
  def bulk_load_show(name)
138
111
  path = session_path(name)
139
112
  res = api { get(path) }
140
113
  unless res.ok?
141
114
  raise_error("BulkLoadSession: #{name} retrieve failed", res)
142
115
  end
143
- BulkLoad.from_json(res.body)
116
+ JSON.load(res.body)
144
117
  end
145
118
 
146
- # name: String, job: BulkLoad -> BulkLoad
119
+ # name: String, job: Hash -> Hash
147
120
  def bulk_load_update(name, job)
148
121
  path = session_path(name)
149
- res = api { put(path, job.validate.to_json) }
122
+ res = api { put(path, job.to_json) }
150
123
  unless res.ok?
151
124
  raise_error("BulkLoadSession: #{name} update failed", res)
152
125
  end
153
- BulkLoad.from_json(res.body)
126
+ JSON.load(res.body)
154
127
  end
155
128
 
156
- # name: String -> BulkLoad
129
+ # name: String -> Hash
157
130
  def bulk_load_delete(name)
158
131
  path = session_path(name)
159
132
  res = api { delete(path) }
160
133
  unless res.ok?
161
134
  raise_error("BulkLoadSession: #{name} delete failed", res)
162
135
  end
163
- BulkLoad.from_json(res.body)
136
+ JSON.load(res.body)
164
137
  end
165
138
 
166
- # name: String -> [Job]
139
+ # name: String -> [Hash]
167
140
  def bulk_load_history(name)
168
141
  path = job_path(name)
169
142
  res = api { get(path) }
170
143
  unless res.ok?
171
144
  raise_error("history of BulkLoadSession: #{name} retrieve failed", res)
172
145
  end
173
- to_ary(res, Job)
146
+ JSON.load(res.body)
174
147
  end
175
148
 
176
149
  def bulk_load_run(name, scheduled_time = nil)
@@ -195,11 +168,5 @@ private
195
168
  JOB % e(name)
196
169
  end
197
170
 
198
- def to_ary(res, klass)
199
- JSON.parse(res.body).map { |bulk_load|
200
- klass.from_hash(bulk_load)
201
- }
202
- end
203
-
204
171
  end
205
172
  end
@@ -35,8 +35,10 @@ module Job
35
35
  result_url = m['result']
36
36
  priority = m['priority']
37
37
  retry_limit = m['retry_limit']
38
+ duration = m['duration']
38
39
  result << [job_id, type, status, query, start_at, end_at, cpu_time,
39
- result_size, result_url, priority, retry_limit, nil, database]
40
+ result_size, result_url, priority, retry_limit, nil, database,
41
+ duration]
40
42
  }
41
43
  return result
42
44
  end
@@ -381,9 +381,10 @@ class Job < Model
381
381
  # @param [Fixnum] retry_limit
382
382
  # @param [String] org_name
383
383
  # @param [String] db_name
384
+ # @param [Fixnum] duration
384
385
  def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, start_at=nil, end_at=nil, cpu_time=nil,
385
386
  result_size=nil, result=nil, result_url=nil, hive_result_schema=nil, priority=nil, retry_limit=nil,
386
- org_name=nil, db_name=nil)
387
+ org_name=nil, db_name=nil, duration=nil)
387
388
  super(client)
388
389
  @job_id = job_id
389
390
  @type = type
@@ -401,6 +402,7 @@ class Job < Model
401
402
  @priority = priority
402
403
  @retry_limit = retry_limit
403
404
  @db_name = db_name
405
+ @duration = duration
404
406
  end
405
407
 
406
408
  # @!attribute [r] job_id
@@ -410,8 +412,10 @@ class Job < Model
410
412
  # @!attribute [r] retry_limit
411
413
  # @!attribute [r] org_name
412
414
  # @!attribute [r] db_name
415
+ # @!attribute [r] duration
413
416
  attr_reader :job_id, :type, :result_url
414
417
  attr_reader :priority, :retry_limit, :org_name, :db_name
418
+ attr_reader :duration
415
419
 
416
420
  def wait(timeout=nil)
417
421
  # TODO
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
  class Client
3
- VERSION = '0.8.69'
3
+ VERSION = '0.8.70'
4
4
  end
5
5
  end
@@ -114,8 +114,8 @@ describe 'BulkImport API' do
114
114
  with(:body => original_config.to_json).
115
115
  to_return(:body => guessed_config.to_json)
116
116
  api.bulk_load_guess(
117
- TreasureData::API::BulkLoad::BulkLoad.from_hash(original_config)
118
- ).to_h.should == guessed_config
117
+ original_config
118
+ ).should == guessed_config
119
119
  end
120
120
 
121
121
  it 'raises an error' do
@@ -124,24 +124,56 @@ describe 'BulkImport API' do
124
124
  to_return(:status => 500, :body => guessed_config.to_json)
125
125
  expect {
126
126
  api.bulk_load_guess(
127
- TreasureData::API::BulkLoad::BulkLoad.from_hash(original_config)
127
+ original_config
128
128
  )
129
129
  }.to raise_error(TreasureData::APIError)
130
130
  end
131
131
 
132
- it 'raises on validation error' do
133
- config = TreasureData::API::BulkLoad::BulkLoad.from_hash({})
134
- expect {
135
- api.bulk_load_guess(config)
136
- }.to raise_error(ArgumentError)
132
+ it 'perform redo on 500 error' do
133
+ stub_api_request(:post, '/v3/bulk_loads/guess').
134
+ with(:body => original_config.to_json).
135
+ to_return(:status => 500, :body => guessed_config.to_json)
136
+ begin
137
+ retry_api.bulk_load_guess(
138
+ original_config
139
+ ).should != nil
140
+ rescue TreasureData::APIError => e
141
+ e.message.should =~ /^500: BulkLoad configuration guess failed/
142
+ end
137
143
  end
138
144
 
139
- it 'raises on nested validation error' do
140
- config = TreasureData::API::BulkLoad::BulkLoad.from_hash(original_config)
141
- config.config.type = nil
145
+ it 'perform retries on connection failure' do
146
+ api = retry_api
147
+ api.instance_eval { @api }.stub(:post).and_raise(SocketError.new('>>'))
148
+ begin
149
+ retry_api.bulk_load_guess(
150
+ original_config
151
+ )
152
+ rescue SocketError => e
153
+ e.message.should == '>> (Retried 1 times in 1 seconds)'
154
+ end
155
+ end
156
+ end
157
+
158
+ describe 'guess with old format' do
159
+ it 'returns guessed json' do
160
+ stub_api_request(:post, '/v3/bulk_loads/guess').
161
+ with(:body => original_config.to_json).
162
+ to_return(:body => guessed_config.to_json)
163
+ api.bulk_load_guess(
164
+ original_config
165
+ ).should == guessed_config
166
+ end
167
+
168
+ it 'raises an error' do
169
+ stub_api_request(:post, '/v3/bulk_loads/guess').
170
+ with(:body => original_config.to_json).
171
+ to_return(:status => 500, :body => guessed_config.to_json)
142
172
  expect {
143
- api.bulk_load_guess(config)
144
- }.to raise_error(ArgumentError)
173
+ api.bulk_load_guess(
174
+ original_config
175
+ )
176
+ }.to raise_error(TreasureData::APIError)
145
177
  end
146
178
 
147
179
  it 'perform redo on 500 error' do
@@ -150,7 +182,7 @@ describe 'BulkImport API' do
150
182
  to_return(:status => 500, :body => guessed_config.to_json)
151
183
  begin
152
184
  retry_api.bulk_load_guess(
153
- TreasureData::API::BulkLoad::BulkLoad.from_hash(original_config)
185
+ original_config
154
186
  ).should != nil
155
187
  rescue TreasureData::APIError => e
156
188
  e.message.should =~ /^500: BulkLoad configuration guess failed/
@@ -162,7 +194,7 @@ describe 'BulkImport API' do
162
194
  api.instance_eval { @api }.stub(:post).and_raise(SocketError.new('>>'))
163
195
  begin
164
196
  retry_api.bulk_load_guess(
165
- TreasureData::API::BulkLoad::BulkLoad.from_hash(original_config)
197
+ original_config
166
198
  )
167
199
  rescue SocketError => e
168
200
  e.message.should == '>> (Retried 1 times in 1 seconds)'
@@ -176,8 +208,8 @@ describe 'BulkImport API' do
176
208
  with(:body => guessed_config.to_json).
177
209
  to_return(:body => preview_result.to_json)
178
210
  api.bulk_load_preview(
179
- TreasureData::API::BulkLoad::BulkLoad.from_hash(guessed_config)
180
- ).to_h.should == preview_result
211
+ guessed_config
212
+ ).should == preview_result
181
213
  end
182
214
 
183
215
  it 'raises an error' do
@@ -186,17 +218,10 @@ describe 'BulkImport API' do
186
218
  to_return(:status => 500, :body => preview_result.to_json)
187
219
  expect {
188
220
  api.bulk_load_preview(
189
- TreasureData::API::BulkLoad::BulkLoad.from_hash(guessed_config)
221
+ guessed_config
190
222
  )
191
223
  }.to raise_error(TreasureData::APIError)
192
224
  end
193
-
194
- it 'raises on validation error' do
195
- config = TreasureData::API::BulkLoad::BulkLoad.from_hash({})
196
- expect {
197
- api.bulk_load_preview(config)
198
- }.to raise_error(ArgumentError)
199
- end
200
225
  end
201
226
 
202
227
  describe 'issue' do
@@ -210,16 +235,9 @@ describe 'BulkImport API' do
210
235
  api.bulk_load_issue(
211
236
  'database',
212
237
  'table',
213
- TreasureData::API::BulkLoad::BulkLoad.from_hash(guessed_config)
238
+ guessed_config
214
239
  ).should == '12345'
215
240
  end
216
-
217
- it 'raises on validation error' do
218
- config = TreasureData::API::BulkLoad::BulkLoad.from_hash({})
219
- expect {
220
- api.bulk_load_issue(config)
221
- }.to raise_error(ArgumentError)
222
- end
223
241
  end
224
242
 
225
243
  describe 'list' do
@@ -228,7 +246,7 @@ describe 'BulkImport API' do
228
246
  to_return(:body => [bulk_load_session, bulk_load_session].to_json)
229
247
  result = api.bulk_load_list
230
248
  result.size.should == 2
231
- result.first.to_h.should == bulk_load_session
249
+ result.first.should == bulk_load_session
232
250
  end
233
251
 
234
252
  it 'returns empty' do
@@ -254,13 +272,13 @@ describe 'BulkImport API' do
254
272
  'nahi_test_1',
255
273
  'database',
256
274
  'table',
257
- TreasureData::API::BulkLoad::BulkLoad.from_hash(guessed_config),
275
+ guessed_config,
258
276
  {
259
277
  cron: '@daily',
260
278
  timezone: 'Asia/Tokyo',
261
279
  delay: 3600
262
280
  }
263
- ).to_h.should == bulk_load_session
281
+ ).should == bulk_load_session
264
282
  end
265
283
 
266
284
  it 'accepts empty option' do
@@ -275,8 +293,8 @@ describe 'BulkImport API' do
275
293
  'nahi_test_1',
276
294
  'database',
277
295
  'table',
278
- TreasureData::API::BulkLoad::BulkLoad.from_hash(guessed_config)
279
- ).to_h.should == bulk_load_session
296
+ guessed_config
297
+ ).should == bulk_load_session
280
298
  end
281
299
 
282
300
  it 'accepts time_column option' do
@@ -292,11 +310,11 @@ describe 'BulkImport API' do
292
310
  'nahi_test_1',
293
311
  'database',
294
312
  'table',
295
- TreasureData::API::BulkLoad::BulkLoad.from_hash(guessed_config),
313
+ guessed_config,
296
314
  {
297
315
  time_column: 'c0'
298
316
  }
299
- ).to_h.should == bulk_load_session
317
+ ).should == bulk_load_session
300
318
  end
301
319
  end
302
320
 
@@ -304,7 +322,7 @@ describe 'BulkImport API' do
304
322
  it 'returns bulk_load_session' do
305
323
  stub_api_request(:get, '/v3/bulk_loads/nahi_test_1').
306
324
  to_return(:body => bulk_load_session.to_json)
307
- api.bulk_load_show('nahi_test_1').to_h.should == bulk_load_session
325
+ api.bulk_load_show('nahi_test_1').should == bulk_load_session
308
326
  end
309
327
  end
310
328
 
@@ -315,8 +333,8 @@ describe 'BulkImport API' do
315
333
  to_return(:body => bulk_load_session.to_json)
316
334
  api.bulk_load_update(
317
335
  'nahi_test_1',
318
- TreasureData::API::BulkLoad::BulkLoad.from_hash(bulk_load_session)
319
- ).to_h.should == bulk_load_session
336
+ bulk_load_session
337
+ ).should == bulk_load_session
320
338
  end
321
339
  end
322
340
 
@@ -324,7 +342,7 @@ describe 'BulkImport API' do
324
342
  it 'returns updated bulk_load_session' do
325
343
  stub_api_request(:delete, '/v3/bulk_loads/nahi_test_1').
326
344
  to_return(:body => bulk_load_session.to_json)
327
- api.bulk_load_delete('nahi_test_1').to_h.should == bulk_load_session
345
+ api.bulk_load_delete('nahi_test_1').should == bulk_load_session
328
346
  end
329
347
  end
330
348
 
@@ -334,7 +352,7 @@ describe 'BulkImport API' do
334
352
  to_return(:body => [bulk_load_job, bulk_load_job].to_json)
335
353
  result = api.bulk_load_history('nahi_test_1')
336
354
  result.size.should == 2
337
- result.first.to_h.should == bulk_load_job
355
+ result.first.should == bulk_load_job
338
356
  end
339
357
  end
340
358
 
@@ -30,7 +30,8 @@ describe 'Job API' do
30
30
 
31
31
  jobs = api.list_jobs
32
32
  jobs[i..i].map {|job_id, type, status, query, start_at, end_at, cpu_time,
33
- result_size, result_url, priority, retry_limit, org, db|
33
+ result_size, result_url, priority, retry_limit, org, db,
34
+ duration|
34
35
  job_id.should == job['job_id']
35
36
  type.should == job['type']
36
37
  status.should == job['status']
@@ -44,6 +45,7 @@ describe 'Job API' do
44
45
  retry_limit.should == job['retry_limit']
45
46
  org.should == job['organization']
46
47
  db.should == job['database']
48
+ duration.should == job['duration']
47
49
  }
48
50
  end
49
51
  }
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'td/client/spec_resources'
3
+
4
+ describe 'Job Model' do
5
+ include_context 'spec symbols'
6
+ include_context 'common helper'
7
+ include_context 'job resources'
8
+
9
+ before do
10
+ stub_api_request(:post, "/v3/user/authenticate").
11
+ to_return(:body => {'apikey' => 'apikey'}.to_json)
12
+ end
13
+
14
+ describe '#client' do
15
+ subject do
16
+ Job.new(client, *arguments).client
17
+ end
18
+
19
+ let :client do
20
+ Client.authenticate('user', 'password')
21
+ end
22
+
23
+ let :arguments do
24
+ job_attributes = raw_jobs.first
25
+ [
26
+ 'job_id', 'type', 'query', 'status', 'url', 'debug',
27
+ 'start_at', 'end_at', 'cpu_time', 'result_size', 'result', 'result_url',
28
+ 'hive_result_schema', 'priority', 'retry_limit', 'org_name', 'db_name',
29
+ 'duration'
30
+ ].map {|name| job_attributes[name]}
31
+ end
32
+
33
+ it 'returns Job object having client' do
34
+ expect(subject).to eq client
35
+ end
36
+ end
37
+ end
@@ -85,6 +85,7 @@ shared_context 'job resources' do
85
85
  "cpu_time" => i * 100 + i,
86
86
  "result_size" => i * 1000,
87
87
  'retry_limit' => 10,
88
+ "duration" => i,
88
89
  'organization' => nil,
89
90
  'hive_result_schema' => nil,
90
91
  'debug' => {
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'td/client/spec_resources'
3
+
4
+ describe 'Command' do
5
+ include_context 'spec symbols'
6
+ include_context 'common helper'
7
+ include_context 'job resources'
8
+
9
+ before do
10
+ stub_api_request(:post, "/v3/user/authenticate").
11
+ to_return(:body => {'apikey' => 'apikey'}.to_json)
12
+ end
13
+
14
+ let :client do
15
+ Client.authenticate('user', 'password')
16
+ end
17
+
18
+ describe '#job' do
19
+ before do
20
+ stub_api_request(:get, "/v3/job/list").to_return(:body => {'jobs' => raw_jobs}.to_json)
21
+ end
22
+
23
+ it 'return jobs created with API result' do
24
+ jobs = client.jobs
25
+
26
+ expect(jobs).to be_kind_of Array
27
+ jobs.each.with_index do |job, i|
28
+ expect(job.job_id).to eq raw_jobs[i]['job_id']
29
+ expect(job.type).to eq raw_jobs[i]['type']
30
+ expect(job.status).to eq raw_jobs[i]['status']
31
+ expect(job.query).to eq raw_jobs[i]['query']
32
+ expect(job.start_at).to eq Time.parse(raw_jobs[i]['start_at'])
33
+ expect(job.end_at).to eq Time.parse(raw_jobs[i]['end_at'])
34
+ expect(job.cpu_time).to eq raw_jobs[i]['cpu_time']
35
+ expect(job.result_size).to eq raw_jobs[i]['result_size']
36
+ expect(job.result_url).to eq raw_jobs[i]['result_url']
37
+ expect(job.priority).to eq raw_jobs[i]['priority']
38
+ expect(job.retry_limit).to eq raw_jobs[i]['retry_limit']
39
+ expect(job.org_name).to eq raw_jobs[i]['organization']
40
+ expect(job.db_name).to eq raw_jobs[i]['database']
41
+ expect(job.duration).to eq raw_jobs[i]['duration']
42
+ end
43
+ end
44
+ end
45
+ 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.69
4
+ version: 0.8.70
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-04-16 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -223,7 +223,6 @@ files:
223
223
  - lib/td/client/api/schedule.rb
224
224
  - lib/td/client/api/server_status.rb
225
225
  - lib/td/client/api/table.rb
226
- - lib/td/client/api/to_hash_struct.rb
227
226
  - lib/td/client/api/user.rb
228
227
  - lib/td/client/api_error.rb
229
228
  - lib/td/client/compat_gzip_reader.rb
@@ -241,6 +240,7 @@ files:
241
240
  - spec/td/client/export_api_spec.rb
242
241
  - spec/td/client/import_api_spec.rb
243
242
  - spec/td/client/job_api_spec.rb
243
+ - spec/td/client/model_job_spec.rb
244
244
  - spec/td/client/partial_delete_api_spec.rb
245
245
  - spec/td/client/result_api_spec.rb
246
246
  - spec/td/client/sched_api_spec.rb
@@ -249,6 +249,7 @@ files:
249
249
  - spec/td/client/table_api_spec.rb
250
250
  - spec/td/client/user_api_spec.rb
251
251
  - spec/td/client_sched_spec.rb
252
+ - spec/td/client_spec.rb
252
253
  homepage: http://treasuredata.com/
253
254
  licenses: []
254
255
  metadata: {}
@@ -283,6 +284,7 @@ test_files:
283
284
  - spec/td/client/export_api_spec.rb
284
285
  - spec/td/client/import_api_spec.rb
285
286
  - spec/td/client/job_api_spec.rb
287
+ - spec/td/client/model_job_spec.rb
286
288
  - spec/td/client/partial_delete_api_spec.rb
287
289
  - spec/td/client/result_api_spec.rb
288
290
  - spec/td/client/sched_api_spec.rb
@@ -290,4 +292,5 @@ test_files:
290
292
  - spec/td/client/table_api_spec.rb
291
293
  - spec/td/client/user_api_spec.rb
292
294
  - spec/td/client_sched_spec.rb
295
+ - spec/td/client_spec.rb
293
296
  has_rdoc: false
@@ -1,82 +0,0 @@
1
- class TreasureData::API
2
- class ToHashStruct < Struct
3
- module ClassModule
4
- def parse_json(body)
5
- begin
6
- js = JSON.load(body)
7
- rescue
8
- raise "Unexpected API response: #{$!}"
9
- end
10
- unless js.is_a?(Hash)
11
- raise "Unexpected API response: #{body}"
12
- end
13
- js
14
- end
15
-
16
- def from_json(json)
17
- from_hash(parse_json(json))
18
- end
19
-
20
- def from_hash(hash)
21
- return new if hash.nil?
22
- new(*members.map { |sym|
23
- v = hash[sym] || hash[sym.to_s]
24
- model.key?(sym) ? model[sym].from_hash(v) : v
25
- })
26
- end
27
-
28
- def model_property(key, klass)
29
- model[key.to_sym] = klass
30
- end
31
-
32
- def model
33
- @model ||= {}
34
- end
35
- end
36
- extend ClassModule
37
-
38
- def to_h
39
- self.class.members.inject({}) { |r, e|
40
- v = obj_to_h(self[e])
41
- r[e.to_s] = v unless v.nil?
42
- r
43
- }
44
- end
45
-
46
- def to_json
47
- to_h.to_json
48
- end
49
-
50
- def validate
51
- validate_self
52
- values.each do |v|
53
- v.validate if v.is_a?(ToHashStruct)
54
- end
55
- self
56
- end
57
-
58
- def validate_self
59
- # define as required
60
- end
61
-
62
- private
63
-
64
- def validate_presence_of(key)
65
- unless self.send(key)
66
- raise ArgumentError.new("#{key} required")
67
- end
68
- end
69
-
70
- def obj_to_h(obj)
71
- if obj.nil?
72
- nil
73
- elsif Array === obj
74
- obj.map { |e| obj_to_h(e) }
75
- elsif obj.respond_to?(:to_h)
76
- obj.to_h
77
- else
78
- obj
79
- end
80
- end
81
- end
82
- end