Class: CpanelRuby::API::Service
- Inherits:
-
Object
- Object
- CpanelRuby::API::Service
- Defined in:
- lib/cpanel_ruby/api/service.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#port ⇒ Object
Returns the value of attribute port.
-
#query ⇒ Object
Returns the value of attribute query.
-
#request ⇒ Object
Returns the value of attribute request.
-
#token ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #account_summary(params) ⇒ Object
- #change_password(params) ⇒ Object
- #create_account(params) ⇒ Object
- #headers ⇒ Object
-
#initialize(params = {}) ⇒ Service
constructor
A new instance of Service.
- #limit_bw(params) ⇒ Object
- #list_account ⇒ Object
- #remove_account(params) ⇒ Object
- #set_request(request) ⇒ Object
- #show_bw(params) ⇒ Object
- #suspend_account(params) ⇒ Object
- #unsuspend_account(params) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Service
Returns a new instance of Service.
8 9 10 11 12 13 14 15 |
# File 'lib/cpanel_ruby/api/service.rb', line 8 def initialize params = {} self.address = params[:address] self.port = params[:port] self.username = params[:username] self.token = params[:token] HTTParty::Basement..update(verify: false) end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
6 7 8 |
# File 'lib/cpanel_ruby/api/service.rb', line 6 def address @address end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/cpanel_ruby/api/service.rb', line 6 def port @port end |
#query ⇒ Object
Returns the value of attribute query.
6 7 8 |
# File 'lib/cpanel_ruby/api/service.rb', line 6 def query @query end |
#request ⇒ Object
Returns the value of attribute request.
6 7 8 |
# File 'lib/cpanel_ruby/api/service.rb', line 6 def request @request end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/cpanel_ruby/api/service.rb', line 6 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/cpanel_ruby/api/service.rb', line 6 def username @username end |
Instance Method Details
#account_summary(params) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/cpanel_ruby/api/service.rb', line 29 def account_summary params set_request("accountsummary") response = HTTParty.get self.url, query: params, headers: self.headers CpanelRuby::API::Account::AccountSummaryResponse.new response end |
#change_password(params) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/cpanel_ruby/api/service.rb', line 36 def change_password params set_request("passwd") response = HTTParty.post self.url, query: params, headers: self.headers CpanelRuby::API::Account::ChangePasswordResponse.new response end |
#create_account(params) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/cpanel_ruby/api/service.rb', line 43 def create_account params set_request("createacct") response = HTTParty.post self.url, query: params, headers: self.headers CpanelRuby::API::Account::CreateAccountResponse.new response end |
#headers ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cpanel_ruby/api/service.rb', line 17 def headers { 'Authorization' => "whm #{self.username}:#{self.token}", 'Content-Type' => 'application/json', 'Accept' => 'application/json' } end |
#limit_bw(params) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/cpanel_ruby/api/service.rb', line 50 def limit_bw params set_request("limitbw") response = HTTParty.post self.url, query: params, headers: self.headers CpanelRuby::API::Account::LimitBwResponse.new response end |
#list_account ⇒ Object
57 58 59 60 61 62 |
# File 'lib/cpanel_ruby/api/service.rb', line 57 def list_account set_request("listaccts") response = HTTParty.get self.url, query: {}, headers: self.headers CpanelRuby::API::Account::ListAccountResponse.new response end |
#remove_account(params) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/cpanel_ruby/api/service.rb', line 64 def remove_account params set_request("removeacct") response = HTTParty.delete self.url, query: params, headers: self.headers CpanelRuby::API::Account::RemoveAccountResponse.new response end |
#set_request(request) ⇒ Object
92 93 94 |
# File 'lib/cpanel_ruby/api/service.rb', line 92 def set_request request self.request = request end |
#show_bw(params) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/cpanel_ruby/api/service.rb', line 71 def show_bw params set_request("showbw") response = HTTParty.get self.url, query: params, headers: self.headers CpanelRuby::API::Account::ShowBwResponse.new response end |
#suspend_account(params) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/cpanel_ruby/api/service.rb', line 78 def suspend_account params set_request("suspendacct") response = HTTParty.post self.url, query: params, headers: self.headers CpanelRuby::API::Account::SuspendAccountResponse.new response end |
#unsuspend_account(params) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/cpanel_ruby/api/service.rb', line 85 def unsuspend_account params set_request("unsuspendacct") response = HTTParty.get self.url, query: params, headers: self.headers CpanelRuby::API::Account::UnsuspendAccountResponse.new response end |
#url ⇒ Object
25 26 27 |
# File 'lib/cpanel_ruby/api/service.rb', line 25 def url "#{self.address}:#{self.port}/json-api/#{self.request}?api.version=1" end |