td-client 0.8.67 → 0.8.68

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,4 +51,27 @@ describe 'Result API' do
51
51
  }.to raise_error(TreasureData::APIError, /#{err_msg}/)
52
52
  end
53
53
  end
54
+
55
+ describe 'list_result' do
56
+ it 'should return name and url' do
57
+ stub_api_request(:get, '/v3/result/list').
58
+ to_return(:body => {'results' => [{'name' => 'name', 'url' => 'url'}]}.to_json)
59
+ api.list_result.should == [['name', 'url', nil]]
60
+ end
61
+ end
62
+
63
+ describe 'delete_result' do
64
+ it 'should delete the result' do
65
+ stub_api_request(:post, "/v3/result/delete/#{e(result_name)}")
66
+ api.delete_result(result_name).should == true
67
+ end
68
+
69
+ it 'should raise error' do
70
+ stub_api_request(:post, "/v3/result/delete/#{e(result_name)}").
71
+ to_return(:status => 404)
72
+ expect {
73
+ api.delete_result(result_name)
74
+ }.to raise_error(TreasureData::APIError)
75
+ end
76
+ end
54
77
  end
@@ -36,6 +36,14 @@ describe 'Schedule API' do
36
36
  end
37
37
  end
38
38
 
39
+ describe 'delete_schedule' do
40
+ it 'should delete the schedule' do
41
+ stub_api_request(:post, "/v3/schedule/delete/#{e(sched_name)}").
42
+ to_return(:body => {'cron' => 'cron', 'query' => 'query'}.to_json)
43
+ api.delete_schedule(sched_name).should == ['cron', 'query']
44
+ end
45
+ end
46
+
39
47
  describe 'update_schedule' do
40
48
  let :pig_query do
41
49
  "OUT = FOREACH (GROUP plt364 ALL) GENERATE COUNT(plt364);\n" * 200
@@ -65,4 +73,29 @@ describe 'Schedule API' do
65
73
  expect(api.list_schedules.first[2]).to eq(pig_query)
66
74
  end
67
75
  end
76
+
77
+ describe 'history' do
78
+ let :history do
79
+ ['history', 'job_id', 'type', 'database', 'status', 'query', 'start_at', 'end_at', 'result', 'priority'].inject({}) { |r, e|
80
+ r[e] = e
81
+ r
82
+ }
83
+ end
84
+
85
+ it 'should return history records' do
86
+ stub_api_request(:get, "/v3/schedule/history/#{e(sched_name)}").
87
+ with(:query => {'from' => 0, 'to' => 100}).
88
+ to_return(:body => {'history' => [history]}.to_json)
89
+ api.history(sched_name, 0, 100).should == [[nil, 'job_id', :type, 'status', 'query', 'start_at', 'end_at', 'result', 'priority', 'database']]
90
+ end
91
+ end
92
+
93
+ describe 'run_schedule' do
94
+ it 'should return history records' do
95
+ stub_api_request(:post, "/v3/schedule/run/#{e(sched_name)}/123456789").
96
+ with(:body => {'num' => '5'}).
97
+ to_return(:body => {'jobs' => [{'job_id' => 'job_id', 'scheduled_at' => 'scheduled_at', 'type' => 'type'}]}.to_json)
98
+ api.run_schedule(sched_name, 123456789, 5).should == [['job_id', :type, 'scheduled_at']]
99
+ end
100
+ end
68
101
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'td/client/spec_resources'
3
+
4
+ describe 'ServerStatus API' do
5
+ include_context 'spec symbols'
6
+ include_context 'common helper'
7
+
8
+ let :api do
9
+ API.new(nil, {:max_cumul_retry_delay => -1})
10
+ end
11
+
12
+ describe 'server_status' do
13
+ it 'returns status' do
14
+ stub_api_request(:get, '/v3/system/server_status').
15
+ to_return(:body => {'status' => 'OK'}.to_json)
16
+ api.server_status.should == 'OK'
17
+ end
18
+
19
+ it 'returns error description' do
20
+ stub_api_request(:get, '/v3/system/server_status').
21
+ to_return(:status => 500)
22
+ api.server_status.should == 'Server is down (500)'
23
+ end
24
+ end
25
+ end
@@ -162,4 +162,49 @@ describe 'Table API' do
162
162
  expect(table.updated_at).to eq(Time.parse(tables[i][5]))
163
163
  end
164
164
  end
165
+
166
+ describe 'swap_table' do
167
+ it 'should swap tables' do
168
+ stub_api_request(:post, '/v3/table/swap/db/table1/table2')
169
+ api.swap_table('db', 'table1', 'table2').should == true
170
+ end
171
+ end
172
+
173
+ describe 'update_expire' do
174
+ it 'should update expiry days' do
175
+ stub_api_request(:post, '/v3/table/update/db/table').
176
+ with(:body => {'expire_days' => '5'}).
177
+ to_return(:body => {'type' => 'type'}.to_json)
178
+ api.update_expire('db', 'table', 5).should == true
179
+ end
180
+ end
181
+
182
+ describe 'tail' do
183
+ let :packed do
184
+ s = StringIO.new
185
+ pk = MessagePack::Packer.new(s)
186
+ pk.write([1, 2, 3])
187
+ pk.write([4, 5, 6])
188
+ pk.flush
189
+ s.string
190
+ end
191
+
192
+ it 'yields row if block given' do
193
+ stub_api_request(:get, '/v3/table/tail/db/table').
194
+ with(:query => {'format' => 'msgpack', 'count' => '10', 'from' => '0', 'to' => '100'}).
195
+ to_return(:body => packed)
196
+ result = []
197
+ api.tail('db', 'table', 10, 100, 0) do |row|
198
+ result << row
199
+ end
200
+ result.should == [[1, 2, 3], [4, 5, 6]]
201
+ end
202
+
203
+ it 'returns rows' do
204
+ stub_api_request(:get, '/v3/table/tail/db/table').
205
+ with(:query => {'format' => 'msgpack', 'count' => '10', 'from' => '0', 'to' => '100'}).
206
+ to_return(:body => packed)
207
+ api.tail('db', 'table', 10, 100, 0).should == [[1, 2, 3], [4, 5, 6]]
208
+ end
209
+ end
165
210
  end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+ require 'td/client/spec_resources'
3
+ require 'json'
4
+
5
+ describe 'User API' do
6
+ include_context 'spec symbols'
7
+ include_context 'common helper'
8
+
9
+ let :api do
10
+ API.new(nil)
11
+ end
12
+
13
+ describe 'authenticate' do
14
+ it 'returns apikey' do
15
+ stub_api_request(:post, "/v3/user/authenticate").
16
+ to_return(:body => {'apikey' => 'apikey'}.to_json)
17
+ api.authenticate('user', 'password').should == 'apikey'
18
+ end
19
+
20
+ it 'raises AuthError for authentication failure' do
21
+ stub_api_request(:post, "/v3/user/authenticate").
22
+ to_return(:status => 400, :body => {'apikey' => 'apikey'}.to_json)
23
+ expect {
24
+ api.authenticate('user', 'password')
25
+ }.to raise_error(TreasureData::AuthError)
26
+ end
27
+
28
+ it 'raises APIError for other error' do
29
+ stub_api_request(:post, "/v3/user/authenticate").
30
+ to_return(:status => 500, :body => {'apikey' => 'apikey'}.to_json)
31
+ expect {
32
+ api.authenticate('user', 'password')
33
+ }.to raise_error(TreasureData::APIError)
34
+ end
35
+ end
36
+
37
+ describe 'list_users' do
38
+ it 'returns users' do
39
+ stub_api_request(:get, "/v3/user/list").
40
+ to_return(:body => {'users' => [{'name' => 'name1', 'email' => 'email1'}, {'name' => 'name2', 'email' => 'email2'}]}.to_json)
41
+ api.list_users.should == [
42
+ ['name1', nil, nil, 'email1'],
43
+ ['name2', nil, nil, 'email2'],
44
+ ]
45
+ end
46
+ end
47
+
48
+ describe 'add_user' do
49
+ it 'runs' do
50
+ stub_api_request(:post, "/v3/user/add/name").to_return(:body => {}.to_json)
51
+ api.add_user('name', "org", 'name+suffix@example.com', 'password').should == true
52
+ end
53
+
54
+ # TODO
55
+ it 'does not escape sp but it must be a bug' do
56
+ stub_api_request(:post, "/v3/user/add/!++++@%23$%25%5E&*()_+%7C~").to_return(:body => {}.to_json)
57
+ api.add_user('! @#$%^&*()_+|~', "org", 'name+suffix@example.com', 'password').should == true
58
+ end
59
+ end
60
+
61
+ describe 'remove_user' do
62
+ it 'runs' do
63
+ stub_api_request(:post, "/v3/user/remove/name").to_return(:body => {}.to_json)
64
+ api.remove_user('name').should == true
65
+ end
66
+ end
67
+
68
+ describe 'change_email' do
69
+ it 'runs' do
70
+ stub_api_request(:post, "/v3/user/email/change/name").
71
+ with(:body => {'email' => 'new@email.com'}).
72
+ to_return(:body => {}.to_json)
73
+ api.change_email('name', 'new@email.com').should == true
74
+ end
75
+ end
76
+
77
+ describe 'list_apikeys' do
78
+ it 'runs' do
79
+ stub_api_request(:get, "/v3/user/apikey/list/name").
80
+ to_return(:body => {'apikeys' => ['key1', 'key2']}.to_json)
81
+ api.list_apikeys('name').should == ['key1', 'key2']
82
+ end
83
+ end
84
+
85
+ describe 'add_apikey' do
86
+ it 'does not return the generated apikey because you can list apikey afterwards' do
87
+ stub_api_request(:post, "/v3/user/apikey/add/name").
88
+ to_return(:body => {'apikey' => 'apikey'}.to_json)
89
+ api.add_apikey('name').should == true
90
+ end
91
+ end
92
+
93
+ describe 'remove_apikey' do
94
+ it 'runs' do
95
+ stub_api_request(:post, "/v3/user/apikey/remove/name").
96
+ to_return(:body => {}.to_json)
97
+ api.remove_apikey('name', 'apikey').should == true
98
+ end
99
+ end
100
+
101
+ describe 'change password' do
102
+ it 'runs' do
103
+ stub_api_request(:post, "/v3/user/password/change/name").
104
+ with(:body => {'password' => 'password'}).
105
+ to_return(:body => {}.to_json)
106
+ api.change_password('name', 'password').should == true
107
+ end
108
+ end
109
+
110
+ describe 'change my password' do
111
+ it 'runs' do
112
+ stub_api_request(:post, "/v3/user/password/change").
113
+ with(:body => {'old_password' => 'old_password', 'password' => 'password'}).
114
+ to_return(:body => {}.to_json)
115
+ api.change_my_password('old_password', 'password').should == true
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'td/client/spec_resources'
3
+
4
+ describe 'Schedule Command' do
5
+ include_context 'spec symbols'
6
+ include_context 'common helper'
7
+
8
+ let :api do
9
+ API.new(nil)
10
+ end
11
+
12
+ let :client do
13
+ client = TreasureData::Client.new('dummy')
14
+ client.instance_variable_set('@api', api)
15
+ client
16
+ end
17
+
18
+ describe 'history' do
19
+ let :opts do
20
+ {'database' => db_name}
21
+ end
22
+
23
+ let :history do
24
+ ['history', 'scheduled_at', 'job_id', 'type', 'database', 'status', 'query', 'start_at', 'end_at', 'result', 'priority'].inject({}) { |r, e|
25
+ r[e] = e
26
+ r
27
+ }
28
+ end
29
+
30
+ it 'returns scheduled_job' do
31
+ h = history; h['scheduled_at'] = '2015-02-17 14:16:00 +0900'
32
+ stub_api_request(:get, "/v3/schedule/history/#{e(sched_name)}?from=0&to=19").
33
+ to_return(:body => {'count' => 1, 'history' => [h]}.to_json)
34
+
35
+ client.history(sched_name, 0, 19).each do |scheduled_job|
36
+ scheduled_job.scheduled_at.xmlschema.should == '2015-02-17T14:16:00+09:00'
37
+ scheduled_job.job_id.should == 'job_id'
38
+ scheduled_job.status.should == 'status'
39
+ scheduled_job.priority.should == 'priority'
40
+ scheduled_job.result_url.should == 'result'
41
+ end
42
+ end
43
+
44
+ it 'works when scheduled_at == ""' do
45
+ h = history; h['scheduled_at'] = ''
46
+ stub_api_request(:get, "/v3/schedule/history/#{e(sched_name)}?from=0&to=19").
47
+ to_return(:body => {'count' => 1, 'history' => [h]}.to_json)
48
+
49
+ client.history(sched_name, 0, 19).each do |scheduled_job|
50
+ scheduled_job.scheduled_at.should == nil
51
+ end
52
+ end
53
+ end
54
+ 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.67
4
+ version: 0.8.68
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: 2014-12-05 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -72,16 +72,22 @@ dependencies:
72
72
  name: httpclient
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ~>
75
+ - - '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: 2.4.0
78
+ - - <
79
+ - !ruby/object:Gem::Version
80
+ version: 2.6.0
78
81
  type: :runtime
79
82
  prerelease: false
80
83
  version_requirements: !ruby/object:Gem::Requirement
81
84
  requirements:
82
- - - ~>
85
+ - - '>='
83
86
  - !ruby/object:Gem::Version
84
87
  version: 2.4.0
88
+ - - <
89
+ - !ruby/object:Gem::Version
90
+ version: 2.6.0
85
91
  - !ruby/object:Gem::Dependency
86
92
  name: rspec
87
93
  requirement: !ruby/object:Gem::Requirement
@@ -144,25 +150,46 @@ executables: []
144
150
  extensions: []
145
151
  extra_rdoc_files: []
146
152
  files:
153
+ - lib/td/client/api/access_control.rb
154
+ - lib/td/client/api/account.rb
155
+ - lib/td/client/api/bulk_import.rb
156
+ - lib/td/client/api/database.rb
157
+ - lib/td/client/api/export.rb
158
+ - lib/td/client/api/import.rb
159
+ - lib/td/client/api/job.rb
160
+ - lib/td/client/api/partial_delete.rb
161
+ - lib/td/client/api/result.rb
162
+ - lib/td/client/api/schedule.rb
163
+ - lib/td/client/api/server_status.rb
164
+ - lib/td/client/api/table.rb
165
+ - lib/td/client/api/user.rb
147
166
  - lib/td/client/api.rb
167
+ - lib/td/client/api_error.rb
148
168
  - lib/td/client/compat_gzip_reader.rb
149
169
  - lib/td/client/model.rb
150
170
  - lib/td/client/version.rb
151
171
  - lib/td/client.rb
172
+ - lib/td/core_ext/openssl/ssl/sslcontext/set_params.rb
152
173
  - lib/td-client.rb
153
174
  - data/ca-bundle.crt
154
175
  - spec/spec_helper.rb
176
+ - spec/td/client/access_control_api_spec.rb
177
+ - spec/td/client/account_api_spec.rb
155
178
  - spec/td/client/api_spec.rb
156
179
  - spec/td/client/api_ssl_connection_spec.rb
157
180
  - spec/td/client/bulk_import_spec.rb
158
181
  - spec/td/client/db_api_spec.rb
159
182
  - spec/td/client/export_api_spec.rb
183
+ - spec/td/client/import_api_spec.rb
160
184
  - spec/td/client/job_api_spec.rb
161
185
  - spec/td/client/partial_delete_api_spec.rb
162
186
  - spec/td/client/result_api_spec.rb
163
187
  - spec/td/client/sched_api_spec.rb
188
+ - spec/td/client/server_status_api_spec.rb
164
189
  - spec/td/client/spec_resources.rb
165
190
  - spec/td/client/table_api_spec.rb
191
+ - spec/td/client/user_api_spec.rb
192
+ - spec/td/client_sched_spec.rb
166
193
  homepage: http://treasuredata.com/
167
194
  licenses: []
168
195
  metadata: {}
@@ -187,13 +214,19 @@ signing_key:
187
214
  specification_version: 4
188
215
  summary: Treasure Data API library for Ruby
189
216
  test_files:
217
+ - spec/td/client/access_control_api_spec.rb
218
+ - spec/td/client/account_api_spec.rb
190
219
  - spec/td/client/api_spec.rb
191
220
  - spec/td/client/api_ssl_connection_spec.rb
192
221
  - spec/td/client/bulk_import_spec.rb
193
222
  - spec/td/client/db_api_spec.rb
194
223
  - spec/td/client/export_api_spec.rb
224
+ - spec/td/client/import_api_spec.rb
195
225
  - spec/td/client/job_api_spec.rb
196
226
  - spec/td/client/partial_delete_api_spec.rb
197
227
  - spec/td/client/result_api_spec.rb
198
228
  - spec/td/client/sched_api_spec.rb
229
+ - spec/td/client/server_status_api_spec.rb
199
230
  - spec/td/client/table_api_spec.rb
231
+ - spec/td/client/user_api_spec.rb
232
+ - spec/td/client_sched_spec.rb