Class: Cpanel::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/cpanel/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cpanel/response.rb', line 7

def initialize(response)      
  response = ActiveSupport::JSON.decode(response)
  
  if response["result"]
    @response = response["result"][0] ? response["result"][0] : response["result"]
  else
    @response = response
  end
  
  @success = success?
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/cpanel/response.rb', line 5

def response
  @response
end

#successObject

Returns the value of attribute success.



5
6
7
# File 'lib/cpanel/response.rb', line 5

def success
  @success
end

Instance Method Details

#errorsObject



19
20
21
22
23
24
25
# File 'lib/cpanel/response.rb', line 19

def errors
  if success?
    nil
  else
    return response["statusmsg"] ? response["statusmsg"] : nil
  end
end

#success?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cpanel/response.rb', line 27

def success?
  return response["status"] ? response["status"] == 1 : true
end