Sha256: 11c617fe080e32f76b6653e4e8b9176d2ee747e6704d68e56cd45bd90b290770

Contents?: true

Size: 690 Bytes

Versions: 9

Compression:

Stored size: 690 Bytes

Contents

module Goauth2
  class HashResponse
    
    def initialize(response_hash)
      @hash = response_hash
      @hash = @hash['data'] if @hash['data']
    end
    
    def first
      wrap(@hash.first)
    end
    
    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
    
    private
      def wrap(val)
        if val.is_a? Hash
          Goauth2::HashResponse.new(val)
        elsif val.is_a? Array
          Goauth2::ArrayResponse.new(val)
        else
          val
        end
      end
    
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
goauth2-0.0.10 lib/goauth2/hash_response.rb
goauth2-0.0.9 lib/goauth2/hash_response.rb
goauth2-0.0.7 lib/goauth2/hash_response.rb
goauth2-0.0.6 lib/goauth2/hash_response.rb
goauth2-0.0.5 lib/goauth2/hash_response.rb
goauth2-0.0.4 lib/goauth2/hash_response.rb
goauth2-0.0.3 lib/goauth2/hash_response.rb
goauth2-0.0.2 lib/goauth2/hash_response.rb
goauth2-0.0.1 lib/goauth2/hash_response.rb