Module: Mastercontrol::Accounts
- Defined in:
- lib/mastercontrol/accounts.rb
Defined Under Namespace
Classes: WhmAccount
Class Method Summary collapse
- .list ⇒ Object
- .parse_account(whm_account) ⇒ Object
- .retrieve(username) ⇒ Object
- .suspend(username, reason) ⇒ Object
- .unsuspend(username) ⇒ Object
Class Method Details
.list ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mastercontrol/accounts.rb', line 13 def self.list url = "#{Mastercontrol.base_url}/listaccts?api.version=1" response = RestClient.get url, {authorization: Mastercontrol.auth_header} # parse the json json_response = JSON.parse(response) return_array = [] # build and return the ServerLoad Object json_response['data']['acct'].each do |account| return_array << parse_account(account) end return_array end |
.parse_account(whm_account) ⇒ Object
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 |
# File 'lib/mastercontrol/accounts.rb', line 72 def self.parse_account(whm_account) account = WhmAccount.new account.max_addons = whm_account["maxaddons"] account.ip = whm_account["ip"] account.ipv6 = whm_account["ipv6"] account.outgoing_mail_suspended = Integer(whm_account["outgoing_mail_suspended"]) account.outgoing_mail_hold = Integer(whm_account["outgoing_mail_hold"]) account.min_defer_fail_to_trigger_protection = Integer(whm_account["min_defer_fail_to_trigger_protection"]) account.legacy_backup = Integer(whm_account["legacy_backup"]) account.disk_used = whm_account["diskused"] account.max_ftp = whm_account["maxftp"] account.start_date = whm_account["startdate"] account.max_defer_fail_percentage = Integer(whm_account["max_defer_fail_percentage"]) account.disk_limit = whm_account["disklimit"] account.is_locked = Integer(whm_account["is_locked"]) account.suspend_time = whm_account["suspendtime"] account.email = whm_account["email"] account.domain = whm_account["domain"] account.unix_startdate = whm_account["unix_startdate"] account.user = whm_account["user"] account.plan = whm_account["plan"] account.shell = whm_account["shell"] account.max_pop = whm_account["maxpop"] account.backup = Integer(whm_account["backup"]) account.theme = whm_account["theme"] account.owner = whm_account["owner"] account.max_email_per_hour = whm_account["max_email_per_hour"] account.suspend_reason = whm_account["suspendreason"] account.max_list = whm_account["maxlst"] account.suspended = Integer(whm_account["suspended"]) account.max_sql = whm_account["maxsql"] account.max_parked = whm_account["maxparked"] account.partition = whm_account["partition"] account.max_sub = whm_account["maxsub"] account end |
.retrieve(username) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mastercontrol/accounts.rb', line 28 def self.retrieve(username) url = "#{Mastercontrol.base_url}/accountsummary?api.version=1&user=#{username}" response = RestClient.get url, {authorization: Mastercontrol.auth_header} # parse the json json_response = JSON.parse(response) if json_response["data"]["acct"].nil? return nil end whm_account = json_response["data"]["acct"][0] parse_account(whm_account) end |
.suspend(username, reason) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mastercontrol/accounts.rb', line 44 def self.suspend(username, reason) url = "#{Mastercontrol.base_url}/suspendacct?api.version=1&user=#{username}&reason=#{reason}" response = RestClient.get url, {authorization: Mastercontrol.auth_header} # parse the json json_response = JSON.parse(response) if json_response["metadata"]["result"].to_i == 1 return true else return false end end |
.unsuspend(username) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mastercontrol/accounts.rb', line 58 def self.unsuspend(username) url = "#{Mastercontrol.base_url}/unsuspendacct?api.version=1&user=#{username}" response = RestClient.get url, {authorization: Mastercontrol.auth_header} # parse the json json_response = JSON.parse(response) if json_response["metadata"]["result"].to_i == 1 return true else return false end end |