Class: Goauth2::HashResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/goauth2/hash_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ HashResponse

Returns a new instance of HashResponse.



5
6
7
8
9
# File 'lib/goauth2/hash_response.rb', line 5

def initialize(response)
  @response = response
  @hash = JSON.parse(response.body)
  @hash = @hash['data'] if @hash['data']
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/goauth2/hash_response.rb', line 15

def method_missing(name)
  val = @hash[name] if @hash.key? name
  @hash.each { |k,v| val = v if k.to_s.to_sym == name } unless val
  if val        
    return wrap(val)
  end
  super.method_missing name
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



3
4
5
# File 'lib/goauth2/hash_response.rb', line 3

def hash
  @hash
end

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/goauth2/hash_response.rb', line 3

def response
  @response
end

Instance Method Details

#firstObject



11
12
13
# File 'lib/goauth2/hash_response.rb', line 11

def first
  wrap(@hash.first)
end