Class: Faraday::Request::Authorization
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::Request::Authorization
- Defined in:
- lib/faraday/request/authorization.rb
Overview
Request middleware for the Authorization HTTP header
Constant Summary collapse
- KEY =
'Authorization'
Instance Attribute Summary
Attributes included from DependencyLoader
Class Method Summary collapse
-
.build_hash(type, hash) ⇒ String
private
Type followed by comma-separated key=value pairs.
-
.header(type, token) ⇒ String
A header value.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, type, token) ⇒ Authorization
constructor
A new instance of Authorization.
Methods included from MiddlewareRegistry
#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware, #unregister_middleware
Methods included from DependencyLoader
#dependency, #inherited, #loaded?, #new
Constructor Details
#initialize(app, type, token) ⇒ Authorization
Returns a new instance of Authorization.
41 42 43 44 |
# File 'lib/faraday/request/authorization.rb', line 41 def initialize(app, type, token) @header_value = self.class.header(type, token) super(app) end |
Class Method Details
.build_hash(type, hash) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns type followed by comma-separated key=value pairs.
29 30 31 32 33 34 35 36 |
# File 'lib/faraday/request/authorization.rb', line 29 def self.build_hash(type, hash) comma = ', ' values = [] hash.each do |key, value| values << "#{key}=#{value.to_s.inspect}" end "#{type} #{values * comma}" end |
.header(type, token) ⇒ String
Returns a header value.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/faraday/request/authorization.rb', line 12 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 |