td-client 1.0.6 → 1.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 62d7b67418193055ae96afc611d3d60498dc31f2
4
- data.tar.gz: 435833ca652ee44eb037425f6f4b5429d7bc770e
2
+ SHA256:
3
+ metadata.gz: bfa8466ceb0e2dc014d9222e5bb295d7f9102951828531d993f9d92eb6592457
4
+ data.tar.gz: 8521a0ec4855d3d266fceabe8bbb7a42fcf52c38bdf4f6d8e8af96cae97add7f
5
5
  SHA512:
6
- metadata.gz: 60fa14a70c5f1c4692482a9aea14355ddd7ace29da1caadced59b07fa076cd85bff27dbd4e008d3d90bf84c2d2511e497a29c25c7825a4c9afb57423b28799fc
7
- data.tar.gz: 5a50764649b21f4f29a98e527d50c9bf6c7fa7f4887b95e4a14bb7dfb9d304ca52f89aa664c2142033cd34c67a97b2f0b08dc50f471c4c3841170ea3a6e6a4e8
6
+ metadata.gz: 477518baf02db8ec6f126f847d54b2b9fe5885a4bb3c5d6d07dfb4a8110d997ca4288541260932abd0e69dc56c50dd0ed1d62b5fbd9884cc6be10b31329b8440
7
+ data.tar.gz: f13066abdba694a7dd28f3fe67efac2c598f25b67f1fa7948dc85b4cdd6d9c476ea12eddd63b3229cb275ba193cb397f3a803a2c6ccc56cf7c08e56498d93e34
@@ -173,6 +173,14 @@ class Client
173
173
  @api.tail(db_name, table_name, count, to, from, &block)
174
174
  end
175
175
 
176
+ # @param [String] db_name
177
+ # @param [String] table_name
178
+ # @param [String] new_db_name
179
+ # @return [true]
180
+ def change_database(db_name, table_name, new_db_name)
181
+ @api.change_database(db_name, table_name, new_db_name)
182
+ end
183
+
176
184
  # @param [String] db_name
177
185
  # @param [String] q
178
186
  # @param [String] result_url
@@ -140,5 +140,14 @@ module Table
140
140
  end
141
141
  end
142
142
 
143
+ def change_database(db, table, dest_db)
144
+ params = { 'dest_database_name' => dest_db }
145
+ code, body, res = post("/v3/table/change_database/#{e db}/#{e table}", params)
146
+ if code != "200"
147
+ raise_error("Change database failed", res)
148
+ end
149
+ return true
150
+ end
151
+
143
152
  end
144
153
  end
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
  class Client
3
- VERSION = '1.0.6'
3
+ VERSION = '1.0.7'
4
4
  end
5
5
  end
@@ -49,11 +49,7 @@ shared_context 'common helper' do
49
49
  end
50
50
 
51
51
  let :headers do
52
- if RUBY_VERSION >= "2.0.0"
53
- {'Accept' => '*/*', 'Accept-Encoding' => /gzip/, 'Date' => /.*/, 'User-Agent' => /Ruby/}
54
- else
55
- {'Accept' => '*/*', 'Date' => /.*/, 'User-Agent' => /Ruby/}
56
- end
52
+ {'Accept' => '*/*', 'Accept-Encoding' => /gzip/, 'Date' => /.*/, 'User-Agent' => /Ruby/}
57
53
  end
58
54
 
59
55
  def stub_api_request(method, path, opts = nil)
@@ -43,16 +43,13 @@ describe 'API SSL connection' do
43
43
  }.to raise_error OpenSSL::SSL::SSLError
44
44
  end
45
45
 
46
- # 1.8.7's net/http does not call SSLContext#set_params. Use 1.8.7 where you don't care security.
47
- if RUBY_VERSION >= '1.9.0'
48
- it 'should success to connect TLSv1 only server' do
49
- @server = setup_server(:TLSv1)
50
- api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false)
51
- api.ssl_ca_file = File.join(DIR, 'ca-all.cert')
52
- expect {
53
- api.delete_database('no_such_database')
54
- }.to raise_error TreasureData::NotFoundError
55
- end
46
+ it 'should success to connect TLSv1 only server' do
47
+ @server = setup_server(:TLSv1)
48
+ api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false)
49
+ api.ssl_ca_file = File.join(DIR, 'ca-all.cert')
50
+ expect {
51
+ api.delete_database('no_such_database')
52
+ }.to raise_error TreasureData::NotFoundError
56
53
  end
57
54
 
58
55
  def setup_server(ssl_version)
@@ -301,4 +301,43 @@ describe 'Table API' do
301
301
  expect(r.read).to eq(%Q(parameter "to" and "from" no longer work\n))
302
302
  end
303
303
  end
304
+
305
+ describe 'change_database' do
306
+ it 'should change the database belonging to' do
307
+ stub_api_request(:post, "/v3/table/change_database/src_db/table").
308
+ with(:body => {'dest_database_name' => 'dst_db'}).
309
+ to_return(:body => {'database' => 'dst_db', 'table' => 'table', 'type' => 'log'}.to_json)
310
+ expect(api.change_database('src_db', 'table', 'dst_db')).to be true
311
+ end
312
+
313
+ it 'should return 403 error if dest database is inaccessible' do
314
+ err_msg = 'Access denied for the destination'
315
+ stub_api_request(:post, "/v3/table/change_database/src_db/table").
316
+ with(:body => {'dest_database_name' => 'inaccessible_db'}).
317
+ to_return(:status => 403, :body => {'message' => err_msg}.to_json)
318
+ expect {
319
+ api.change_database('src_db', 'table', 'inaccessible_db')
320
+ }.to raise_error(TreasureData::ForbiddenError, /#{err_msg}/)
321
+ end
322
+
323
+ it 'should return 403 error if there is a same name table in the dest database' do
324
+ err_msg = 'Table table already exists in the destination'
325
+ stub_api_request(:post, "/v3/table/change_database/src_db/table").
326
+ with(:body => {'dest_database_name' => 'dst_db'}).
327
+ to_return(:status => 403, :body => {'message' => err_msg}.to_json)
328
+ expect {
329
+ api.change_database('src_db', 'table', 'dst_db')
330
+ }.to raise_error(TreasureData::ForbiddenError, /#{err_msg}/)
331
+ end
332
+
333
+ it 'should return 404 error if the dest database does not exist' do
334
+ err_msg = 'Destination database is not found'
335
+ stub_api_request(:post, "/v3/table/change_database/src_db/table").
336
+ with(:body => {'dest_database_name' => 'notexist_db'}).
337
+ to_return(:status => 404, :body => {'message' => err_msg}.to_json)
338
+ expect {
339
+ api.change_database('src_db', 'table', 'notexist_db')
340
+ }.to raise_error(TreasureData::NotFoundError, /#{err_msg}/)
341
+ end
342
+ end
304
343
  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: 1.0.6
4
+ version: 1.0.7
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: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2019-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -198,8 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  requirements: []
201
- rubyforge_project:
202
- rubygems_version: 2.6.13
201
+ rubygems_version: 3.0.0.beta3
203
202
  signing_key:
204
203
  specification_version: 4
205
204
  summary: Treasure Data API library for Ruby