Sha256: 7738a7df66d7c14f068469dc5381826e3f06a94d1c2872382890bb33e9cd94f6

Contents?: true

Size: 950 Bytes

Versions: 3

Compression:

Stored size: 950 Bytes

Contents

module Tinder
  module FaradayResponse
    class WithIndifferentAccess < ::Faraday::Response::Middleware
      begin
        require 'active_support/core_ext/hash/indifferent_access'
      rescue LoadError, NameError => error
        self.load_error = error
      end

      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
    end

    class RaiseOnAuthenticationFailure < ::Faraday::Response::Middleware
      def self.register_on_complete(env)
        env[:response].on_complete do |response|
          raise AuthenticationFailed if response[:status] == 401
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tinder-1.4.4 lib/tinder/middleware.rb
tinder-1.4.3 lib/tinder/middleware.rb
tinder-1.4.2 lib/tinder/middleware.rb