class Faraday::Request::Authorization

Request middleware for the Authorization HTTP header

def self.build_hash(type, hash)

Other tags:
    Api: - private

Returns:
  • (String) - type followed by comma-separated key=value pairs

Parameters:
  • hash (Hash) --
  • type (String) --
def self.build_hash(type, hash)
  comma = ', '
  values = []
  hash.each do |key, value|
    values << "#{key}=#{value.to_s.inspect}"
  end
  "#{type} #{values * comma}"
end

def self.header(type, token)

Returns:
  • (String) - a header value

Parameters:
  • token (String, Symbol, Hash) --
  • type (String, Symbol) --
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

def call(env)

Parameters:
  • env (Faraday::Env) --
def call(env)
  env.request_headers[KEY] = @header_value unless env.request_headers[KEY]
  @app.call(env)
end

def initialize(app, type, token)

Parameters:
  • token (String, Symbol, Hash) -- Token value for the Authorization
  • type (String, Symbol) -- Type of Authorization
  • app (#call) --
def initialize(app, type, token)
  @header_value = self.class.header(type, token)
  super(app)
end