dreamy 0.5.1

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.
@@ -0,0 +1,32 @@
1
+ module Dreamy::Command
2
+ class Users < Base
3
+
4
+ def index
5
+ users = @account.users
6
+ if users.empty?
7
+ display "No users on this account"
8
+ else
9
+ user_table = table do |t|
10
+ t.headings = 'Name', 'Account Type', 'Server', 'Disk used (MB)', 'Quota (MB)'
11
+ users.each { |u| t << [u.gecos, u.type, u.home, u.disk_used_mb, u.quota_mb] }
12
+ end
13
+ display user_table
14
+ end
15
+ end
16
+
17
+ def pw
18
+ users = @account.users(passwords=true)
19
+ if users.empty?
20
+ display "No users on this account"
21
+ else
22
+ user_table = table do |t|
23
+ t.headings = 'UserName', 'Password'
24
+ users.each { |u| t << [u.username, u.password] }
25
+ end
26
+ display user_table
27
+
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def to_param_array
3
+ p = Array.new
4
+ self.each do |k,v|
5
+ p << "#{k}=#{v}"
6
+ end
7
+ p
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Dreamy
2
+ class Dns
3
+ include EasyClassMaker
4
+
5
+ attributes :account_id, :comment, :editable, :record, :type, :value, :zone
6
+
7
+ def self.new_from_xml(xml)
8
+ d = new
9
+ d.account_id = (xml).at('account_id').innerHTML.to_i
10
+ d.comment = (xml).at('comment').innerHTML
11
+ d.editable = (xml).at('editable').innerHTML.to_i
12
+ d.record = (xml).at('record').innerHTML
13
+ d.type = (xml).at('type').innerHTML
14
+ d.value = (xml).at('value').innerHTML
15
+ d.zone = (xml).at('zone').innerHTML
16
+ d
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ module Dreamy
2
+ class Domain
3
+ include EasyClassMaker
4
+
5
+ attributes :account_id, :domain, :fastcgi, :home, :hosting_type, :outside_url, :passenger,
6
+ :path, :php, :php_fcgid, :security, :type, :unique_ip, :user, :www_or_not, :xcache
7
+
8
+ def self.new_from_xml(xml)
9
+ d = new
10
+
11
+ d.account_id = (xml).at('account_id').innerHTML.to_i
12
+ d.domain = (xml).at('domain').innerHTML
13
+ d.home = (xml).at('home').innerHTML
14
+ d.type = (xml).at('type').innerHTML
15
+ d.unique_ip = (xml).at('unique_ip').innerHTML
16
+
17
+ if d.type == 'http'
18
+ d.fastcgi = (xml).at('fastcgi').innerHTML.to_i
19
+ d.hosting_type = (xml).at('hosting_type').innerHTML
20
+ d.outside_url = (xml).at('outside_url').innerHTML
21
+ d.passenger = (xml).at('passenger').innerHTML.to_i
22
+ d.path = (xml).at('path').innerHTML
23
+ d.php = (xml).at('php').innerHTML
24
+ d.php_fcgid = (xml).at('php_fcgid').innerHTML.to_i
25
+ d.security = (xml).at('security').innerHTML.to_i
26
+ d.user = (xml).at('user').innerHTML
27
+ d.www_or_not = (xml).at('www_or_not').innerHTML
28
+ d.xcache = (xml).at('xcache').innerHTML.to_i
29
+ end
30
+
31
+ d
32
+ end
33
+
34
+ def short_home
35
+ home.gsub(".Dreamy.com","")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,43 @@
1
+ # This is pretty much just a macro for creating a class that allows
2
+ # using a block to initialize stuff and to define getters and setters
3
+ # really quickly.
4
+ module Dreamy
5
+ module EasyClassMaker
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ # creates the attributes class variable and creates each attribute's accessor methods
13
+ def attributes(*attrs)
14
+ @@attributes = attrs
15
+ @@attributes.each { |a| attr_accessor a }
16
+ end
17
+
18
+ # read method for attributes class variable
19
+ def self.attributes; @@attributes end
20
+ end
21
+
22
+ # allows for any class that includes this to use a block to initialize
23
+ # variables instead of assigning each one seperately
24
+ #
25
+ # Example:
26
+ #
27
+ # instead of...
28
+ #
29
+ # s = Status.new
30
+ # s.foo = 'thing'
31
+ # s.bar = 'another thing'
32
+ #
33
+ # you can ...
34
+ #
35
+ # Status.new do |s|
36
+ # s.foo = 'thing'
37
+ # s.bar = 'another thing'
38
+ # end
39
+ def initialize
40
+ yield self if block_given?
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ module Dreamy
2
+ class MysqlDb
3
+ include EasyClassMaker
4
+
5
+ attributes :account_id, :name, :description, :home, :disk_usage_mb
6
+
7
+ def self.new_from_xml(xml)
8
+ db = new
9
+ db.account_id = (xml).at('account_id').innerHTML.to_i
10
+ db.name = (xml).at('db').innerHTML
11
+ db.description = (xml).at('description').innerHTML
12
+ db.home = (xml).at('home').innerHTML
13
+ db.disk_usage_mb = (xml).at('disk_usage_mb').innerHTML.to_f
14
+ db
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Dreamy
2
+ class MysqlHost
3
+ include EasyClassMaker
4
+
5
+ attributes :account_id, :domain, :home
6
+
7
+ def self.new_from_xml(xml)
8
+ host = new
9
+ host.account_id = (xml).at('account_id').innerHTML.to_i
10
+ host.domain = (xml).at('domain').innerHTML
11
+ host.home = (xml).at('home').innerHTML
12
+ host
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Dreamy
2
+ class MysqlUser
3
+ include EasyClassMaker
4
+
5
+ attributes :account_id, :db, :home, :username, :host, :select, :insert,
6
+ :update, :delete, :create, :drop, :index, :alter
7
+
8
+ def self.new_from_xml(xml)
9
+ u = new
10
+ u.account_id = (xml).at('account_id').innerHTML.to_i
11
+ u.db = (xml).at('db').innerHTML
12
+ u.home = (xml).at('home').innerHTML
13
+ u.username = (xml).at('username').innerHTML
14
+ u.host = (xml).at('host').innerHTML
15
+ u.select = (xml).at('select_priv').innerHTML
16
+ u.insert = (xml).at('insert_priv').innerHTML
17
+ u.update = (xml).at('update_priv').innerHTML
18
+ u.delete = (xml).at('delete_priv').innerHTML
19
+ u.create = (xml).at('create_priv').innerHTML
20
+ u.drop = (xml).at('drop_priv').innerHTML
21
+ u.index = (xml).at('index_priv').innerHTML
22
+ u.alter = (xml).at('alter_priv').innerHTML
23
+ u
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,53 @@
1
+ module Dreamy
2
+ class PrivateServer
3
+ include EasyClassMaker
4
+
5
+ attributes :account_id, :name, :type, :memory, :start_date
6
+
7
+ def self.new_from_xml(xml)
8
+ ps = new
9
+ ps.account_id = (xml).at('account_id').innerHTML.to_i
10
+ ps.name = (xml).at('ps').innerHTML
11
+ ps.type = (xml).at('type').innerHTML
12
+ ps.memory = (xml).at('memory_mb').innerHTML.to_i
13
+ ps.start_date = (xml).at('start_date').innerHTML
14
+ ps
15
+ end
16
+
17
+ def self.settings_from_xml(xml)
18
+ settings = {}
19
+ (xml/:data).each do |d|
20
+ settings[(d).at('setting').innerHTML] = (d).at('value').innerHTML
21
+ end
22
+ settings
23
+ end
24
+
25
+ def self.size_from_xml(xml)
26
+ size = {}
27
+ size["memory_mb"] = (xml).at('memory_mb').innerHTML.to_i
28
+ size["monthly_cost"] = (xml).at('monthly_cost').innerHTML.to_f
29
+ size["period_cost"] = (xml).at('period_cost').innerHTML.to_f
30
+ size["period_seconds"] = (xml).at('period_seconds').innerHTML.to_i
31
+ size["stamp"] = (xml).at('stamp').innerHTML
32
+ size
33
+ end
34
+
35
+ def self.usage_from_xml(xml)
36
+ usage = {}
37
+ usage["load"] = (xml).at('load').innerHTML.to_f
38
+ usage["memory_mb"] = (xml).at('memory_mb').innerHTML.to_i
39
+ usage["stamp"] = (xml).at('stamp').innerHTML
40
+ usage
41
+ end
42
+
43
+ def self.pending_from_xml(xml)
44
+ pending = {}
45
+ pending["account_id"] = (xml).at('account_id').innerHTML
46
+ pending["ip"] = (xml).at('ip').innerHTML
47
+ pending["type"] = (xml).at('type').innerHTML
48
+ pending["stamp"] = (xml).at('stamp').innerHTML
49
+ pending
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ module Dreamy
2
+ class Subscriber
3
+ include EasyClassMaker
4
+
5
+ attributes :email, :confirmed, :subscribe_date, :name, :num_bounces
6
+
7
+ def self.new_from_xml(xml)
8
+ s = new
9
+ s.email = (xml).at('email').innerHTML
10
+ s.confirmed = (xml).at('confirmed').innerHTML.to_i
11
+ s.subscribe_date = (xml).at('subscribe_date').innerHTML
12
+ s.name = (xml).at('name').innerHTML
13
+ s.num_bounces = (xml).at('num_bounces').innerHTML.to_i
14
+ s
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Dreamy
2
+ class User
3
+ include EasyClassMaker
4
+
5
+ attributes :account_id, :disk_used_mb, :gecos, :home, :password, :quota_mb, :shell, :type, :username
6
+
7
+ def self.new_from_xml(xml)
8
+ u = new
9
+ u.account_id = (xml).at('account_id').innerHTML.to_i
10
+ u.disk_used_mb = (xml).at('disk_used_mb').innerHTML.to_f
11
+ u.gecos = (xml).at('gecos').innerHTML
12
+ u.home = (xml).at('home').innerHTML
13
+ u.password = (xml).at('password').innerHTML
14
+ u.quota_mb = (xml).at('quota_mb').innerHTML.to_i
15
+ u.shell = (xml).at('shell').innerHTML
16
+ u.type = (xml).at('type').innerHTML
17
+ u.username = (xml).at('username').innerHTML
18
+ u
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+
3
+ class DreamyAnnounceListTest < Test::Unit::TestCase
4
+
5
+ context "Creation" do
6
+ setup do
7
+ @xml = <<EOF
8
+ <data>
9
+ <name>Super Announce</name>
10
+ <account_id>8675309</account_id>
11
+ <domain>anessalee.net</domain>
12
+ <listname>testlist</listname>
13
+ <max_bounces>5</max_bounces>
14
+ <num_subscribers>22</num_subscribers>
15
+ <start_date>2009-04-20</start_date>
16
+ </data>
17
+ EOF
18
+ end
19
+
20
+ should "create a new list of announce lists from xml" do
21
+ l = Dreamy::AnnounceList.new_from_xml(Hpricot.XML(@xml))
22
+ assert_equal "Super Announce", l.name
23
+ assert_equal 8675309, l.account_id
24
+ assert_equal "anessalee.net", l.domain
25
+ assert_equal "testlist", l.short_name
26
+ assert_equal 5, l.max_bounces
27
+ assert_equal 22, l.subscribers
28
+ assert_equal "2009-04-20", l.start_date
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,235 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+
3
+ class DreamyBaseTest < Test::Unit::TestCase
4
+
5
+ @@base = Dreamy::Base.new(CREDS["user"],CREDS["key"])
6
+
7
+ context "Initialization" do
8
+
9
+ should "require email and API key" do
10
+ assert_raise(ArgumentError) { Dreamy::Base.new }
11
+ end
12
+
13
+ end
14
+
15
+ context "Domains" do
16
+
17
+ should "return array of domain objects" do
18
+ domains = @@base.domains
19
+ assert_kind_of Array, domains
20
+ assert_kind_of Dreamy::Domain, domains.first unless domains.empty?
21
+ end
22
+
23
+ end
24
+
25
+ context "Users" do
26
+
27
+ should "return array of user objects" do
28
+ users = @@base.users
29
+ assert_kind_of Array, users
30
+ assert_kind_of Dreamy::User, users.first unless users.empty?
31
+ end
32
+
33
+ should "not include user passwords by default" do
34
+ assert_equal "********", @@base.users.first.password
35
+ end
36
+ end
37
+
38
+ context "DNS" do
39
+
40
+ should "return array of DNS records" do
41
+ records = @@base.dns
42
+ assert_kind_of Array, records
43
+ assert_kind_of Dreamy::Dns, records.first unless records.empty?
44
+ end
45
+
46
+ context "adding a record" do
47
+ setup { @record_count = @@base.dns.size }
48
+
49
+ should "require 3 arguments" do
50
+ assert_raise(ArgumentError) { @@base.dns_add("first","second") }
51
+ end
52
+
53
+ should "add record and return true with valid data" do
54
+ assert @@base.dns_add("test." + CREDS["domain"],"A","208.97.188.35")
55
+ assert_equal @record_count + 1, @@base.dns.size
56
+ end
57
+
58
+ should "not add record and raise error with invalid data" do
59
+ assert_raise(Dreamy::ApiError) { @@base.dns_add("test." + CREDS["domain"],"B","208.97.188.35") }
60
+ assert_equal @record_count, @@base.dns.size
61
+ end
62
+
63
+ end
64
+
65
+ context "removing a record" do
66
+
67
+ should "require 3 arguments" do
68
+ assert_raise(ArgumentError) { @@base.dns_remove("first","second") }
69
+ end
70
+
71
+ should "remove record and return true with valid data" do
72
+ record_count = @@base.dns.size
73
+ assert @@base.dns_remove("test." + CREDS["domain"],"A","208.97.188.35")
74
+ assert_equal record_count - 1, @@base.dns.size
75
+ end
76
+
77
+ should "not remove record and raise error with invalid data" do
78
+ record_count = @@base.dns.size
79
+ assert_raise(Dreamy::ApiError) { @@base.dns_remove("test." + CREDS["domain"],"B","208.97.188.35") }
80
+ assert_equal record_count, @@base.dns.size
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
87
+ context "Announcement lists" do
88
+
89
+ context "listing lists" do
90
+
91
+ should "return array of AnnounceList records" do
92
+ lists = @@base.announce_lists
93
+ assert_kind_of Array, lists
94
+ assert_kind_of Dreamy::AnnounceList, lists.first unless lists.empty?
95
+ end
96
+
97
+ end
98
+
99
+ context "subscribers" do
100
+
101
+ should "require values for listname and domain" do
102
+ assert_raise(ArgumentError) { @@base.announce_list() }
103
+ end
104
+
105
+ should "return array of Subscriber records" do
106
+ subscribers = @@base.announce_list(CREDS["listname"],CREDS["domain"])
107
+ assert_kind_of Array, subscribers
108
+ assert_kind_of Dreamy::Subscriber, subscribers.first unless subscribers.empty?
109
+ end
110
+
111
+ end
112
+
113
+ context "adding a subscriber" do
114
+
115
+ should "require values for listname, domain, and email" do
116
+ assert_raise(ArgumentError) { @@base.announce_add() }
117
+ end
118
+
119
+ # should "return true on success" do
120
+ # assert @@base.announce_add(CREDS["listname"],CREDS["domain"],"new_guy@test.com")
121
+ # end
122
+
123
+ end
124
+
125
+ context "removing a subscriber" do
126
+
127
+ should "require values for listname, domain, and email" do
128
+ assert_raise(ArgumentError) { @@base.announce_remove() }
129
+ end
130
+
131
+ # should "return true on success" do
132
+ # assert @@base.announce_remove(CREDS["listname"],CREDS["domain"],"new_guy@test.com")
133
+ # end
134
+
135
+ end
136
+
137
+ end # announcement lists
138
+
139
+ context "MySQL" do
140
+
141
+ should "return array of MysqlDb records" do
142
+ dbs = @@base.mysql_dbs
143
+ assert_kind_of Array, dbs
144
+ assert_kind_of Dreamy::MysqlDb, dbs.first unless dbs.empty?
145
+ end
146
+
147
+ should "return array of MysqlHost records" do
148
+ hosts = @@base.mysql_hosts
149
+ assert_kind_of Array, hosts
150
+ assert_kind_of Dreamy::MysqlDb, hosts.first unless hosts.empty?
151
+ end
152
+
153
+ should "return array of MysqlUser records" do
154
+ users = @@base.mysql_users
155
+ assert_kind_of Array, users
156
+ assert_kind_of Dreamy::MysqlUser, users.first unless users.empty?
157
+ end
158
+
159
+ end
160
+
161
+ context "Private Servers" do
162
+ setup { @ps = CREDS["ps"] }
163
+
164
+ should "return an array of PrivateServer objects" do
165
+ ps = @@base.ps
166
+ assert_kind_of Array, ps
167
+ assert_kind_of Dreamy::PrivateServer, ps.first unless ps.empty?
168
+ end
169
+
170
+ context "settings" do
171
+
172
+ should "return a hash of settings" do
173
+ settings = @@base.ps_settings(@ps)
174
+ assert_kind_of Hash, settings
175
+ end
176
+
177
+ should "require values for ps, setting, and value when setting value" do
178
+ assert_raise(ArgumentError) { @@base.ps_set() }
179
+ end
180
+
181
+ should "set specified setting" do
182
+ @@base.ps_set(@ps,'comment','testps')
183
+ settings = @@base.ps_settings(@ps)
184
+ assert_equal 'testps', settings['comment']
185
+ end
186
+
187
+ end
188
+
189
+ context "Size" do
190
+
191
+ should "return an array of size history hashes" do
192
+ sizes = @@base.ps_size_history(@ps)
193
+ assert_kind_of Array, sizes
194
+ assert_kind_of Hash, sizes.first
195
+ end
196
+
197
+ should "set new size" do
198
+ @@base.ps_size_set(@ps,"200")
199
+ assert_equal 200, @@base.ps_size_history(@ps).last["memory_mb"]
200
+ end
201
+
202
+ end
203
+
204
+ context "Rebooting" do
205
+
206
+ should "return an array of reboot time stamps" do
207
+ reboots = @@base.ps_reboot_history(@ps)
208
+ assert_kind_of Array, reboots
209
+ end
210
+
211
+ end
212
+
213
+ context "Usage" do
214
+
215
+ should "return array of usage hashes" do
216
+ usage = @@base.ps_usage(@ps)
217
+ assert_kind_of Array, usage
218
+ assert_kind_of Hash, usage.first
219
+ end
220
+
221
+ end
222
+
223
+ context "Pending requests" do
224
+
225
+ should "return array of pending hashes" do
226
+ pending = @@base.ps_pending
227
+ assert_kind_of Array, pending
228
+ assert_kind_of Hash, pending.first unless pending.empty?
229
+ end
230
+
231
+ end
232
+
233
+ end
234
+
235
+ end