td-client 0.8.68 → 0.8.69

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: a6f4ce3a275f3c038d731feb43dda2ec4cc477e5
4
- data.tar.gz: b6affcd7ad8e6430af814d9459cfbabde9ae50f9
3
+ metadata.gz: cce938755d8baa274b4129395cc3bf025852123d
4
+ data.tar.gz: 251fa5c0007d67a8bcbae03f01f31d7748a2654d
5
5
  SHA512:
6
- metadata.gz: 3127bd887d7fff303cde39f92932d8d9a263cfb37201e3c299a24e53a3767390a70ce4195fe34ce9003ecd815465a0776e3e094cc1c35d3da37f181bc4273c98
7
- data.tar.gz: d002d279379a09a63c10882503cf09f6d25d7e3d12198281c55e82881d8f1ef5a7e2ca2af3cb66856b89d8056667da7003a5172f91d424e87fba8a1c625ddcdf
6
+ metadata.gz: ebe285884532e4683d0ca58db039433d5f53fd5cf047db0318ceb93230f0bf0b151fd1f5bd321bbfc55f23784ecd4650764fa57019ec3b6e8d8762a74b6486e1
7
+ data.tar.gz: d37ce150f9a65d5d5a5231c4d277cd1867f193e0c9dec8c5920424faa67acfa75ff5e0e114130156ebc6db991af4eb58b6095784c5afc8cb0124724180ffb687
data/lib/td/client.rb CHANGED
@@ -5,53 +5,70 @@ require 'td/client/model'
5
5
 
6
6
 
7
7
  class Client
8
+ # @param [String] user TreasureData username
9
+ # @param [String] password TreasureData password
10
+ # @param [Hash] opts options for API
11
+ # @return [Client] instance of this class
8
12
  def self.authenticate(user, password, opts={})
9
13
  api = API.new(nil, opts)
10
14
  apikey = api.authenticate(user, password)
11
15
  new(apikey)
12
16
  end
13
17
 
18
+ # @param [Hash] opts options for API
19
+ # @return [String] HTTP status code of server returns
14
20
  def self.server_status(opts={})
15
21
  api = API.new(nil, opts)
16
22
  api.server_status
17
23
  end
18
24
 
25
+ # @param [String] apikey TreasureData API key
26
+ # @param [Hash] opts options for API
19
27
  def initialize(apikey, opts={})
20
28
  @api = API.new(apikey, opts)
21
29
  end
22
30
 
31
+ # @!attribute [r] api
23
32
  attr_reader :api
24
33
 
34
+ # @return [String] API key
25
35
  def apikey
26
36
  @api.apikey
27
37
  end
28
38
 
39
+ # @return [String] HTTP status code of server returns
29
40
  def server_status
30
41
  @api.server_status
31
42
  end
32
43
 
33
- # => true
44
+ # @param [String] db_name
45
+ # @param [Hash] opts
46
+ # @return [true]
34
47
  def create_database(db_name, opts={})
35
48
  @api.create_database(db_name, opts)
36
49
  end
37
50
 
38
- # => true
51
+ # @param [String] db_name
52
+ # @return [Symbol]
39
53
  def delete_database(db_name)
40
54
  @api.delete_database(db_name)
41
55
  end
42
56
 
43
- # => Account
57
+ # @return [Account]
44
58
  def account
45
59
  account_id, plan, storage, guaranteed_cores, maximum_cores, created_at = @api.show_account
46
60
  return Account.new(self, account_id, plan, storage, guaranteed_cores, maximum_cores, created_at)
47
61
  end
48
62
 
63
+ # @param [Fixnum] from
64
+ # @param [Fixnum] to
65
+ # @return [Array] from, to, interval, history
49
66
  def core_utilization(from, to)
50
67
  from, to, interval, history = @api.account_core_utilization(from, to)
51
68
  return from, to, interval, history
52
69
  end
53
70
 
