Class: Panelbeater::Response

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

Constant Summary collapse

@@response_types =
{
  :applist        => 'app',
  :createacct     => 'result',
  :changepackage  => 'result',
  :passwd         => 'passwd',
  :suspendacct    => 'result',
  :unsuspendacct  => 'result',
  :removeacct     => 'result'
}

Instance Method Summary collapse

Constructor Details

#initialize(command, response) ⇒ Response

Returns a new instance of Response.



14
15
16
17
# File 'lib/panelbeater/response.rb', line 14

def initialize(command, response)
  @command  = command
  @response = response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/panelbeater/response.rb', line 31

def method_missing(method, *args)
  # check for a key in the json response
  if json[node_name].respond_to? 'first'
    if json[node_name].first.respond_to?('has_key?') && json[node_name].first.has_key?(method.to_s)
      json[node_name].first[method.to_s]
    end
  end
end

Instance Method Details

#codeObject



23
24
25
# File 'lib/panelbeater/response.rb', line 23

def code
  @response.code
end

#jsonObject



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

def json
  JSON.parse @response.body
end

#success?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/panelbeater/response.rb', line 19

def success?
  self.status == 1
end