td-client 0.8.25 → 0.8.26
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.
- data/ChangeLog +6 -0
- data/lib/td/client.rb +8 -2
- data/lib/td/client/api.rb +24 -5
- data/lib/td/client/model.rb +25 -2
- data/lib/td/client/version.rb +1 -1
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
|
2
|
+
== 2012-09-13 version 0.8.26
|
3
|
+
|
4
|
+
* Added Account model and Table#esetimated_storage_size method
|
5
|
+
* Name length limit is changed from 32 characters to 256 characters
|
6
|
+
|
7
|
+
|
2
8
|
== 2012-09-04 version 0.8.25
|
3
9
|
|
4
10
|
* Added Client#change_my_password(old_password, password)
|
data/lib/td/client.rb
CHANGED
@@ -41,6 +41,12 @@ class Client
|
|
41
41
|
@api.delete_database(db_name)
|
42
42
|
end
|
43
43
|
|
44
|
+
# => Account
|
45
|
+
def account
|
46
|
+
plan, storage = @api.show_account
|
47
|
+
return Account.new(self, plan, storage)
|
48
|
+
end
|
49
|
+
|
44
50
|
# => [Database]
|
45
51
|
def databases
|
46
52
|
m = @api.list_databases
|
@@ -83,9 +89,9 @@ class Client
|
|
83
89
|
# => [Table]
|
84
90
|
def tables(db_name)
|
85
91
|
m = @api.list_tables(db_name)
|
86
|
-
m.map {|table_name,(type,schema,count,created_at,updated_at)|
|
92
|
+
m.map {|table_name,(type,schema,count,created_at,updated_at,estimated_storage_size)|
|
87
93
|
schema = Schema.new.from_json(schema)
|
88
|
-
Table.new(self, db_name, table_name, type, schema, count, created_at, updated_at)
|
94
|
+
Table.new(self, db_name, table_name, type, schema, count, created_at, updated_at, estimated_storage_size)
|
89
95
|
}
|
90
96
|
end
|
91
97
|
|
data/lib/td/client/api.rb
CHANGED
@@ -77,8 +77,8 @@ class API
|
|
77
77
|
if name.empty?
|
78
78
|
raise "Empty name is not allowed"
|
79
79
|
end
|
80
|
-
if name.length < 3 ||
|
81
|
-
raise "Name must be 3 to
|
80
|
+
if name.length < 3 || 256 < name.length
|
81
|
+
raise "Name must be 3 to 256 characters, got #{name.length} characters."
|
82
82
|
end
|
83
83
|
unless name =~ /^([a-z0-9_]+)$/
|
84
84
|
raise "Name must consist only of lower-case alphabets, numbers and '_'."
|
@@ -99,8 +99,8 @@ class API
|
|
99
99
|
if name.empty?
|
100
100
|
raise "Empty column name is not allowed"
|
101
101
|
end
|
102
|
-
if
|
103
|
-
raise "Column name must be to
|
102
|
+
if 256 < name.length
|
103
|
+
raise "Column name must be to 256 characters, got #{name.length} characters."
|
104
104
|
end
|
105
105
|
unless name =~ /^([a-z0-9_]+)$/
|
106
106
|
raise "Column name must consist only of alphabets, numbers, '_'."
|
@@ -145,6 +145,24 @@ class API
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
|
149
|
+
####
|
150
|
+
## Account API
|
151
|
+
##
|
152
|
+
|
153
|
+
def show_account
|
154
|
+
code, body, res = get("/v3/account/show")
|
155
|
+
if code != "200"
|
156
|
+
raise_error("Show account failed", res)
|
157
|
+
end
|
158
|
+
js = checked_json(body, %w[account])
|
159
|
+
a = js["account"]
|
160
|
+
plan = a['plan'].to_i
|
161
|
+
storage_size = a['storage_size'].to_f
|
162
|
+
return [plan, storage_size]
|
163
|
+
end
|
164
|
+
|
165
|
+
|
148
166
|
####
|
149
167
|
## Database API
|
150
168
|
##
|
@@ -205,8 +223,9 @@ class API
|
|
205
223
|
count = (m['count'] || 0).to_i # TODO?
|
206
224
|
created_at = m['created_at']
|
207
225
|
updated_at = m['updated_at']
|
226
|
+
estimated_storage_size = m['estimated_storage_size']
|
208
227
|
schema = JSON.parse(m['schema'] || '[]')
|
209
|
-
result[name] = [type, schema, count, created_at, updated_at]
|
228
|
+
result[name] = [type, schema, count, created_at, updated_at, estimated_storage_size]
|
210
229
|
}
|
211
230
|
return result
|
212
231
|
end
|
data/lib/td/client/model.rb
CHANGED
@@ -10,6 +10,28 @@ class Model
|
|
10
10
|
attr_reader :client
|
11
11
|
end
|
12
12
|
|
13
|
+
class Account < Model
|
14
|
+
def initialize(client, plan, storage_size=nil)
|
15
|
+
super(client)
|
16
|
+
@plan = plan
|
17
|
+
@storage_size = storage_size
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :plan, :storage_size
|
21
|
+
|
22
|
+
def storage_size_string
|
23
|
+
s = "%.1f GB" % (@storage_size / (1024*1024*1024))
|
24
|
+
if s == "0.0 GB"
|
25
|
+
if @storage_size <= 1024*1024
|
26
|
+
return "0.0 GB"
|
27
|
+
end
|
28
|
+
return "0.01 GB"
|
29
|
+
else
|
30
|
+
return s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
13
35
|
class Database < Model
|
14
36
|
def initialize(client, db_name, tables=nil, count=nil, created_at=nil, updated_at=nil, org_name=nil)
|
15
37
|
super(client)
|
@@ -68,7 +90,7 @@ class Database < Model
|
|
68
90
|
end
|
69
91
|
|
70
92
|
class Table < Model
|
71
|
-
def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil)
|
93
|
+
def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil, estimated_storage_size=nil)
|
72
94
|
super(client)
|
73
95
|
@db_name = db_name
|
74
96
|
@table_name = table_name
|
@@ -77,9 +99,10 @@ class Table < Model
|
|
77
99
|
@count = count
|
78
100
|
@created_at = created_at
|
79
101
|
@updated_at = updated_at
|
102
|
+
@estimated_storage_size = estimated_storage_size
|
80
103
|
end
|
81
104
|
|
82
|
-
attr_reader :type, :db_name, :table_name, :schema, :count
|
105
|
+
attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size
|
83
106
|
|
84
107
|
alias database_name db_name
|
85
108
|
alias name table_name
|
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.26
|
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: 2012-09-
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|