td-client 1.0.7 → 1.0.8
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/api.rb +16 -4
- data/lib/td/client/api/import.rb +1 -3
- data/lib/td/client/api_error.rb +32 -8
- data/lib/td/client/version.rb +1 -1
- data/spec/td/client/api_ssl_connection_spec.rb +7 -3
- data/spec/td/client/import_api_spec.rb +14 -14
- data/spec/td/client/model_job_spec.rb +6 -5
- metadata +34 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8650b4fe6267d1edb91dad045ac0b31f77d0d0e37d776ea5433ec88debfe4b81
|
4
|
+
data.tar.gz: baf35bbd09b187c8f76ee48f68328f23ac09721ddb31641154a97900dc4ac93b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 643dc4c3d7ec6e5e73b506f3b18750a7aeaf73e915890c68ccd7b590f8d539a1fb047f5adbb4652bb0a732f2e8466658be112384d9d57aae1cb72b902b8a4b46
|
7
|
+
data.tar.gz: fbf3228a704dd954299becd06462920f72934674d8cae49ba1db91d169441fe4a079348e33ec8f2e3b08c986b5383fbf476f7161de8711a3677583da1b4b3169
|
data/lib/td/client/api.rb
CHANGED
@@ -636,15 +636,27 @@ private
|
|
636
636
|
klass
|
637
637
|
else
|
638
638
|
case status_code
|
639
|
+
when "400"
|
640
|
+
BadRequestError
|
641
|
+
when "401"
|
642
|
+
AuthError
|
643
|
+
when "403"
|
644
|
+
ForbiddenError
|
639
645
|
when "404"
|
640
646
|
NotFoundError
|
647
|
+
when "405"
|
648
|
+
MethodNotAllowedError
|
641
649
|
when "409"
|
642
650
|
message = "#{message}: conflicts_with job:#{error["details"]["conflicts_with"]}" if error["details"] && error["details"]["conflicts_with"]
|
643
651
|
AlreadyExistsError
|
644
|
-
when "
|
645
|
-
|
646
|
-
when "
|
647
|
-
|
652
|
+
when "415"
|
653
|
+
UnsupportedMediaTypeError
|
654
|
+
when "422"
|
655
|
+
UnprocessableEntityError
|
656
|
+
when "429"
|
657
|
+
TooManyRequestsError
|
658
|
+
when /\A4\d\d\z/
|
659
|
+
ClientError
|
648
660
|
else
|
649
661
|
message = "#{status_code}: #{message}"
|
650
662
|
APIError
|
data/lib/td/client/api/import.rb
CHANGED
data/lib/td/client/api_error.rb
CHANGED
@@ -13,16 +13,32 @@ class APIError < StandardError
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
#
|
17
|
-
class
|
16
|
+
# 4xx Client Errors
|
17
|
+
class ClientError < APIError
|
18
18
|
end
|
19
19
|
|
20
|
-
#
|
21
|
-
class
|
20
|
+
# 400 Bad Request
|
21
|
+
class BadRequestError < ClientError
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
25
|
-
class
|
24
|
+
# 401 Unauthorized
|
25
|
+
class AuthError < ClientError
|
26
|
+
end
|
27
|
+
|
28
|
+
# 403 Forbidden, used for database permissions
|
29
|
+
class ForbiddenError < ClientError
|
30
|
+
end
|
31
|
+
|
32
|
+
# 404 Not Found
|
33
|
+
class NotFoundError < ClientError
|
34
|
+
end
|
35
|
+
|
36
|
+
# 405 Method Not Allowed
|
37
|
+
class MethodNotAllowedError < ClientError
|
38
|
+
end
|
39
|
+
|
40
|
+
# 409 Conflict
|
41
|
+
class AlreadyExistsError < ClientError
|
26
42
|
attr_reader :conflicts_with
|
27
43
|
def initialize(error_message = nil, api_backtrace = nil, conflicts_with=nil)
|
28
44
|
super(error_message, api_backtrace)
|
@@ -30,8 +46,16 @@ class AlreadyExistsError < APIError
|
|
30
46
|
end
|
31
47
|
end
|
32
48
|
|
33
|
-
#
|
34
|
-
class
|
49
|
+
# 415 Unsupported Media Type
|
50
|
+
class UnsupportedMediaTypeError < ClientError
|
51
|
+
end
|
52
|
+
|
53
|
+
# 422 Unprocessable Entity
|
54
|
+
class UnprocessableEntityError < ClientError
|
55
|
+
end
|
56
|
+
|
57
|
+
# 429 Too Many Requests
|
58
|
+
class TooManyRequestsError < ClientError
|
35
59
|
end
|
36
60
|
|
37
61
|
end
|
data/lib/td/client/version.rb
CHANGED
@@ -39,7 +39,11 @@ describe 'API SSL connection' do
|
|
39
39
|
api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false)
|
40
40
|
api.ssl_ca_file = File.join(DIR, 'ca-all.cert')
|
41
41
|
expect {
|
42
|
-
|
42
|
+
begin
|
43
|
+
api.delete_database('no_such_database')
|
44
|
+
rescue Errno::ECONNRESET
|
45
|
+
raise OpenSSL::SSL::SSLError # When openssl does not support SSLv3, httpclient server will not start. For context: https://github.com/nahi/httpclient/pull/424#issuecomment-731714786
|
46
|
+
end
|
43
47
|
}.to raise_error OpenSSL::SSL::SSLError
|
44
48
|
end
|
45
49
|
|
@@ -52,13 +56,13 @@ describe 'API SSL connection' do
|
|
52
56
|
}.to raise_error TreasureData::NotFoundError
|
53
57
|
end
|
54
58
|
|
55
|
-
def setup_server(ssl_version)
|
59
|
+
def setup_server(ssl_version, port = 1000 + rand(1000))
|
56
60
|
logger = Logger.new(STDERR)
|
57
61
|
logger.level = Logger::Severity::FATAL # avoid logging SSLError (ERROR level)
|
58
62
|
@server = WEBrick::HTTPServer.new(
|
59
63
|
:BindAddress => "localhost",
|
60
64
|
:Logger => logger,
|
61
|
-
:Port =>
|
65
|
+
:Port => port,
|
62
66
|
:AccessLog => [],
|
63
67
|
:DocumentRoot => '.',
|
64
68
|
:SSLEnable => true,
|
@@ -46,9 +46,9 @@ describe 'Import API' do
|
|
46
46
|
end
|
47
47
|
stub_request(:put, "https://#{endpoint_import}/v3/table/import_with_id/db/table/unique_id/format").
|
48
48
|
with(:body => '12345').
|
49
|
-
to_return(:
|
49
|
+
to_return(:status => 200)
|
50
50
|
File.open(t.path) do |f|
|
51
|
-
expect(api.import('db', 'table', 'format', f, 5, 'unique_id')).to eq(
|
51
|
+
expect(api.import('db', 'table', 'format', f, 5, 'unique_id')).to eq(true)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -59,9 +59,9 @@ describe 'Import API' do
|
|
59
59
|
end
|
60
60
|
stub_request(:put, "https://#{endpoint_import}/v3/table/import/db/table/format").
|
61
61
|
with(:body => '12345').
|
62
|
-
to_return(:
|
62
|
+
to_return(:status => 200)
|
63
63
|
File.open(t.path) do |f|
|
64
|
-
expect(api.import('db', 'table', 'format', f, 5)).to eq(
|
64
|
+
expect(api.import('db', 'table', 'format', f, 5)).to eq(true)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -72,9 +72,9 @@ describe 'Import API' do
|
|
72
72
|
end
|
73
73
|
stub_request(:put, "http://#{endpoint_import_old}/v3/table/import/db/table/format").
|
74
74
|
with(:body => '12345').
|
75
|
-
to_return(:
|
75
|
+
to_return(:status => 200)
|
76
76
|
File.open(t.path) do |f|
|
77
|
-
expect(api_old.import('db', 'table', 'format', f, 5)).to eq(
|
77
|
+
expect(api_old.import('db', 'table', 'format', f, 5)).to eq(true)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -85,9 +85,9 @@ describe 'Import API' do
|
|
85
85
|
end
|
86
86
|
stub_request(:put, "https://#{endpoint_import}/v3/table/import/db/table/format").
|
87
87
|
with(:body => '12345').
|
88
|
-
to_return(:
|
88
|
+
to_return(:status => 200)
|
89
89
|
File.open(t.path) do |f|
|
90
|
-
expect(api_default.import('db', 'table', 'format', f, 5)).to eq
|
90
|
+
expect(api_default.import('db', 'table', 'format', f, 5)).to eq true
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -98,9 +98,9 @@ describe 'Import API' do
|
|
98
98
|
end
|
99
99
|
stub_request(:put, "http://#{endpoint_import}/v3/table/import/db/table/format").
|
100
100
|
with(:body => '12345').
|
101
|
-
to_return(:
|
101
|
+
to_return(:status => 200)
|
102
102
|
File.open(t.path) do |f|
|
103
|
-
expect(api_default_http.import('db', 'table', 'format', f, 5)).to eq
|
103
|
+
expect(api_default_http.import('db', 'table', 'format', f, 5)).to eq true
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -111,9 +111,9 @@ describe 'Import API' do
|
|
111
111
|
end
|
112
112
|
stub_request(:put, "https://#{endpoint_unknown}/v3/table/import/db/table/format").
|
113
113
|
with(:body => '12345').
|
114
|
-
to_return(:
|
114
|
+
to_return(:status => 200)
|
115
115
|
File.open(t.path) do |f|
|
116
|
-
expect(api_unknown_host.import('db', 'table', 'format', f, 5)).to eq
|
116
|
+
expect(api_unknown_host.import('db', 'table', 'format', f, 5)).to eq true
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -124,9 +124,9 @@ describe 'Import API' do
|
|
124
124
|
end
|
125
125
|
stub_request(:put, "http://#{endpoint_unknown}/v3/table/import/db/table/format").
|
126
126
|
with(:body => '12345').
|
127
|
-
to_return(:
|
127
|
+
to_return(:status => 200)
|
128
128
|
File.open(t.path) do |f|
|
129
|
-
expect(api_unknown_host_http.import('db', 'table', 'format', f, 5)).to eq
|
129
|
+
expect(api_unknown_host_http.import('db', 'table', 'format', f, 5)).to eq true
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -140,15 +140,16 @@ describe 'Job Model' do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'calls a given block in every wait_interval second' do
|
143
|
-
|
144
|
-
|
145
|
-
allow(
|
143
|
+
# Let's try disable stubbing #sleep for now
|
144
|
+
# now = 1_400_000_000
|
145
|
+
# allow(self).to receive(:sleep){|arg| now += arg }
|
146
|
+
# allow(Process).to receive(:clock_gettime){ now }
|
146
147
|
expect { |b|
|
147
148
|
begin
|
148
149
|
thread = Thread.start {
|
149
|
-
job.wait(nil,
|
150
|
+
job.wait(nil, 0.1, &b)
|
150
151
|
}
|
151
|
-
sleep
|
152
|
+
sleep 0.3
|
152
153
|
change_job_status(Job::STATUS_SUCCESS)
|
153
154
|
thread.join(1)
|
154
155
|
expect(thread).to be_stop
|
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.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Treasure Data, Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -128,6 +128,20 @@ dependencies:
|
|
128
128
|
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: webrick
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
131
145
|
description: Treasure Data API library for Ruby
|
132
146
|
email: support@treasure-data.com
|
133
147
|
executables: []
|
@@ -183,7 +197,7 @@ homepage: http://treasuredata.com/
|
|
183
197
|
licenses:
|
184
198
|
- Apache-2.0
|
185
199
|
metadata: {}
|
186
|
-
post_install_message:
|
200
|
+
post_install_message:
|
187
201
|
rdoc_options: []
|
188
202
|
require_paths:
|
189
203
|
- lib
|
@@ -198,29 +212,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
212
|
- !ruby/object:Gem::Version
|
199
213
|
version: '0'
|
200
214
|
requirements: []
|
201
|
-
rubygems_version: 3.0.
|
202
|
-
signing_key:
|
215
|
+
rubygems_version: 3.0.9
|
216
|
+
signing_key:
|
203
217
|
specification_version: 4
|
204
218
|
summary: Treasure Data API library for Ruby
|
205
219
|
test_files:
|
206
|
-
- spec/td/
|
207
|
-
- spec/td/
|
220
|
+
- spec/td/client_spec.rb
|
221
|
+
- spec/td/client_sched_spec.rb
|
222
|
+
- spec/td/client/partial_delete_api_spec.rb
|
208
223
|
- spec/td/client/api_spec.rb
|
209
|
-
- spec/td/client/api_ssl_connection_spec.rb
|
210
|
-
- spec/td/client/bulk_import_spec.rb
|
211
|
-
- spec/td/client/bulk_load_spec.rb
|
212
224
|
- spec/td/client/db_api_spec.rb
|
225
|
+
- spec/td/client/result_api_spec.rb
|
213
226
|
- spec/td/client/export_api_spec.rb
|
214
|
-
- spec/td/client/import_api_spec.rb
|
215
|
-
- spec/td/client/job_api_spec.rb
|
216
|
-
- spec/td/client/model_job_spec.rb
|
217
|
-
- spec/td/client/model_schedule_spec.rb
|
218
227
|
- spec/td/client/model_schema_spec.rb
|
219
|
-
- spec/td/client/
|
220
|
-
- spec/td/client/result_api_spec.rb
|
228
|
+
- spec/td/client/api_error_spec.rb
|
221
229
|
- spec/td/client/sched_api_spec.rb
|
222
|
-
- spec/td/client/server_status_api_spec.rb
|
223
230
|
- spec/td/client/table_api_spec.rb
|
231
|
+
- spec/td/client/bulk_load_spec.rb
|
232
|
+
- spec/td/client/api_ssl_connection_spec.rb
|
233
|
+
- spec/td/client/job_api_spec.rb
|
234
|
+
- spec/td/client/account_api_spec.rb
|
224
235
|
- spec/td/client/user_api_spec.rb
|
225
|
-
- spec/td/
|
226
|
-
- spec/td/
|
236
|
+
- spec/td/client/bulk_import_spec.rb
|
237
|
+
- spec/td/client/model_schedule_spec.rb
|
238
|
+
- spec/td/client/import_api_spec.rb
|
239
|
+
- spec/td/client/server_status_api_spec.rb
|
240
|
+
- spec/td/client/model_job_spec.rb
|