Class: Dreamy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dreamy/base.rb

Direct Known Subclasses

Command::Dns, Command::Ps

Constant Summary collapse

@@host =
"api.dreamhost.com"

Instance Method Summary collapse

Constructor Details

#initialize(username, key) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/dreamy/base.rb', line 6

def initialize(username, key)
  @username = username
  @key      = key
end

Instance Method Details

#announce_add(listname, domain, email, name = "") ⇒ Object

adds new subscriber to announce list



62
63
64
65
66
67
# File 'lib/dreamy/base.rb', line 62

def announce_add(listname,domain,email,name="")
  doc = request("announcement_list-add_subscriber",
                  {"listname" => listname, "domain" => domain, "email" => email, "name" => name})
  api_error?(doc)
  true
end

#announce_list(listname, domain) ⇒ Object

returns an array of subscriber objects



55
56
57
58
59
# File 'lib/dreamy/base.rb', line 55

def announce_list(listname,domain)
  doc = request("announcement_list-list_subscribers",{ "listname" => listname, "domain" => domain})
  api_error?(doc)
  (doc/:data).inject([]) { |subs, sub| subs << Subscriber.new_from_xml(sub); subs }
end

#announce_listsObject



48
49
50
51
52
# File 'lib/dreamy/base.rb', line 48

def announce_lists
  doc = request("announcement_list-list_lists")
  api_error?(doc)
  (doc/:data).inject([]) { |lists, list| lists << AnnounceList.new_from_xml(list); lists }
end

#announce_post(listname, domain, subject, message, name, options = {}) ⇒ Object

options:

stamp        - the time to send the message, like "2009-05-28" or "2009-05-28 14:24:36"
charset      - the character set in which the message is encoded
type         - the format of the message, either "text" or "html"
duplicate_ok - whether to allow duplicate messages to be sent, like 1 or 0


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dreamy/base.rb', line 81

def announce_post(listname,domain,subject,message,name,options={})
  values = {
    "listname" => listname,
    "domain" => domain,
    "subject" => subject,
    "message" => message,
    "name" => name
  }.merge(options)
  doc = request("announcement_list-post_announcement", values, true)
  api_error?(doc)
  true
end

#announce_remove(listname, domain, email) ⇒ Object



69
70
71
72
73
74
# File 'lib/dreamy/base.rb', line 69

def announce_remove(listname,domain,email)
  doc = request("announcement_list-remove_subscriber",
                  {"listname" => listname, "domain" => domain, "email" => email})
  api_error?(doc)
  true
end

#dnsObject

returns an array of dns objects



30
31
32
33
34
# File 'lib/dreamy/base.rb', line 30

def dns
  doc = request("dns-list_records")
  api_error?(doc)
  (doc/:data).inject([]) { |records, dns| records << Dns.new_from_xml(dns); records }
end

#dns_add(record, type, value) ⇒ Object



36
37
38
39
40
# File 'lib/dreamy/base.rb', line 36

def dns_add(record,type,value)
  doc = request("dns-add_record", {"record" => record, "type" => type, "value" => value})
  api_error?(doc)
  true
end

#dns_remove(record, type, value) ⇒ Object



42
43
44
45
46
# File 'lib/dreamy/base.rb', line 42

def dns_remove(record,type,value)
  doc = request("dns-remove_record", {"record" => record, "type" => type, "value" => value})
  api_error?(doc)
  true
end

#domainsObject

returns an array of domain objects



12
13
14
15
16
# File 'lib/dreamy/base.rb', line 12

def domains
  doc = request("domain-list_domains")
  api_error?(doc)
  (doc/:data).inject([]) { |domains, domain| domains << Domain.new_from_xml(domain); domains }
end

#mail_add_filter(address, filter_on, filter, action, action_value, contains = "", stop = "", rank = "") ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/dreamy/base.rb', line 100

def mail_add_filter(address,filter_on,filter,action,action_value,contains="",stop="",rank="")
    doc = request("mail-add_filter",
		{
			"address"       => address,
			"filter_on"     => filter_on,
			"filter"        => filter,
			"action"        => action,
			"action_value"  => action_value,
			"contains"      => contains,
			"stop"          => stop,
			"rank"          => rank
		})
    api_error?(doc)
	true
end

#mail_list_filtersObject



94
95
96
97
98
# File 'lib/dreamy/base.rb', line 94

def mail_list_filters
    doc = request("mail-list_filters")
    api_error?(doc)
    (doc/:data).inject([]) { |filters, filter| filters << MailFilter.new_from_xml(filter); filters }
end

#mail_remove_filter(address, filter_on, filter, action, action_value, contains, stop, rank) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/dreamy/base.rb', line 116

def mail_remove_filter(address,filter_on,filter,action,action_value,contains,stop,rank)
    doc = request("mail-remove_filter",
      {
			"address"       => address,
			"filter_on"     => filter_on,
			"filter"        => filter,
			"action"        => action,
			"action_value"  => action_value,
			"contains"      => contains,
			"stop"          => stop,
			"rank"          => rank
      })
    api_error?(doc)
	true
