td-client 0.8.57 → 0.8.58
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/td/client.rb +2 -2
- data/lib/td/client/api.rb +44 -12
- data/lib/td/client/model.rb +5 -3
- data/lib/td/client/version.rb +1 -1
- metadata +24 -3
data/lib/td/client.rb
CHANGED
@@ -104,10 +104,10 @@ class Client
|
|
104
104
|
# => [Table]
|
105
105
|
def tables(db_name)
|
106
106
|
m = @api.list_tables(db_name)
|
107
|
-
m.map {|table_name,(type,schema,count,created_at,updated_at,estimated_storage_size, last_import, last_log_timestamp, expire_days)|
|
107
|
+
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)|
|
108
108
|
schema = Schema.new.from_json(schema)
|
109
109
|
Table.new(self, db_name, table_name, type, schema, count, created_at, updated_at,
|
110
|
-
estimated_storage_size, last_import, last_log_timestamp, expire_days)
|
110
|
+
estimated_storage_size, last_import, last_log_timestamp, expire_days, primary_key, primary_key_type)
|
111
111
|
}
|
112
112
|
end
|
113
113
|
|
data/lib/td/client/api.rb
CHANGED
@@ -20,6 +20,9 @@ class API
|
|
20
20
|
DEFAULT_ENDPOINT = 'api.treasure-data.com'
|
21
21
|
DEFAULT_IMPORT_ENDPOINT = 'api-import.treasure-data.com'
|
22
22
|
|
23
|
+
NEW_DEFAULT_ENDPOINT = 'api.treasuredata.com'
|
24
|
+
NEW_DEFAULT_IMPORT_ENDPOINT = 'api-import.treasuredata.com'
|
25
|
+
|
23
26
|
def initialize(apikey, opts={})
|
24
27
|
require 'json'
|
25
28
|
require 'time'
|
@@ -283,7 +286,9 @@ class API
|
|
283
286
|
estimated_storage_size = m['estimated_storage_size'].to_i
|
284
287
|
schema = JSON.parse(m['schema'] || '[]')
|
285
288
|
expire_days = m['expire_days']
|
286
|
-
|
289
|
+
primary_key = m['primary_key']
|
290
|
+
primary_key_type = m['primary_key_type']
|
291
|
+
result[name] = [type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days, primary_key, primary_key_type]
|
287
292
|
}
|
288
293
|
return result
|
289
294
|
end
|
@@ -342,7 +347,7 @@ class API
|
|
342
347
|
raise_error("Update table expiration failed", res)
|
343
348
|
end
|
344
349
|
return true
|
345
|
-
end
|
350
|
+
end
|
346
351
|
|
347
352
|
# => type:Symbol
|
348
353
|
def delete_table(db, table)
|
@@ -839,6 +844,8 @@ class API
|
|
839
844
|
opts = {}
|
840
845
|
if @host == DEFAULT_ENDPOINT
|
841
846
|
opts[:host] = DEFAULT_IMPORT_ENDPOINT
|
847
|
+
elsif @host == NEW_DEFAULT_ENDPOINT
|
848
|
+
opts[:host] = NEW_DEFAULT_IMPORT_ENDPOINT
|
842
849
|
end
|
843
850
|
code, body, res = put(path, stream, size, opts)
|
844
851
|
if code[0] != ?2
|
@@ -1113,6 +1120,13 @@ class API
|
|
1113
1120
|
header['Accept-Encoding'] = 'deflate, gzip'
|
1114
1121
|
request = Net::HTTP::Get.new(path, header)
|
1115
1122
|
|
1123
|
+
unless ENV['TD_CLIENT_DEBUG'].nil?
|
1124
|
+
puts "DEBUG: REST GET call:"
|
1125
|
+
puts "DEBUG: header: " + header.to_s
|
1126
|
+
puts "DEBUG: path: " + path.to_s
|
1127
|
+
puts "DEBUG: params: " + params.to_s
|
1128
|
+
end
|
1129
|
+
|
1116
1130
|
if block
|
1117
1131
|
response = http.request(request) do |res|
|
1118
1132
|
if ce = res.header['Content-Encoding']
|
@@ -1153,6 +1167,13 @@ class API
|
|
1153
1167
|
|
1154
1168
|
path = @base_path + url
|
1155
1169
|
|
1170
|
+
unless ENV['TD_CLIENT_DEBUG'].nil?
|
1171
|
+
puts "DEBUG: REST POST call:"
|
1172
|
+
puts "DEBUG: header: " + header.to_s
|
1173
|
+
puts "DEBUG: path: " + path.to_s
|
1174
|
+
puts "DEBUG: params: " + params.to_s
|
1175
|
+
end
|
1176
|
+
|
1156
1177
|
if params && !params.empty?
|
1157
1178
|
request = Net::HTTP::Post.new(path, header)
|
1158
1179
|
request.set_form_data(params)
|
@@ -1179,6 +1200,14 @@ class API
|
|
1179
1200
|
stream
|
1180
1201
|
end
|
1181
1202
|
target = build_endpoint(url, opts[:host] || @host)
|
1203
|
+
|
1204
|
+
unless ENV['TD_CLIENT_DEBUG'].nil?
|
1205
|
+
puts "DEBUG: REST PUT call:"
|
1206
|
+
puts "DEBUG: header: " + header.to_s
|
1207
|
+
puts "DEBUG: target: " + target.to_s
|
1208
|
+
puts "DEBUG: body: " + body.to_s
|
1209
|
+
end
|
1210
|
+
|
1182
1211
|
response = client.put(target, body, header)
|
1183
1212
|
return [response.code.to_s, response.body, response]
|
1184
1213
|
end
|
@@ -1237,31 +1266,34 @@ class API
|
|
1237
1266
|
end
|
1238
1267
|
|
1239
1268
|
def raise_error(msg, res, klass=nil)
|
1269
|
+
status_code = res.code.to_s
|
1240
1270
|
begin
|
1241
|
-
status_code = res.code.to_s
|
1242
1271
|
js = JSON.load(res.body)
|
1243
|
-
|
1244
|
-
error_code = js['error_code']
|
1272
|
+
error_msg = js['message'] || js['error']
|
1245
1273
|
|
1246
1274
|
if klass
|
1247
|
-
raise klass, "#{
|
1275
|
+
raise klass, "#{status_code}: #{msg}: #{error_msg}"
|
1248
1276
|
elsif status_code == "404"
|
1249
|
-
raise NotFoundError, "#{
|
1277
|
+
raise NotFoundError, "#{msg}: #{error_msg}"
|
1250
1278
|
elsif status_code == "409"
|
1251
|
-
raise AlreadyExistsError, "#{
|
1279
|
+
raise AlreadyExistsError, "#{msg}: #{error_msg}"
|
1280
|
+
elsif status_code == "401"
|
1281
|
+
raise AuthError, "#{msg}: #{error_msg}"
|
1252
1282
|
else
|
1253
|
-
raise APIError, "#{
|
1283
|
+
raise APIError, "#{status_code}: #{msg}: #{error_msg}"
|
1254
1284
|
end
|
1255
1285
|
|
1256
|
-
rescue
|
1286
|
+
rescue JSON::ParserError
|
1257
1287
|
if klass
|
1258
|
-
raise klass, "#{
|
1288
|
+
raise klass, "#{status_code}: #{msg}: #{res.body}"
|
1259
1289
|
elsif status_code == "404"
|
1260
1290
|
raise NotFoundError, "#{msg}: #{res.body}"
|
1261
1291
|
elsif status_code == "409"
|
1262
1292
|
raise AlreadyExistsError, "#{msg}: #{res.body}"
|
1293
|
+
elsif status_code == "401"
|
1294
|
+
raise AuthError, "#{msg}: #{res.body}"
|
1263
1295
|
else
|
1264
|
-
raise APIError, "#{msg}: #{res.body}"
|
1296
|
+
raise APIError, "#{status_code}: #{msg}: #{res.body}"
|
1265
1297
|
end
|
1266
1298
|
end
|
1267
1299
|
# TODO error
|
data/lib/td/client/model.rb
CHANGED
@@ -97,7 +97,7 @@ class Database < Model
|
|
97
97
|
end
|
98
98
|
|
99
99
|
class Table < Model
|
100
|
-
def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil, estimated_storage_size=nil, last_import=nil, last_log_timestamp=nil, expire_days=nil)
|
100
|
+
def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil, estimated_storage_size=nil, last_import=nil, last_log_timestamp=nil, expire_days=nil, primary_key=nil, primary_key_type=nil)
|
101
101
|
super(client)
|
102
102
|
@db_name = db_name
|
103
103
|
@table_name = table_name
|
@@ -110,9 +110,11 @@ class Table < Model
|
|
110
110
|
@last_import = last_import
|
111
111
|
@last_log_timestamp = last_log_timestamp
|
112
112
|
@expire_days = expire_days
|
113
|
+
@primary_key = primary_key
|
114
|
+
@primary_key_type = primary_key_type
|
113
115
|
end
|
114
116
|
|
115
|
-
attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size
|
117
|
+
attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size, :primary_key, :primary_key_type
|
116
118
|
|
117
119
|
alias database_name db_name
|
118
120
|
alias name table_name
|
@@ -318,7 +320,7 @@ class Job < Model
|
|
318
320
|
|
319
321
|
def finished?
|
320
322
|
update_progress! unless @status
|
321
|
-
if FINISHED_STATUS.include?(@status)
|
323
|
+
if FINISHED_STATUS.include?(@status)
|
322
324
|
return true
|
323
325
|
else
|
324
326
|
return false
|
data/lib/td/client/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.58
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
@@ -137,6 +137,22 @@ dependencies:
|
|
137
137
|
- - ! '>='
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: 0.5.4
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: rake
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
type: :development
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ! '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
140
156
|
description: Treasure Data API library for Ruby
|
141
157
|
email: support@treasure-data.com
|
142
158
|
executables: []
|
@@ -173,12 +189,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
189
|
- - ! '>='
|
174
190
|
- !ruby/object:Gem::Version
|
175
191
|
version: '0'
|
192
|
+
segments:
|
193
|
+
- 0
|
194
|
+
hash: -4425539738292282351
|
176
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
196
|
none: false
|
178
197
|
requirements:
|
179
198
|
- - ! '>='
|
180
199
|
- !ruby/object:Gem::Version
|
181
200
|
version: '0'
|
201
|
+
segments:
|
202
|
+
- 0
|
203
|
+
hash: -4425539738292282351
|
182
204
|
requirements: []
|
183
205
|
rubyforge_project:
|
184
206
|
rubygems_version: 1.8.23
|
@@ -195,4 +217,3 @@ test_files:
|
|
195
217
|
- spec/td/client/partial_delete_api_spec.rb
|
196
218
|
- spec/td/client/result_api_spec.rb
|
197
219
|
- spec/td/client/sched_api_spec.rb
|
198
|
-
has_rdoc: false
|