module Mastercontrol::Accounts

Public Class Methods

list() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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