class JWTEasy::Result
Result
object that represents a decoded token.
-
This is usually not instantiated directly, but rather by way of calling
JWTEasy.encode
.
Constants
- CLAIM_KEYS
Attributes
headers[R]
payload[R]
Public Class Methods
new(payload = nil, headers = nil)
click to toggle source
Initializes a new result instance.
@param [Object] payload from decoding a token @param [Hash] headers from decoding a token
# File lib/jwt_easy/result.rb, line 21 def initialize(payload = nil, headers = nil) @payload = payload @headers = headers end
Public Instance Methods
claim()
click to toggle source
Infers the claim that was observed during decoding.
@return [Symbol] short name for the identified claim
# File lib/jwt_easy/result.rb, line 52 def claim @claim ||= CLAIM_KEYS.find { |claim| payload&.key?(claim.to_s) } end
data()
click to toggle source
Determines the encoded data from the payload structure.
-
If the payload is a hash that contains a claim key alongside other data
attributes, only a hash with the data attributes will be returned.
-
If the payload is hash that contains data in a data attribute alongside any claim keys, the value of the data attribute is returned.
-
If the payload is anything but a hash, the payload is returned.
@return [Object] the data encoded with the payload
# File lib/jwt_easy/result.rb, line 37 def data @data ||= if payload.is_a?(Hash) if claim && payload.key?('data') payload['data'] else payload.except(*CLAIM_KEYS.map(&:to_s)) end else payload end end
method_missing(method, *arguments, &block)
click to toggle source
Calls superclass method
# File lib/jwt_easy/result.rb, line 56 def method_missing(method, *arguments, &block) data.is_a?(Hash) && data.key?(method.to_s) ? data[method.to_s] : super end
respond_to_missing?(method, _include_private = false)
click to toggle source
Calls superclass method
# File lib/jwt_easy/result.rb, line 60 def respond_to_missing?(method, _include_private = false) data.is_a?(Hash) && data.key?(method.to_s) || super end