Sha256: 130bd5b0c21074dfd32e3a7644dbd449a2d7d8fc49b70af0703e34eb1adba437
Contents?: true
Size: 784 Bytes
Versions: 3
Compression:
Stored size: 784 Bytes
Contents
require 'access_token_agent/missing_access_token' require 'access_token_agent/unsupported_token_type_error' module AccessTokenAgent class Token attr_reader :value, :expires_at EXPIRY_MARGIN = 60 # seconds def initialize(auth_response) validate_response(auth_response) @value = auth_response['access_token'] @expires_at = Time.now + auth_response['expires_in'] end def valid? @expires_at - EXPIRY_MARGIN > Time.now end private def validate_response(auth_response) unless auth_response['token_type'] == 'bearer' raise UnsupportedTokenTypeError, auth_response['token_type'] end token = auth_response['access_token'] raise MissingAccessToken if token.nil? || token.empty? end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
access_token_agent-3.3.0 | lib/access_token_agent/token.rb |
access_token_agent-3.2.1 | lib/access_token_agent/token.rb |
access_token_agent-3.2.0 | lib/access_token_agent/token.rb |