end

#mysql_dbsObject



132
133
134
135
136
# File 'lib/dreamy/base.rb', line 132

def mysql_dbs
  doc = request("mysql-list_dbs")
  api_error?(doc)
  (doc/:data).inject([]) { |dbs, db| dbs << MysqlDb.new_from_xml(db); dbs }
end

#mysql_hostsObject



138
139
140
141
142
# File 'lib/dreamy/base.rb', line 138

def mysql_hosts
  doc = request("mysql-list_hostnames")
  api_error?(doc)
  (doc/:data).inject([]) { |hosts, host| hosts << MysqlHost.new_from_xml(host); hosts }
end

#mysql_usersObject



144
145
146
147
148
# File 'lib/dreamy/base.rb', line 144

def mysql_users
  doc = request("mysql-list_users")
  api_error?(doc)
  (doc/:data).inject([]) { |users, user| users << MysqlUser.new_from_xml(user); users }
end

#psObject



150
151
152
153
154
# File 'lib/dreamy/base.rb', line 150

def ps
  doc = request("dreamhost_ps-list_ps")
  api_error?(doc)
  (doc/:data).inject([]) { |servers, server| servers << PrivateServer.new_from_xml(server); servers }
end

#ps_add(type, movedata = "no") ⇒ Object



198
199
200
201
202
# File 'lib/dreamy/base.rb', line 198

def ps_add(type,movedata="no")
  doc = request("dreamhost_ps-add_ps", {"type" => type, "movedata" => movedata})
  api_error?(doc)
  true
end

#ps_pendingObject



210
211
212
213
214
# File 'lib/dreamy/base.rb', line 210

def ps_pending
  doc = request("dreamhost_ps-list_pending_ps")
  api_error?(doc)
  (doc/:data).inject([]) { |pends, pend| pends << PrivateServer.pending_from_xml(pend); pends }
end

#ps_reboot!(name) ⇒ Object



186
187
188
189
190
# File 'lib/dreamy/base.rb', line 186

def ps_reboot!(name)
  doc = request("dreamhost_ps-reboot", {"ps" => name})
  api_error?(doc)
  true
end

#ps_reboot_history(name) ⇒ Object



180
181
182
183
184
# File 'lib/dreamy/base.rb', line 180

def ps_reboot_history(name)
  doc = request("dreamhost_ps-list_reboot_history", {"ps" => name})
  api_error?(doc)
  (doc/:data).inject([]) { |reboots,reboot| reboots << reboot.at('stamp').innerHTML; reboots }
end

#ps_removeObject



204
205
206
207
208
# File 'lib/dreamy/base.rb', line 204

def ps_remove
  doc = request("dreamhost_ps-remove_pending_ps")
  api_error?(doc)
  true
end

#ps_set(name, setting, value) ⇒ Object



162
163
164
165
166
# File 'lib/dreamy/base.rb', line 162

def ps_set(name,setting,value)
  doc = request("dreamhost_ps-set_settings", {"ps" => name, setting => value})
  api_error?(doc)
  true
end

#ps_settings(name) ⇒ Object



156
157
158
159
160
# File 'lib/dreamy/base.rb', line 156

def ps_settings(name)
  doc = request("dreamhost_ps-list_settings", {"ps" => name})
  api_error?(doc)
  PrivateServer.settings_from_xml(doc)
end

#ps_size_history(name) ⇒ Object



168
169
170
171
172
# File 'lib/dreamy/base.rb', line 168

def ps_size_history(name)
  doc = request("dreamhost_ps-list_size_history", {"ps" => name})
  api_error?(doc)
  (doc/:data).inject([]) { |sizes, size| sizes << PrivateServer.size_from_xml(size); sizes }
end

#ps_size_set(name, size) ⇒ Object



174
175
176
177
178
# File 'lib/dreamy/base.rb', line 174

def ps_size_set(name,size)
  doc = request("dreamhost_ps-set_size", {"ps" => name, "size" => size})
  api_error?(doc)
  true
end

#ps_usage(name) ⇒ Object



192
193
194
195
196
# File 'lib/dreamy/base.rb', line 192

def ps_usage(name)
  doc = request("dreamhost_ps-list_usage", {"ps" => name})
  api_error?(doc)
  (doc/:data).inject([]) { |usages, usage| usages << PrivateServer.usage_from_xml(usage); usages }
end

#users(passwords = false) ⇒ Object

returns an array of user objects



19
20
21
22
23
24
25
26
27
# File 'lib/dreamy/base.rb', line 19

def users(passwords=false)
  if passwords
    doc = request("user-list_users")
  else
    doc = request("user-list_users_no_pw")
  end
  api_error?(doc)
  (doc/:data).inject([]) { |users, user| users << User.new_from_xml(user); users }
end