Class: CpanelRuby::API::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/cpanel_ruby/api/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.default_options.update(verify: false)
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



6
7
8
# File 'lib/cpanel_ruby/api/service.rb', line 6

def address
  @address
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/cpanel_ruby/api/service.rb', line 6

def port
  @port
end

#queryObject

Returns the value of attribute query.



6
7
8
# File 'lib/cpanel_ruby/api/service.rb', line 6

def query
  @query
end

#requestObject

Returns the value of attribute request.



6
7
8
# File 'lib/cpanel_ruby/api/service.rb', line 6

def request
  @request
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/cpanel_ruby/api/service.rb', line 6

def token
  @token
end

#usernameObject

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  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  params
  set_request("createacct")

  response = HTTParty.post self.url, query: params, headers: self.headers
  CpanelRuby::API::Account::CreateAccountResponse.new response
end

#headersObject



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_accountObject



57
58
59
60
61
62
# File 'lib/cpanel_ruby/api/service.rb', line 57

def 
  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  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  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  params
  set_request("unsuspendacct")

  response = HTTParty.get self.url, query: params, headers: self.headers
  CpanelRuby::API::Account::UnsuspendAccountResponse.new response
end

#urlObject



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