Class: Faraday::Request::Authorization
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::Request::Authorization
- Defined in:
- lib/faraday/request/authorization.rb
Direct Known Subclasses
Constant Summary collapse
- KEY =
"Authorization".freeze
Class Method Summary collapse
-
.build_hash(type, hash) ⇒ Object
Internal.
-
.header(type, token) ⇒ Object
Public.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Public.
-
#initialize(app, type, token) ⇒ Authorization
constructor
A new instance of Authorization.
Methods inherited from Middleware
adapter?, dependency, inherited, loaded?, new
Methods included from MiddlewareRegistry
#lookup_middleware, #register_middleware
Constructor Details
#initialize(app, type, token) ⇒ Authorization
Returns a new instance of Authorization.
26 27 28 29 |
# File 'lib/faraday/request/authorization.rb', line 26 def initialize(app, type, token) @header_value = self.class.header(type, token) super(app) end |
Class Method Details
.build_hash(type, hash) ⇒ Object
Internal
16 17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
Public
6 7 8 9 10 11 12 13 |
# 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 |