Class: Tinder::FaradayResponse::WithIndifferentAccess

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

Class Method Summary collapse

Class Method Details

.register_on_complete(env) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/tinder/faraday_response.rb', line 36

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) && json.first.is_a?(Hash)
      response[:body] = json.map { |item| ::HashWithIndifferentAccess.new(item) }
    end
  end
end