Class: Tinder::FaradayResponse::WithIndifferentAccess

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/tinder/middleware.rb

Class Method Summary collapse

Class Method Details

.register_on_complete(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/tinder/middleware.rb', line 10

def self.register_on_complete(env)
  env[:response].on_complete do |response|
    json = response[:body]
    if json.is_a?(Hash)
      response[:body] = ::HashWithIndifferentAccess.new(json)
    elsif json.is_a?(Array) and json.first.is_a?(Hash)
      response[:body] = json.map{|item| ::HashWithIndifferentAccess.new(item) }
    end
  end
end