Class: Lumberg::Cpanel::Base
- Defined in:
- lib/lumberg/cpanel/base.rb
Direct Known Subclasses
AddonDomain, Backups, BoxTrapper, Branding, Contact, Cron, DnsLookup, DomainKeys, DomainLookup, Email, FileManager, Ftp, Gpg, Locale, Mime, Mysql, MysqlDb, Net, Park, Password, PasswordStrength, RandomData, Redirect, Ssl, SubDomain, Support, ZoneEdit
Instance Attribute Summary collapse
-
#api_username ⇒ Object
Returns the value of attribute api_username.
Attributes inherited from Whm::Base
Class Method Summary collapse
-
.api_module ⇒ Object
Public: Gets cPanel API module name based on class name.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
Public: Initialize a new cPanel API interface.
-
#perform_request(options = {}) ⇒ Object
Public: Perform a cPanel API method call.
Methods inherited from Whm::Base
Constructor Details
#initialize(options = {}) ⇒ Base
Public: Initialize a new cPanel API interface.
options - Hash options (default: {}):
:api_username - String username to set as the default account
username for cPanel API calls (optional).
20 21 22 23 24 |
# File 'lib/lumberg/cpanel/base.rb', line 20 def initialize( = {}) @api_username = .delete(:api_username) super end |
Instance Attribute Details
#api_username ⇒ Object
Returns the value of attribute api_username.
4 5 6 |
# File 'lib/lumberg/cpanel/base.rb', line 4 def api_username @api_username end |
Class Method Details
.api_module ⇒ Object
Public: Gets cPanel API module name based on class name. This method should be overriden in subclasses where the cPanel API module name and the class name don’t match up.
Returns String cPanel API module name.
11 12 13 |
# File 'lib/lumberg/cpanel/base.rb', line 11 def self.api_module self.name.split("::").last end |
Instance Method Details
#perform_request(options = {}) ⇒ Object
Public: Perform a cPanel API method call.
options - Hash options for API call params (default: {}):
:api_function - String API function name to call.
:api_module - String API module on which API function will be
called (optional, default: self.class.api_module).
:response_key - String key used to select desired part of API
response (optional, default: "cpanelresult").
:api_username - String account username for API call (optional,
default: @api_username)
:api_version - Integer cPanel API version to use (optional,
default: 2)
Returns Hash API response.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lumberg/cpanel/base.rb', line 40 def perform_request( = {}) [:api_username] ||= api_username api_module = .delete(:api_module) || self.class.api_module params = { response_key: .delete(:response_key) || "cpanelresult", cpanel_jsonapi_user: .delete(:api_username), cpanel_jsonapi_module: api_module, cpanel_jsonapi_func: .delete(:api_function), cpanel_jsonapi_apiversion: .delete(:api_version) || 2, }.merge() server.perform_request("cpanel", params) end |