54
- # => [Database]
71
+ # @return [Array] databases
55
72
  def databases
56
73
  m = @api.list_databases
57
74
  m.map {|db_name,(count, created_at, updated_at, org, permission)|
@@ -59,7 +76,8 @@ class Client
59
76
  }
60
77
  end
61
78
 
62
- # => Database
79
+ # @param [String] db_name
80
+ # @return [Database]
63
81
  def database(db_name)
64
82
  m = @api.list_databases
65
83
  m.each {|name,(count, created_at, updated_at, org, permission)|
@@ -70,37 +88,55 @@ class Client
70
88
  raise NotFoundError, "Database '#{db_name}' does not exist"
71
89
  end
72
90
 
73
- # => true
91
+ # @return [true]
74
92
  def create_log_table(db_name, table_name)
75
93
  @api.create_log_table(db_name, table_name)
76
94
  end
77
95
 
78
- # => true
96
+ # @param [String] db_name
97
+ # @param [String] table_name
98
+ # @param [String] primary_key
99
+ # @param [String] primary_key_type
100
+ # @return [true]
79
101
  def create_item_table(db_name, table_name, primary_key, primary_key_type)
80
102
  @api.create_item_table(db_name, table_name, primary_key, primary_key_type)
81
103
  end
82
104
 
83
- # => true
105
+ # Swap table names
106
+ #
107
+ # @param [String] db_name
108
+ # @param [String] table_name1
109
+ # @param [String] table_name2
110
+ # @return [true]
84
111
  def swap_table(db_name, table_name1, table_name2)
85
112
  @api.swap_table(db_name, table_name1, table_name2)
86
113
  end
87
114
 
88
- # => true
115
+ # @param [String] db_name
116
+ # @param [String] table_name
117
+ # @param [String] schema
118
+ # @return [true]
89
119
  def update_schema(db_name, table_name, schema)
90
120
  @api.update_schema(db_name, table_name, schema.to_json)
91
121
  end
92
122
 
93
- # => true
123
+ # @param [String] db_name
124
+ # @param [String] table_name
125
+ # @param [Fixnum] expire_days
126
+ # @return [true]
94
127
  def update_expire(db_name, table_name, expire_days)
95
128
  @api.update_expire(db_name, table_name, expire_days)
96
129
  end
97
130
 
98
- # => type:Symbol
131
+ # @param [String] db_name
132
+ # @param [String] table_name
133
+ # @return [Symbol]
99
134
  def delete_table(db_name, table_name)
100
135
  @api.delete_table(db_name, table_name)
101
136
  end
102
137
 
103
- # => [Table]
138
+ # @param [String] db_name
139
+ # @return [Array] Tables
104
140
  def tables(db_name)
105
141
  m = @api.list_tables(db_name)
106
142
  m.map {|table_name, (type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days, primary_key, primary_key_type)|
@@ -110,7 +146,9 @@ class Client
110
146
  }
111
147
  end
112
148
 
113
- # => Table
149
+ # @param [String] db_name
150
+ # @param [String] table_name
151
+ # @return [Table]
114
152
  def table(db_name, table_name)
115
153
  tables(db_name).each {|t|
116
154
  if t.name == table_name
@@ -120,11 +158,24 @@ class Client
120
158
  raise NotFoundError, "Table '#{db_name}.#{table_name}' does not exist"
121
159
  end
122
160
 
161
+ # @param [String] db_name
162
+ # @param [String] table_name
163
+ # @param [Fixnum] count
164
+ # @param [Fixnum] to
165
+ # @param [Fixnum] from
166
+ # @param [Proc] block
167
+ # @return [Array, nil]
123
168
  def tail(db_name, table_name, count, to=nil, from=nil, &block)
124
169
  @api.tail(db_name, table_name, count, to, from, &block)
125
170
  end
126
171
 
127
- # => Job
172
+ # @param [String] db_name
173
+ # @param [String] q
174
+ # @param [String] result_url
175
+ # @param [Fixnum] priority
176
+ # @param [Fixnum] retry_limit
177
+ # @param [Hash] opts
178
+ # @return [Job]
128
179
  def query(db_name, q, result_url=nil, priority=nil, retry_limit=nil, opts={})
129
180
  # for compatibility, assume type is hive unless specifically specified
130
181
  type = opts[:type] || opts['type'] || :hive
@@ -133,7 +184,11 @@ class Client
133
184
  Job.new(self, job_id, type, q)
134
185
  end
135
186
 
136
- # => [Job]
187
+ # @param [Fixnum] from
188
+ # @param [Fixnum] to
189
+ # @param [String] status
190
+ # @param [Hash] conditions
191
+ # @return [Job]
137
192
  def jobs(from=nil, to=nil, status=nil, conditions=nil)
138
193
  results = @api.list_jobs(from, to, status, conditions)
139
194
  results.map {|job_id, type, status, query, start_at, end_at, cpu_time,
@@ -143,7 +198,8 @@ class Client
143
198
  }
144
199
  end
145
200
 
146
- # => Job
201
+ # @param [String] job_id
202
+ # @return [Job]
147
203
  def job(job_id)
148
204
  job_id = job_id.to_s
149
205
  type, query, status, url, debug, start_at, end_at, cpu_time,
@@ -152,112 +208,154 @@ class Client
152
208
  result_size, nil, result_url, hive_result_schema, priority, retry_limit, org, db)
153
209
  end
154
210
 
155
- # => status:String
211
+ # @param [String] job_id
212
+ # @return [String] HTTP status code
156
213
  def job_status(job_id)
157
214
  return @api.job_status(job_id)
158
215
  end
159
216
 
160
- # => result:[{column:String=>value:Object]
217
+ # @param [String] job_id
218
+ # @return [Object]
161
219
  def job_result(job_id)
162
220
  @api.job_result(job_id)
163
221
  end
164
222
 
165
- # => result:String
223
+ # @param [String] job_id
224
+ # @param [String] format
225
+ # @param [IO] io
226
+ # @param [Proc] block
227
+ # @return [String]
166
228
  def job_result_format(job_id, format, io=nil, &block)
167
229
  @api.job_result_format(job_id, format, io, &block)
168
230
  end
169
231
 
170
- # => nil
232
+ # @param [String] job_id
233
+ # @param [Proc] block
234
+ # @return [nil]
171
235
  def job_result_each(job_id, &block)
172
236
  @api.job_result_each(job_id, &block)
173
237
  end
174
238
 
175
- # => nil
239
+ # @param [String] job_id
240
+ # @param [Proc] block
241
+ # @return [nil]
176
242
  def job_result_each_with_compr_size(job_id, &block)
177
243
  @api.job_result_each_with_compr_size(job_id, &block)
178
244
  end
179
245
 
180
- # => former_status:String
246
+ # @param [String] job_id
247
+ # @return [String] former_status
181
248
  def kill(job_id)
182
249
  @api.kill(job_id)
183
250
  end
184
251
 
185
- # => Job
252
+ # @param [String] db_name
253
+ # @param [String] table_name
254
+ # @param [String] storage_type
255
+ # @param [Hash] opts
256
+ # @return [Job]
186
257
  def export(db_name, table_name, storage_type, opts={})
187
258
  job_id = @api.export(db_name, table_name, storage_type, opts)
188
259
  Job.new(self, job_id, :export, nil)
189
260
  end
190
261
 
191
- # => Job
262
+ # @param [String] db_name
263
+ # @param [String] table_name
264
+ # @param [Fixnum] to
265
+ # @param [Fixnum] from
266
+ # @param [Hash] opts
267
+ # @return [Job]
192
268
  def partial_delete(db_name, table_name, to, from, opts={})
193
269
  job_id = @api.partial_delete(db_name, table_name, to, from, opts)
194
270
  Job.new(self, job_id, :partialdelete, nil)
195
271
  end
196
272
 
197
- # => nil
273
+ # @param [String] name
274
+ # @param [String] database
275
+ # @param [String] table
276
+ # @param [Hash] opts
277
+ # @return [nil]
198
278
  def create_bulk_import(name, database, table, opts={})
199
279
  @api.create_bulk_import(name, database, table, opts)
200
280
  end
201
281
 
202
- # => nil
282
+ # @param [String] name
283
+ # @return [nil]
203
284
  def delete_bulk_import(name)
204
285
  @api.delete_bulk_import(name)
205
286
  end
206
287
 
207
- # => nil
288
+ # @param [String] name
289
+ # @return [nil]
208
290
  def freeze_bulk_import(name)
209
291
  @api.freeze_bulk_import(name)
210
292
  end
211
293
 
212
- # => nil
294
+ # @param [String] name
295
+ # @return [nil]
213
296
  def unfreeze_bulk_import(name)
214
297
  @api.unfreeze_bulk_import(name)
215
298
  end
216
299
 
217
- # => Job
300
+ # @param [String] name
301
+ # @return [Job]
218
302
  def perform_bulk_import(name)
219
303
  job_id = @api.perform_bulk_import(name)
220
304
  Job.new(self, job_id, :bulk_import, nil)
221
305
  end
222
306
 
223
- # => nil
307
+ # @param [String] name
308
+ # @return [nil]
224
309
  def commit_bulk_import(name)
225
310
  @api.commit_bulk_import(name)
226
311
  end
227
312
 
228
- # => records:[row:Hash]
313
+ # @param [String] name
314
+ # @param [Proc] block
315
+ # @return [Hash]
229
316
  def bulk_import_error_records(name, &block)
230
317
  @api.bulk_import_error_records(name, &block)
231
318
  end
232
319
 
233
- # => BulkImport
320
+ # @param [String] name
321
+ # @return [BulkImport]
234
322
  def bulk_import(name)
235
323
  data = @api.show_bulk_import(name)
236
324
  BulkImport.new(self, data)
237
325
  end
238
326
 
239
- # => [BulkImport]
327
+ # @return [Array<BulkImport>]
240
328
  def bulk_imports
241
329
  @api.list_bulk_imports.map {|data|
242
330
  BulkImport.new(self, data)
243
331
  }
244
332
  end
245
333
 
246
- # => nil
334
+ # @param [String] name
335
+ # @param [String] part_name
336
+ # @param [String, StringIO] stream
337
+ # @param [Fixnum] size
338
+ # @return [nil]
247
339
  def bulk_import_upload_part(name, part_name, stream, size)
248
340
  @api.bulk_import_upload_part(name, part_name, stream, size)
249
341
  end
250
342
 
251
- # => nil
343
+ # @param [String] name
344
+ # @param [String] part_name
345
+ # @return [nil]
252
346
  def bulk_import_delete_part(name, part_name)
253
347
  @api.bulk_import_delete_part(name, part_name)
254
348
  end
255
349
 
350
+ # @param [String] name
351
+ # @return [Array]
256
352
  def list_bulk_import_parts(name)
257
353
  @api.list_bulk_import_parts(name)
258
354
  end
259
355
 
260
- # => first_time:Time
356
+ # @param [String] name
357
+ # @param [Hash] opts
358
+ # @return [Time]
261
359
  def create_schedule(name, opts)
262
360
  raise ArgumentError, "'cron' option is required" unless opts[:cron] || opts['cron']
263
361
  raise ArgumentError, "'query' option is required" unless opts[:query] || opts['query']
@@ -265,12 +363,13 @@ class Client
265
363
  return Time.parse(start)
266
364
  end
267
365
 
268
- # => true
366
+ # @param [String] name
367
+ # @return [Array]
269
368
  def delete_schedule(name)
270
369
  @api.delete_schedule(name)
271
370
  end
272
371
 
273
- # [Schedule]
372
+ # @return [Array<Schedule>]
274
373
  def schedules
275
374
  result = @api.list_schedules
276
375
  result.map {|name,cron,query,database,result_url,timezone,delay,next_time,priority,retry_limit,org_name|
@@ -278,12 +377,18 @@ class Client
278
377
  }
279
378
  end
280
379
 
380
+ # @param [String] name
381
+ # @param [Hash] params
382
+ # @return [nil]
281
383
  def update_schedule(name, params)
282
384
  @api.update_schedule(name, params)
283
385
  nil
284
386
  end
285
387
 
286
- # [ScheduledJob]
388
+ # @param [String] name
389
+ # @param [Fixnum] from
390
+ # @param [Fixnum] to
391
+ # @return [Array<ScheduledJob>]
287
392
  def history(name, from=nil, to=nil)
288
393
  result = @api.history(name, from, to)
289
394
  result.map {|scheduled_at,job_id,type,status,query,start_at,end_at,result_url,priority,database|
@@ -302,7 +407,10 @@ class Client
302
407
  }
303
408
  end
304
409
 
305
- # [ScheduledJob]
410
+ # @param [String] name
411
+ # @param [Fixnum] time UNIX timestamp
412
+ # @param [Fixnum] num
413
+ # @return [Array<ScheduledJob>]
306
414
  def run_schedule(name, time, num)
307
415
  results = @api.run_schedule(name, time, num)
308
416
  results.map {|job_id,type,scheduled_at|
@@ -310,12 +418,18 @@ class Client
310
418
  }
311
419
  end
312
420
 
313
- # => time:Flaot
421
+ # @param [String] db_name
422
+ # @param [String] table_name
423
+ # @param [String] format
424
+ # @param [String, StringIO] stream
425
+ # @param [Fixnum] size
426
+ # @param [String] unique_id
427
+ # @return [Float]
314
428
  def import(db_name, table_name, format, stream, size, unique_id=nil)
315
429
  @api.import(db_name, table_name, format, stream, size, unique_id)
316
430
  end
317
431
 
318
- # => [Result]
432
+ # @return [Array<Result>]
319
433
  def results
320
434
  results = @api.list_result
321
435
  rs = results.map {|name,url,organizations|
@@ -324,17 +438,21 @@ class Client
324
438
  return rs
325
439
  end
326
440
 
327
- # => true
441
+ # @param [String] name
442
+ # @param [String] url
443
+ # @param [Hash] opts
444
+ # @return [true]
328
445
  def create_result(name, url, opts={})
329
446
  @api.create_result(name, url, opts)
330
447
  end
331
448
 
332
- # => true
449
+ # @param [String] name
450
+ # @return [true]
333
451
  def delete_result(name)
334
452
  @api.delete_result(name)
335
453
  end
336
454
 
337
- # => [User]
455
+ # @return [Array<User>]
338
456
  def users
339
457
  list = @api.list_users
340
458
  list.map {|name,org,roles,email|
@@ -342,47 +460,62 @@ class Client
342
460
  }
343
461
  end
344
462
 
345
- # => true
463
+ # @param [String] name
464
+ # @param [String] org
465
+ # @param [String] email
466
+ # @param [String] password
467
+ # @return [true]
346
468
  def add_user(name, org, email, password)
347
469
  @api.add_user(name, org, email, password)
348
470
  end
349
471
 
350
- # => true
472
+ # @param [String] user
473
+ # @return [true]
351
474
  def remove_user(user)
352
475
  @api.remove_user(user)
353
476
  end
354
477
 
355
- # => true
478
+ # @param [String] user
479
+ # @param [String] email
480
+ # @return [true]
356
481
  def change_email(user, email)
357
482
  @api.change_email(user, email)
358
483
  end
359
484
 
360
- # => [apikey:String]
485
+ # @param [String] user
486
+ # @return [Array<String>]
361
487
  def list_apikeys(user)
362
488
  @api.list_apikeys(user)
363
489
  end
364
490
 
365
- # => true
491
+ # @param [String] user
492
+ # @return [true]
366
493
  def add_apikey(user)
367
494
  @api.add_apikey(user)
368
495
  end
369
496
 
370
- # => true
497
+ # @param [String] user
498
+ # @param [String] apikey
499
+ # @return [true]
371
500
  def remove_apikey(user, apikey)
372
501
  @api.remove_apikey(user, apikey)
373
502
  end
374
503
 
375
- # => true
504
+ # @param [String] user
505
+ # @param [String] password
506
+ # @return [true]
376
507
  def change_password(user, password)
377
508
  @api.change_password(user, password)
378
509
  end
379
510
 
380
- # => true
511
+ # @param [String] old_password
512
+ # @param [String] password
513
+ # @return [true]
381
514
  def change_my_password(old_password, password)
382
515
  @api.change_my_password(old_password, password)
383
516
  end
384
517
 
385
- # => [User]
518
+ # @return [Array<AccessControl>]
386
519
  def access_controls
387
520
  list = @api.list_access_controls
388
521
  list.map {|subject,action,scope,grant_option|
@@ -390,20 +523,80 @@ class Client
390
523
  }
391
524
  end
392
525
 
393
- # => true
526
+ # @param [String] subject
527
+ # @param [String] action
528
+ # @param [String] scope
529
+ # @param [Array] grant_option
530
+ # @return [true]
394
531
  def grant_access_control(subject, action, scope, grant_option)
395
532
  @api.grant_access_control(subject, action, scope, grant_option)
396
533
  end
397
534
 
398
- # => true
535
+ # @param [String] subject
536
+ # @param [String] action
537
+ # @param [String] scope
538
+ # @return [true]
399
539
  def revoke_access_control(subject, action, scope)
400
540
  @api.revoke_access_control(subject, action, scope)
401
541
  end
402
542
 
403
- # => true
543
+ # @param [String] user
544
+ # @param [String] action
545
+ # @param [String] scope
546
+ # @return [Array]
404
547
  def test_access_control(user, action, scope)
405
548
  @api.test_access_control(user, action, scope)
406
549
  end
550
+
551
+ # => BulkLoad::Job
552
+ def bulk_load_guess(job)
553
+ @api.bulk_load_guess(job)
554
+ end
555
+
556
+ # => BulkLoad::Job
557
+ def bulk_load_preview(job)
558
+ @api.bulk_load_preview(job)
559
+ end
560
+
561
+ # => String
562
+ def bulk_load_issue(database, table, job)
563
+ @api.bulk_load_issue(database, table, job)
564
+ end
565
+
566
+ # nil -> [BulkLoad]
567
+ def bulk_load_list
568
+ @api.bulk_load_list
569
+ end
570
+
571
+ # name: String, database: String, table: String, job: BulkLoad -> BulkLoad
572
+ def bulk_load_create(name, database, table, job, opts = {})
573
+ @api.bulk_load_create(name, database, table, job, opts)
574
+ end
575
+
576
+ # name: String -> BulkLoad
577
+ def bulk_load_show(name)
578
+ @api.bulk_load_show(name)
579
+ end
580
+
581
+ # name: String, job: BulkLoad -> BulkLoad
582
+ def bulk_load_update(name, job)
583
+ @api.bulk_load_update(name, job)
584
+ end
585
+
586
+ # name: String -> BulkLoad
587
+ def bulk_load_delete(name)
588
+ @api.bulk_load_delete(name)
589
+ end
590
+
591
+ # name: String -> [Job]
592
+ def bulk_load_history(name)
593
+ @api.bulk_load_history(name)
594
+ end
595
+
596
+ def bulk_load_run(name, scheduled_time = nil)
597
+ @api.bulk_load_run(name, scheduled_time)
598
+ end
599
+
407
600
  end
408
601
 
409
602
  end # module TreasureData