Class: Cpanel::Server
- Inherits:
-
Object
- Object
- Cpanel::Server
- Includes:
- ActiveResource
- Defined in:
- lib/cpanel/server.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#key ⇒ Object
Returns the value of attribute key.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #request(script, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
12 13 14 15 16 17 |
# File 'lib/cpanel/server.rb', line 12 def initialize( = {}) @url = URI.parse([:url]) @key = format_key([:key]) @timeout = [:timeout] || 300 @api = [:api] || "json" end |
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
10 11 12 |
# File 'lib/cpanel/server.rb', line 10 def api @api end |
#key ⇒ Object
Returns the value of attribute key.
10 11 12 |
# File 'lib/cpanel/server.rb', line 10 def key @key end |
#timeout ⇒ Object
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/cpanel/server.rb', line 10 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/cpanel/server.rb', line 10 def url @url end |
Instance Method Details
#request(script, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cpanel/server.rb', line 23 def request(script, = {}) request = Net::HTTP::Get.new("/#{api}-api/" + script) request.add_field "Authorization", "WHM root:#{key}" request.set_form_data() unless .empty? result = http.request(request) response = handle_response(result) return Response.new(response) rescue Timeout::Error, Errno::ETIMEDOUT => e raise TimeoutError.new(e.) rescue Errno::ECONNREFUSED => e raise CommandFailed.new("Connection to cPanel server was refused; may be down or unreachable") end |