Class: Rsodx::Headers
- Inherits:
-
Object
- Object
- Rsodx::Headers
- Defined in:
- lib/rsodx/headers.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #authorization ⇒ Object
- #bearer_token ⇒ Object
-
#initialize(request) ⇒ Headers
constructor
A new instance of Headers.
- #to_h ⇒ Object
Constructor Details
#initialize(request) ⇒ Headers
Returns a new instance of Headers.
5 6 7 8 9 10 11 12 |
# File 'lib/rsodx/headers.rb', line 5 def initialize(request) @headers = request.env.each_with_object({}) do |(k, v), memo| if k.start_with?("HTTP_") key = k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-') memo[key] = v end end end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/rsodx/headers.rb', line 3 def headers @headers end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 |
# File 'lib/rsodx/headers.rb', line 14 def [](key) headers[key] end |
#authorization ⇒ Object
18 19 20 |
# File 'lib/rsodx/headers.rb', line 18 def headers["Authorization"] end |
#bearer_token ⇒ Object
22 23 24 25 |
# File 'lib/rsodx/headers.rb', line 22 def bearer_token return nil unless &.start_with?("Bearer ") .sub("Bearer ", "") end |
#to_h ⇒ Object
27 28 29 |
# File 'lib/rsodx/headers.rb', line 27 def to_h headers end |