lumberg 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +98 -0
- data/LICENSE +20 -0
- data/README.md +178 -0
- data/Rakefile +49 -0
- data/lib/cacert.pem +3910 -0
- data/lib/lumberg.rb +23 -0
- data/lib/lumberg/exceptions.rb +6 -0
- data/lib/lumberg/version.rb +3 -0
- data/lib/lumberg/whm.rb +70 -0
- data/lib/lumberg/whm/account.rb +329 -0
- data/lib/lumberg/whm/args.rb +113 -0
- data/lib/lumberg/whm/base.rb +28 -0
- data/lib/lumberg/whm/dns.rb +205 -0
- data/lib/lumberg/whm/reseller.rb +268 -0
- data/lib/lumberg/whm/server.rb +290 -0
- data/lib/net_http_hacked.rb +42 -0
- data/lumberg.gemspec +28 -0
- data/spec/lumberg_spec.rb +9 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/vcr_cassettes/whm/account/accountsummary.yml +43 -0
- data/spec/vcr_cassettes/whm/account/changepackage.yml +64 -0
- data/spec/vcr_cassettes/whm/account/createacct.yml +43 -0
- data/spec/vcr_cassettes/whm/account/domainuserdata.yml +43 -0
- data/spec/vcr_cassettes/whm/account/editquota.yml +85 -0
- data/spec/vcr_cassettes/whm/account/limitbw.yml +85 -0
- data/spec/vcr_cassettes/whm/account/listaccts.yml +147 -0
- data/spec/vcr_cassettes/whm/account/listsuspended.yml +43 -0
- data/spec/vcr_cassettes/whm/account/modifyacct.yml +63 -0
- data/spec/vcr_cassettes/whm/account/myprivs.yml +43 -0
- data/spec/vcr_cassettes/whm/account/passwd.yml +43 -0
- data/spec/vcr_cassettes/whm/account/removeacct.yml +85 -0
- data/spec/vcr_cassettes/whm/account/restoreaccount.yml +198 -0
- data/spec/vcr_cassettes/whm/account/setsiteip.yml +190 -0
- data/spec/vcr_cassettes/whm/account/suspend.yml +64 -0
- data/spec/vcr_cassettes/whm/account/unsuspend.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/adddns.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/addzonerecord.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/dumpzone.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/editzonerecord.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/getzonerecord.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/killdns.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/listmxs.yml +22 -0
- data/spec/vcr_cassettes/whm/dns/listzones.yml +22 -0
- data/spec/vcr_cassettes/whm/dns/lookupnsip.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/removezonerecord.yml +64 -0
- data/spec/vcr_cassettes/whm/dns/resetzone.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/resolvedomainname.yml +43 -0
- data/spec/vcr_cassettes/whm/dns/savemxs.yml +22 -0
- data/spec/vcr_cassettes/whm/reseller/acctcounts.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/listacls.yml +22 -0
- data/spec/vcr_cassettes/whm/reseller/listresellers.yml +22 -0
- data/spec/vcr_cassettes/whm/reseller/resellerstats.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/saveacllist.yml +85 -0
- data/spec/vcr_cassettes/whm/reseller/setacls.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/setresellerips.yml +42 -0
- data/spec/vcr_cassettes/whm/reseller/setresellerlimits.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/setresellermainip.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/setresellernameservers.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/setresellerpackagelimit.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/setupreseller.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/suspendreseller.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/terminatereseller.yml +64 -0
- data/spec/vcr_cassettes/whm/reseller/unsetupreseller.yml +43 -0
- data/spec/vcr_cassettes/whm/reseller/unsuspendreseller.yml +43 -0
- data/spec/vcr_cassettes/whm/server/applist.yml +22 -0
- data/spec/vcr_cassettes/whm/server/gethostname.yml +22 -0
- data/spec/vcr_cassettes/whm/server/getlanglist.yml +22 -0
- data/spec/vcr_cassettes/whm/server/loadavg.yml +28 -0
- data/spec/vcr_cassettes/whm/server/my_function.yml +64 -0
- data/spec/vcr_cassettes/whm/server/response_type.yml +85 -0
- data/spec/vcr_cassettes/whm/server/systemloadavg.yml +43 -0
- data/spec/vcr_cassettes/whm/server/version.yml +22 -0
- data/spec/whm/account_spec.rb +577 -0
- data/spec/whm/args_spec.rb +179 -0
- data/spec/whm/base_spec.rb +28 -0
- data/spec/whm/dns_spec.rb +352 -0
- data/spec/whm/reseller_spec.rb +359 -0
- data/spec/whm/server_spec.rb +288 -0
- data/spec/whm/whm_spec.rb +41 -0
- metadata +265 -0
data/lib/lumberg.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
# External Libs
|
4
|
+
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http'
|
7
|
+
require 'net/https'
|
8
|
+
|
9
|
+
# Internal Libs
|
10
|
+
require 'net_http_hacked'
|
11
|
+
require 'lumberg/version'
|
12
|
+
require 'lumberg/exceptions'
|
13
|
+
require 'lumberg/whm/args'
|
14
|
+
require 'lumberg/whm'
|
15
|
+
|
16
|
+
module Lumberg
|
17
|
+
class << self
|
18
|
+
def base_path
|
19
|
+
File.dirname(__FILE__)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/lib/lumberg/whm.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Lumberg
|
2
|
+
module Whm
|
3
|
+
autoload :Base, 'lumberg/whm/base'
|
4
|
+
autoload :Server, 'lumberg/whm/server'
|
5
|
+
autoload :Account, 'lumberg/whm/account'
|
6
|
+
autoload :Dns, 'lumberg/whm/dns'
|
7
|
+
autoload :Reseller, 'lumberg/whm/reseller'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
# Converts keys to symbols
|
12
|
+
def symbolize_keys(arg)
|
13
|
+
case arg
|
14
|
+
when Array
|
15
|
+
arg.map { |elem| symbolize_keys elem }
|
16
|
+
when Hash
|
17
|
+
Hash[
|
18
|
+
arg.map { |key, value|
|
19
|
+
k = key.is_a?(String) ? key.gsub('-', '_').to_sym : key
|
20
|
+
v = symbolize_keys value
|
21
|
+
[k,v]
|
22
|
+
}]
|
23
|
+
else
|
24
|
+
arg
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Recursively converts values of 0 or 1 to true or false
|
29
|
+
def to_bool(hash, *keys)
|
30
|
+
if keys.empty?
|
31
|
+
keys = [:all]
|
32
|
+
else
|
33
|
+
keys.flatten!
|
34
|
+
end
|
35
|
+
|
36
|
+
if hash.is_a?(Hash)
|
37
|
+
hash = Hash[
|
38
|
+
hash.map {|key, value|
|
39
|
+
# recurse
|
40
|
+
value = to_bool(value, keys) if value.is_a?(Hash)
|
41
|
+
value = value.map {|elem| to_bool(elem, keys) } if value.is_a?(Array)
|
42
|
+
|
43
|
+
if (keys.first == :all) || (keys.include?(key) || (keys.include?(key.to_sym)))
|
44
|
+
value = (value.to_s.match(/0|1/) ? value.to_i == 1 : value)
|
45
|
+
end
|
46
|
+
[key, value]
|
47
|
+
}]
|
48
|
+
end
|
49
|
+
hash
|
50
|
+
end
|
51
|
+
|
52
|
+
# Converts boolean values to 0 or 1
|
53
|
+
def from_bool(input)
|
54
|
+
if input == false
|
55
|
+
0
|
56
|
+
elsif input == true
|
57
|
+
1
|
58
|
+
elsif input.is_a?(Hash)
|
59
|
+
Hash[
|
60
|
+
input.map {|k,v|
|
61
|
+
v = from_bool(v)
|
62
|
+
[k,v]
|
63
|
+
}
|
64
|
+
]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,329 @@
|
|
1
|
+
module Lumberg
|
2
|
+
module Whm
|
3
|
+
# Some WHM functions require different params for the same 'thing'
|
4
|
+
# e.g. some accept 'username' while others accept 'user'
|
5
|
+
# Be sure to keep our API consistent and work around those inconsistencies internally
|
6
|
+
class Account < Base
|
7
|
+
|
8
|
+
# Creates a hosting account and sets up its associated domain information
|
9
|
+
#
|
10
|
+
# ==== Required
|
11
|
+
# * <tt>:username</tt> - PENDING
|
12
|
+
# * <tt>:domain</tt> - PENDING
|
13
|
+
# * <tt>:password</tt> - PENDING
|
14
|
+
#
|
15
|
+
# ==== Optional
|
16
|
+
# * <tt>:plan</tt> - PENDING
|
17
|
+
# * <tt>:pkgname</tt> - PENDING
|
18
|
+
# * <tt>:savepkg</tt> - PENDING
|
19
|
+
# * <tt>:featurelist</tt> - PENDING
|
20
|
+
# * <tt>:quota</tt> - PENDING
|
21
|
+
# * <tt>:ip</tt> - PENDING
|
22
|
+
# * <tt>:cgi</tt> - PENDING
|
23
|
+
# * <tt>:</tt> - PENDING
|
24
|
+
def create(options = {})
|
25
|
+
Args.new(options) do |c|
|
26
|
+
c.requires :username, :domain, :password
|
27
|
+
c.booleans :savepkg, :ip, :cgi, :frontpage, :hasshell, :useregns, :reseller, :forcedns
|
28
|
+
c.optionals :plan, :pkgname, :savepkg, :featurelist, :quota, :ip, :cgi,
|
29
|
+
:frontpage, :hasshell, :contactemail, :cpmod, :maxftp, :maxsql, :maxpop, :maxlst,
|
30
|
+
:maxsub, :maxpark, :maxaddon, :bwlimit, :customip, :language, :useregns, :hasuseregns,
|
31
|
+
:reseller, :forcedns, :mxcheck
|
32
|
+
end
|
33
|
+
|
34
|
+
server.perform_request('createacct', options)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Permanently removes a cPanel account
|
38
|
+
#
|
39
|
+
# ==== Required
|
40
|
+
# * <tt>:username</tt> - PENDING
|
41
|
+
def remove(options = {})
|
42
|
+
Args.new(options) do |c|
|
43
|
+
c.requires :username
|
44
|
+
c.booleans :keepdns
|
45
|
+
end
|
46
|
+
|
47
|
+
options[:user] = options.delete(:username)
|
48
|
+
server.perform_request('removeacct', options)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Changes the password of a domain owner (cPanel) or reseller (WHM) account
|
52
|
+
#
|
53
|
+
# ==== Required
|
54
|
+
# * <tt>:username</tt> - PENDING
|
55
|
+
# * <tt>:password</tt> - PENDING
|
56
|
+
def change_password(options = {})
|
57
|
+
Args.new(options) do |c|
|
58
|
+
c.requires :username, :password
|
59
|
+
c.booleans :db_pass_update
|
60
|
+
end
|
61
|
+
|
62
|
+
options[:user] = options.delete(:username)
|
63
|
+
options[:pass] = options.delete(:password)
|
64
|
+
server.perform_request('passwd', options.merge(:key => 'passwd'))
|
65
|
+
end
|
66
|
+
|
67
|
+
# Displays pertinent information about a specific account
|
68
|
+
#
|
69
|
+
# ==== Required
|
70
|
+
# * <tt>:username</tt> - PENDING
|
71
|
+
def summary(options = {})
|
72
|
+
Args.new(options) do |c|
|
73
|
+
c.requires :username
|
74
|
+
end
|
75
|
+
|
76
|
+
options[:user] = options.delete(:username)
|
77
|
+
server.perform_request('accountsummary', options)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Modifies the bandwidth usage (transfer) limit for a specific account
|
81
|
+
#
|
82
|
+
# ==== Required
|
83
|
+
# * <tt>:username</tt> - PENDING
|
84
|
+
# * <tt>:bwlimit</tt> - PENDING
|
85
|
+
def limit_bandwidth(options = {})
|
86
|
+
Args.new(options) do |c|
|
87
|
+
c.requires :username, :bwlimit
|
88
|
+
end
|
89
|
+
|
90
|
+
verify_user(options[:username]) do
|
91
|
+
options[:user] = options.delete(:username)
|
92
|
+
server.perform_request('limitbw', options) do |s|
|
93
|
+
s.boolean_params = :unlimited, :bwlimitenable
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Lists all accounts on the server, and also allows you to search for a specific account or set of accounts
|
99
|
+
|
100
|
+
#
|
101
|
+
# ==== Optional
|
102
|
+
# * <tt>:searchtype</tt> - PENDING
|
103
|
+
# * <tt>:search</tt> - PENDING
|
104
|
+
def list(options = {})
|
105
|
+
Args.new(options) do |c|
|
106
|
+
c.optionals :searchtype, :search
|
107
|
+
end
|
108
|
+
|
109
|
+
server.perform_request('listaccts', options) do |s|
|
110
|
+
s.boolean_params = :suspended
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Modifies settings for an account
|
115
|
+
#
|
116
|
+
# ==== Required
|
117
|
+
# * <tt>:username</tt> - PENDING
|
118
|
+
#
|
119
|
+
# ==== Optional
|
120
|
+
# * <tt>:domain</tt> - PENDING
|
121
|
+
# * <tt>:newuser</tt> - PENDING
|
122
|
+
# * <tt>:owner</tt> - PENDING
|
123
|
+
# * <tt>:CPTHEME</tt> - PENDING
|
124
|
+
# * <tt>:HASCGI</tt> - PENDING
|
125
|
+
# * <tt>:LANG</tt> - PENDING
|
126
|
+
# * <tt>:LOCALE</tt> - PENDING
|
127
|
+
# * <tt>:MAXFTP</tt> - PENDING
|
128
|
+
# * <tt>:MAXSQL</tt> - PENDING
|
129
|
+
# * <tt>:MAXPOP</tt> - PENDING
|
130
|
+
# * <tt>:MAXLST</tt> - PENDING
|
131
|
+
# * <tt>:MAXSUB</tt> - PENDING
|
132
|
+
# * <tt>:MAXPARK</tt> - PENDING
|
133
|
+
# * <tt>:MAXADDON</tt> - PENDING
|
134
|
+
# * <tt>:shell</tt> - PENDING
|
135
|
+
def modify(options = {})
|
136
|
+
Args.new(options) do |c|
|
137
|
+
c.requires :username
|
138
|
+
c.optionals :domain, :newuser, :owner, :CPTHEME, :HASCGI, :LANG, :LOCALE, :MAXFTP, :MAXSQL, :MAXPOP, :MAXLST, :MAXSUB, :MAXPARK, :MAXADDON, :shell
|
139
|
+
end
|
140
|
+
|
141
|
+
options[:user] = options.delete(:username)
|
142
|
+
server.perform_request('modifyacct', options) do |s|
|
143
|
+
s.boolean_params = :DEMO
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Changes an account's disk space usage quota
|
148
|
+
#
|
149
|
+
# ==== Required
|
150
|
+
# * <tt>:username</tt> - PENDING
|
151
|
+
# * <tt>:quota</tt> - PENDING
|
152
|
+
def edit_quota(options = {})
|
153
|
+
Args.new(options) do |c|
|
154
|
+
c.requires :username, :quota
|
155
|
+
end
|
156
|
+
|
157
|
+
options[:user] = options.delete(:username)
|
158
|
+
server.perform_request('editquota', options)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Adds a new hosting package
|
162
|
+
#
|
163
|
+
# ==== Required
|
164
|
+
# * <tt>:name</tt> - PENDING
|
165
|
+
#
|
166
|
+
# ==== Optional
|
167
|
+
# * <tt>:featurelist</tt> - PENDING
|
168
|
+
# * <tt>:quota</tt> - PENDING
|
169
|
+
# * <tt>:ip</tt> - PENDING
|
170
|
+
# * <tt>:cgi</tt> - PENDING
|
171
|
+
# * <tt>:frontpage</tt> - PENDING
|
172
|
+
# * <tt>:cpmod</tt> - PENDING
|
173
|
+
# * <tt>:language</tt> - PENDING
|
174
|
+
# * <tt>:maxftp</tt> - PENDING
|
175
|
+
# * <tt>:maxsql</tt> - PENDING
|
176
|
+
# * <tt>:maxpop</tt> - PENDING
|
177
|
+
# * <tt>:maxlists</tt> - PENDING
|
178
|
+
# * <tt>:maxsub</tt> - PENDING
|
179
|
+
# * <tt>:maxpark</tt> - PENDING
|
180
|
+
# * <tt>:maxaddon</tt> - PENDING
|
181
|
+
# * <tt>:hasshell</tt> - PENDING
|
182
|
+
# * <tt>:bwlimit</tt> - PENDING
|
183
|
+
def add_package(options = {})
|
184
|
+
Args.new(options) do |c|
|
185
|
+
c.requires :name
|
186
|
+
c.optionals :featurelist, :quota, :ip, :cgi, :frontpage, :cpmod, :language, :maxftp, :maxsql, :maxpop, :maxlists, :maxsub, :maxpark, :maxaddon, :hasshell, :bwlimit
|
187
|
+
c.booleans :ip, :cgi, :frontpage, :hasshell
|
188
|
+
end
|
189
|
+
|
190
|
+
server.perform_request('addpkg', options)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Changes the hosting package associated with a cPanel account
|
194
|
+
#
|
195
|
+
# ==== Required
|
196
|
+
# * <tt>:username</tt> - PENDING
|
197
|
+
# * <tt>:pkg</tt> - PENDING
|
198
|
+
def change_package(options = {})
|
199
|
+
Args.new(options) do |c|
|
200
|
+
c.requires :username, :pkg
|
201
|
+
end
|
202
|
+
|
203
|
+
options[:user] = options.delete(:username)
|
204
|
+
server.perform_request('changepackage', options)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Obtains user data for a specific domain
|
208
|
+
#
|
209
|
+
# ==== Required
|
210
|
+
# * <tt>:domain</tt> - PENDING
|
211
|
+
def domain_user_data(options = {})
|
212
|
+
Args.new(options) do |c|
|
213
|
+
c.requires :domain
|
214
|
+
end
|
215
|
+
|
216
|
+
server.perform_request('domainuserdata', options.merge(:key => 'userdata')) do |s|
|
217
|
+
s.boolean_params = :hascgi
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# Prevents a cPanel user from accessing his or her account. Once an account is suspended, it can be un-suspended to allow a user to access the account again
|
222
|
+
#
|
223
|
+
# ==== Required
|
224
|
+
# * <tt>:username</tt> - PENDING
|
225
|
+
#
|
226
|
+
# ==== Optional
|
227
|
+
# * <tt>:reason</tt> - PENDING
|
228
|
+
def suspend(options ={})
|
229
|
+
Args.new(options) do |c|
|
230
|
+
c.requires :username
|
231
|
+
c.optionals :reason
|
232
|
+
end
|
233
|
+
|
234
|
+
options[:user] = options.delete(:username)
|
235
|
+
server.perform_request('suspendacct', options)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Unsuspend a suspended account. When a user's account is unsuspended, he or she will be able to access cPanel again
|
239
|
+
#
|
240
|
+
# ==== Required
|
241
|
+
# * <tt>:username</tt> - PENDING
|
242
|
+
def unsuspend(options ={})
|
243
|
+
Args.new(options) do |c|
|
244
|
+
c.requires :username
|
245
|
+
end
|
246
|
+
|
247
|
+
options[:user] = options.delete(:username)
|
248
|
+
server.perform_request('unsuspendacct', options)
|
249
|
+
end
|
250
|
+
|
251
|
+
# Generates a list of suspended accounts
|
252
|
+
def list_suspended(options = {})
|
253
|
+
server.perform_request('listsuspended', options)
|
254
|
+
end
|
255
|
+
|
256
|
+
# Generates a list of features you are allowed to use in WHM. Each feature will display either a 1 or 0. You are only able to use features with a corresponding 1
|
257
|
+
#
|
258
|
+
# ==== Required
|
259
|
+
# * <tt>:username</tt> - PENDING
|
260
|
+
def privs(options ={})
|
261
|
+
Args.new(options) do |c|
|
262
|
+
c.requires :username
|
263
|
+
end
|
264
|
+
|
265
|
+
verify_user(options[:username]) do
|
266
|
+
resp = server.perform_request('myprivs', options.merge(:key => 'privs')) do |s|
|
267
|
+
s.boolean_params = :all
|
268
|
+
end
|
269
|
+
# if you get this far, it's successful
|
270
|
+
resp[:success] = true
|
271
|
+
resp
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# Changes the IP address of a website, or a user account, hosted on your server
|
276
|
+
#
|
277
|
+
# ==== Required
|
278
|
+
# * <tt>:ip</tt> - PENDING
|
279
|
+
def set_site_ip(options = {})
|
280
|
+
Args.new(options) do |c|
|
281
|
+
c.requires :ip
|
282
|
+
c.one_of :username, :domain
|
283
|
+
end
|
284
|
+
|
285
|
+
options[:user] = options.delete(:username) if options[:username]
|
286
|
+
server.perform_request('setsiteip', options)
|
287
|
+
end
|
288
|
+
|
289
|
+
# Restores a user's account from a backup file. You may restore a monthly, weekly, or daily backup
|
290
|
+
#
|
291
|
+
# ==== Required
|
292
|
+
# * <tt>:username</tt> - PENDING
|
293
|
+
# * <tt>:type</tt> - PENDING
|
294
|
+
# * <tt>:all</tt> - PENDING
|
295
|
+
# * <tt>:ip</tt> - PENDING
|
296
|
+
# * <tt>:mail</tt> - PENDING
|
297
|
+
# * <tt>:mysql</tt> - PENDING
|
298
|
+
# * <tt>:subs</tt> - PENDING
|
299
|
+
def restore_account(options = {})
|
300
|
+
Args.new(options) do |c|
|
301
|
+
c.requires "api.version".to_sym, :username, :type, :all, :ip, :mail, :mysql, :subs
|
302
|
+
c.booleans :all, :ip, :mail, :mysql, :subs
|
303
|
+
end
|
304
|
+
|
305
|
+
options[:user] = options.delete(:username) if options[:username]
|
306
|
+
server.perform_request('restoreaccount', options.merge(:key => 'metadata'))
|
307
|
+
end
|
308
|
+
|
309
|
+
protected
|
310
|
+
# Some WHM API methods always return a result, even if the user
|
311
|
+
# doesn't actually exist. This makes it seem like your request
|
312
|
+
# was successful when it really wasn't
|
313
|
+
#
|
314
|
+
# Example
|
315
|
+
# verify_user('bob') do
|
316
|
+
# change_password()
|
317
|
+
# end
|
318
|
+
def verify_user(username, &block)
|
319
|
+
exists = summary(:username => username)
|
320
|
+
if exists[:success]
|
321
|
+
yield
|
322
|
+
else
|
323
|
+
raise WhmInvalidUser, "User #{username} does not exist"
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Lumberg
|
2
|
+
|
3
|
+
#
|
4
|
+
# ==== Optional
|
5
|
+
# * <tt>:whatever</tt> - PENDING
|
6
|
+
module Whm
|
7
|
+
class Args
|
8
|
+
attr_reader :required_params, :boolean_params, :optional_params, :one_of_params
|
9
|
+
attr_reader :options
|
10
|
+
# Check the included hash for the included parameters.
|
11
|
+
# Raises WhmArgumentError when it's mising the proper params
|
12
|
+
#
|
13
|
+
# ==== Example
|
14
|
+
#
|
15
|
+
# Args.new(options) do |c|
|
16
|
+
# c.requries :user, :pass
|
17
|
+
# c.booleans :name
|
18
|
+
# c.optionals :whatever
|
19
|
+
# end
|
20
|
+
def initialize(options)
|
21
|
+
@required_params ||= []
|
22
|
+
@boolean_params ||= []
|
23
|
+
@optional_params ||= []
|
24
|
+
@one_of_params ||= []
|
25
|
+
@options = options
|
26
|
+
|
27
|
+
yield self
|
28
|
+
|
29
|
+
requires!
|
30
|
+
booleans!
|
31
|
+
one_ofs!
|
32
|
+
valid_options!
|
33
|
+
end
|
34
|
+
|
35
|
+
# Specifies the required arguments
|
36
|
+
def requires(*values)
|
37
|
+
@optional_params.concat(values)
|
38
|
+
@required_params = values
|
39
|
+
end
|
40
|
+
|
41
|
+
# Specifies which arguments are boolean
|
42
|
+
def booleans(*values)
|
43
|
+
@optional_params.concat(values)
|
44
|
+
@boolean_params = values
|
45
|
+
end
|
46
|
+
|
47
|
+
# Specifies which arguments are optional
|
48
|
+
def optionals(*values)
|
49
|
+
@optional_params.concat(values)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Specifies which arguments take one of a set of arguments
|
53
|
+
def one_of(*values)
|
54
|
+
@optional_params.concat(values)
|
55
|
+
@one_of_params = values
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
# Verifies that all required arguments are present
|
61
|
+
def requires!
|
62
|
+
@required_params.each do |param|
|
63
|
+
key = (param.is_a?(Array) ? param.first : param)
|
64
|
+
verify_required_param(key)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# Checks to see if supplied params (which are booleans) contain
|
70
|
+
# either a 1 ("Yes") or 0 ("No") value.
|
71
|
+
def booleans!
|
72
|
+
@boolean_params.each do |param|
|
73
|
+
key = (param.is_a?(Array) ? param.first : param)
|
74
|
+
verify_boolean_param(key)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Verifies that only valid arguments were set
|
79
|
+
def valid_options!
|
80
|
+
@options.keys.uniq.each do |key|
|
81
|
+
raise WhmArgumentError.new("Not a valid parameter: #{key}") unless @optional_params.include?(key)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Verifies that the one_of arguments were used correctly
|
86
|
+
def one_ofs!
|
87
|
+
if @one_of_params.size > 1
|
88
|
+
specified = @options.keys.select { |key| @one_of_params.include?(key) }.uniq
|
89
|
+
if specified.size > 1 || specified.size == 0
|
90
|
+
raise WhmArgumentError.new("The parameters may include only one of '#{@one_of_params.join(', ')}'")
|
91
|
+
end
|
92
|
+
else
|
93
|
+
raise WhmArgumentError.new("One of requires two or more items") unless @one_of_params.empty?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
# Internal method for verifiying required arguments
|
100
|
+
def verify_required_param(param)
|
101
|
+
raise WhmArgumentError.new("Missing required parameter: #{param}") unless @options.has_key?(param)
|
102
|
+
raise WhmArgumentError.new("Required parameter cannot be blank: #{param}") if (@options[param].nil? || (@options[param].respond_to?(:empty?) && @options[param].empty?))
|
103
|
+
end
|
104
|
+
|
105
|
+
# Internal method for verifying boolean arguments
|
106
|
+
def verify_boolean_param(param)
|
107
|
+
if @options.include?(param) && ![true, false].include?(@options[param])
|
108
|
+
raise WhmArgumentError.new("Boolean parameter must be \"true\" or \"false\": #{param}")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|