Class: FaceB::Api::Response
- Inherits:
-
Object
- Object
- FaceB::Api::Response
- Defined in:
- lib/faceb/api.rb
Overview
Response
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(data) ⇒ Response
constructor
A new instance of Response.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(data) ⇒ Response
Returns a new instance of Response.
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
41 42 43 |
# File 'lib/faceb/api.rb', line 41 def data @data end |
Instance Method Details
#error ⇒ Object
56 57 58 |
# File 'lib/faceb/api.rb', line 56 def error {:code => @data['error_code'], :msg => @data['error_msg'] } end |