Class: FaceB::Api::Response

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

Overview

Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Response

Returns a new instance of Response.

Raises:



43
44
45
46
# File 'lib/faceb/api.rb', line 43

def initialize(data)
  @data = data
  raise Error.new(data["error_code"], data["error_msg"]) if data.respond_to?(:include?) && data.include?("error_msg")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/faceb/api.rb', line 48

def method_missing(name, *args)
  if @data.is_a?(Hash)
    @data[name.to_s]
  elsif @data.is_a?(Array) && @data.size == 1 && @data.first.is_a?(Hash)
    @data.first[name.to_s]
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



41
42
43
# File 'lib/faceb/api.rb', line 41

def data
  @data
end

Instance Method Details

#errorObject



56
57
58
# File 'lib/faceb/api.rb', line 56

def error
  {:code =>  @data['error_code'], :msg => @data['error_msg'] }
end