Class: Apiphobic::Requests::AuthorizationToken
- Inherits:
-
Object
- Object
- Apiphobic::Requests::AuthorizationToken
- Defined in:
- lib/apiphobic/requests/authorization_token.rb
Constant Summary collapse
- BASE64_PATTERN =
%r{[A-Za-z0-9_/+=\-.]}- BASE64_TOKEN_HEADER_PATTERN =
/\A(?:Basic|Bearer)\s+(.*)\z/- BASE64_TOKEN_PARAM_NAME =
'token_b64'- BASE64_TOKEN_PARAM_PATTERN =
/(?:\A|&)#{BASE64_TOKEN_PARAM_NAME}=(.*)(?=\z|&)/- JSON_WEB_TOKEN_PATTERN =
/(#{BASE64_PATTERN}+?\.){4}#{BASE64_PATTERN}+?/- JSON_WEB_TOKEN_HEADER_PATTERN =
/\AToken\s+(.*)\z/- JSON_WEB_TOKEN_PARAM_NAME =
'token_jwt'- JSON_WEB_TOKEN_PARAM_PATTERN =
/(?:\A|&)#{JSON_WEB_TOKEN_PARAM_NAME}=(.*)(?=\z|&)/
Instance Attribute Summary collapse
-
#private_key ⇒ Object
Returns the value of attribute private_key.
-
#request ⇒ Object
Returns the value of attribute request.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(request, private_key:, type:) ⇒ AuthorizationToken
constructor
A new instance of AuthorizationToken.
Constructor Details
#initialize(request, private_key:, type:) ⇒ AuthorizationToken
Returns a new instance of AuthorizationToken.
26 27 28 29 30 31 32 33 |
# File 'lib/apiphobic/requests/authorization_token.rb', line 26 def initialize(request, private_key:, type:) self.request = request self.private_key = private_key self.type = type end |
Instance Attribute Details
#private_key ⇒ Object
Returns the value of attribute private_key.
22 23 24 |
# File 'lib/apiphobic/requests/authorization_token.rb', line 22 def private_key @private_key end |
#request ⇒ Object
Returns the value of attribute request.
22 23 24 |
# File 'lib/apiphobic/requests/authorization_token.rb', line 22 def request @request end |
#type ⇒ Object
Returns the value of attribute type.
22 23 24 |
# File 'lib/apiphobic/requests/authorization_token.rb', line 22 def type @type end |
Instance Method Details
#fetch ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/apiphobic/requests/authorization_token.rb', line 35 def fetch if !token_from_header.blank? && token_from_params.blank? token_from_header elsif !token_from_params.blank? token_from_params else # rubocop:disable Lint/DuplicateBranch token_from_header end end |