Class: TreasureData::API
- Inherits:
-
Object
show all
- Includes:
- API::Account, API::BulkImport, API::BulkLoad, API::Database, API::Export, API::Import, API::Job, API::Result, API::Schedule, API::ServerStatus, API::Table, API::User
- Defined in:
- lib/td/client/api.rb,
lib/td/client/api/job.rb,
lib/td/client/api/user.rb,
lib/td/client/api/table.rb,
lib/td/client/api/export.rb,
lib/td/client/api/import.rb,
lib/td/client/api/result.rb,
lib/td/client/api/account.rb,
lib/td/client/api/database.rb,
lib/td/client/api/schedule.rb,
lib/td/client/api/bulk_load.rb,
lib/td/client/api/bulk_import.rb,
lib/td/client/api/server_status.rb
Defined Under Namespace
Modules: Account, BulkImport, BulkLoad, Database, Export, Import, Job, Result, Schedule, ServerStatus, Table, User
Classes: IncompleteError
Constant Summary
collapse
- DEFAULT_ENDPOINT =
'api.treasuredata.com'
- DEFAULT_IMPORT_ENDPOINT =
'api-import.treasuredata.com'
- NEW_DEFAULT_ENDPOINT =
Deprecated. Use DEFAULT_ENDPOINT and DEFAULT_IMPORT_ENDPOINT instead
DEFAULT_ENDPOINT
- NEW_DEFAULT_IMPORT_ENDPOINT =
DEFAULT_IMPORT_ENDPOINT
- OLD_ENDPOINT =
'api.treasure-data.com'
- MSGPACK_INT64_MAX =
2 ** 64 - 1
- MSGPACK_INT64_MIN =
it's just same with -2**63, but for readability
-1 * (2 ** 63)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(apikey, opts = {}) ⇒ API
for backward compatibility
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/td/client/api.rb', line 48
def initialize(apikey, opts={})
require 'json'
require 'time'
require 'uri'
require 'net/http'
require 'net/https'
require 'time'
require 'httpclient'
require 'zlib'
require 'stringio'
require 'cgi'
require 'msgpack'
@apikey = apikey
@user_agent = "TD-Client-Ruby: #{TreasureData::Client::VERSION}"
@user_agent = "#{opts[:user_agent]}; " + @user_agent if opts.has_key?(:user_agent)
endpoint = opts[:endpoint] || ENV['TD_API_SERVER'] || DEFAULT_ENDPOINT
uri = URI.parse(endpoint)
@connect_timeout = opts[:connect_timeout] || 60
@read_timeout = opts[:read_timeout] || 600
@send_timeout = opts[:send_timeout] || 600
@retry_post_requests = opts[:retry_post_requests] || false
@retry_delay = opts[:retry_delay] || 5
@max_cumul_retry_delay = opts[:max_cumul_retry_delay] || 600
@verify = opts[:verify]
case uri.scheme
when 'http', 'https'
@host = uri.host
@port = uri.port
@ssl = (uri.scheme == 'https')
@base_path = uri.path.to_s
else
if uri.port
raise "Invalid endpoint: #{endpoint}"
end
@host, @port = endpoint.split(':', 2)
@port = @port.to_i
if opts[:ssl] === false || @host == TreasureData::API::OLD_ENDPOINT
@port = 80 if @port == 0
@ssl = false
else
@port = 443 if @port == 0
@ssl = true
end
@base_path = ''
end
@http_proxy = opts[:http_proxy] || ENV['HTTP_PROXY']
@headers = opts[:headers] || {}
@api = api_client("#{@ssl ? 'https' : 'http'}://#{@host}:#{@port}")
end
|
Instance Attribute Details
#apikey ⇒ Object
Returns the value of attribute apikey.
119
120
121
|
# File 'lib/td/client/api.rb', line 119
def apikey
@apikey
end
|
Class Method Details
.create_empty_gz_data ⇒ String
for fluent-plugin-td / td command to check table existence with import onlt user
236
237
238
239
240
|
# File 'lib/td/client/api.rb', line 236
def self.create_empty_gz_data
io = StringIO.new
Zlib::GzipWriter.new(io).close
io.string
end
|
.normalize_database_name(name) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/td/client/api.rb', line 213
def self.normalize_database_name(name)
name = name.to_s
if name.empty?
raise "Empty name is not allowed"
end
if name.length < 3
name += "_" * (3 - name.length)
end
if 255 < name.length
name = name[0, 253] + "__"
end
name = name.downcase
name = name.gsub(/[^a-z0-9_]/, '_')
name
end
|
.normalize_table_name(name) ⇒ Object
230
231
232
|
# File 'lib/td/client/api.rb', line 230
def self.normalize_table_name(name)
normalize_database_name(name)
end
|
.normalized_msgpack(record, out = nil) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/td/client/api.rb', line 126
def self.normalized_msgpack(record, out = nil)
record.keys.each { |k|
v = record[k]
if v.kind_of?(Integer) && (v > MSGPACK_INT64_MAX || v < MSGPACK_INT64_MIN)
record[k] = v.to_s
end
}
if out
out << record.to_msgpack
out
else
record.to_msgpack
end
end
|
.validate_column_name(name) ⇒ Object
197
198
199
200
201
202
203
204
205
|
# File 'lib/td/client/api.rb', line 197
def self.validate_column_name(name)
target = 'column'
name = name.to_s
if name.empty?
raise ParameterValidationError,
"Empty #{target} name is not allowed"
end
name
end
|
.validate_database_name(name) ⇒ Object
182
183
184
|
# File 'lib/td/client/api.rb', line 182
def self.validate_database_name(name)
validate_name("database", 3, 255, name)
end
|
.validate_name(target, min_len, max_len, name) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/td/client/api.rb', line 145
def self.validate_name(target, min_len, max_len, name)
if !target.instance_of?(String) || target.empty?
raise ParameterValidationError,
"A valid target name is required"
end
name = name.to_s
if max_len
if name.length < min_len || name.length > max_len
raise ParameterValidationError,
"#{target.capitalize} name must be between #{min_len} and #{max_len} characters long. Got #{name.length} " +
(name.length == 1 ? "character" : "characters") + "."
end
else
if min_len == 1
if name.empty?
raise ParameterValidationError,
"Empty #{target} name is not allowed"
end
else
if name.length < min_len
raise ParameterValidationError,
"#{target.capitalize} name must be longer than #{min_len} characters. Got #{name.length} " +
(name.length == 1 ? "character" : "characters") + "."
end
end
end
unless name =~ /^([a-z0-9_]+)$/
raise ParameterValidationError,
"#{target.capitalize} name must only consist of lower-case alpha-numeric characters and '_'."
end
name
end
|
.validate_result_set_name(name) ⇒ Object
192
193
194
|
# File 'lib/td/client/api.rb', line 192
def self.validate_result_set_name(name)
validate_name("result set", 3, 255, name)
end
|
.validate_sql_alias_name(name) ⇒ Object
208
209
210
|
# File 'lib/td/client/api.rb', line 208
def self.validate_sql_alias_name(name)
validate_name("sql_alias", 1, nil, name)
end
|
.validate_table_name(name) ⇒ Object
187
188
189
|
# File 'lib/td/client/api.rb', line 187
def self.validate_table_name(name)
validate_name("table", 3, 255, name)
end
|
Instance Method Details
#ssl_ca_file=(ssl_ca_file) ⇒ Object
243
244
245
|
# File 'lib/td/client/api.rb', line 243
def ssl_ca_file=(ssl_ca_file)
@ssl_ca_file = ssl_ca_file
end
|