Sha256: c0d45b819412ef3ff6a024970fe50114dbf34bca49c7c23107fee39c9e8627fa

Contents?: true

Size: 980 Bytes

Versions: 15

Compression:

Stored size: 980 Bytes

Contents

module Faraday
  class Request::Authorization < Faraday::Middleware
    KEY = "Authorization".freeze unless defined? KEY

    # Public
    def self.header(type, token)
      case token
      when String, Symbol
        "#{type} #{token}"
      when Hash
        build_hash(type.to_s, token)
      else
        raise ArgumentError, "Can't build an Authorization #{type} header from #{token.inspect}"
      end
    end

    # Internal
    def self.build_hash(type, hash)
      offset = KEY.size + type.size + 3
      comma = ",\n#{' ' * offset}"
      values = []
      hash.each do |key, value|
        values << "#{key}=#{value.to_s.inspect}"
      end
      "#{type} #{values * comma}"
    end

    def initialize(app, type, token)
      @header_value = self.class.header(type, token)
      super(app)
    end

    # Public
    def call(env)
      unless env.request_headers[KEY]
        env.request_headers[KEY] = @header_value
      end
      @app.call(env)
    end
  end
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
mercadopago-custom-checkout-0.1.2 .gs/gems/faraday-0.9.2/lib/faraday/request/authorization.rb
mercadopago-custom-checkout-0.1.1 .gs/gems/faraday-0.9.2/lib/faraday/request/authorization.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/faraday-0.9.2/lib/faraday/request/authorization.rb
faraday-0.10.1 lib/faraday/request/authorization.rb
faraday-0.10.0 lib/faraday/request/authorization.rb
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/faraday-0.9.2/lib/faraday/request/authorization.rb
tdiary-5.0.2 vendor/bundle/gems/faraday-0.9.2/lib/faraday/request/authorization.rb
tdiary-5.0.1 vendor/bundle/gems/faraday-0.9.2/lib/faraday/request/authorization.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/request/authorization.rb
faraday-0.9.2 lib/faraday/request/authorization.rb
faraday-0.9.1 lib/faraday/request/authorization.rb
whos_dated_who-0.1.0 vendor/bundle/gems/faraday-0.9.0/lib/faraday/request/authorization.rb
whos_dated_who-0.0.1 vendor/bundle/gems/faraday-0.9.0/lib/faraday/request/authorization.rb
faraday-0.9.0 lib/faraday/request/authorization.rb
faraday-0.9.0.rc7 lib/faraday/request/authorization.rb