class Faraday::Request::Authorization

Constants

KEY

Public Class Methods

build_hash(type, hash) click to toggle source

Internal

# File lib/faraday/request/authorization.rb, line 16
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
header(type, token) click to toggle source

Public

# File lib/faraday/request/authorization.rb, line 6
def self.header(type, token)
  case token
  when String, Symbol then "#{type} #{token}"
  when Hash then build_hash(type.to_s, token)
  else
    raise ArgumentError, "Can't build an Authorization #{type} header from #{token.inspect}"
  end
end
new(app, type, token) click to toggle source
# File lib/faraday/request/authorization.rb, line 26
def initialize(app, type, token)
  @header_value = self.class.header(type, token)
  super(app)
end

Public Instance Methods

call(env) click to toggle source

Public

# File lib/faraday/request/authorization.rb, line 32
def call(env)
  unless env[:request_headers][KEY]
    env[:request_headers][KEY] = @header_value
  end
  @app.call(env)
end