Module: AnotherApi::ApiTokenContract

Extended by:
ActiveSupport::Concern
Defined in:
lib/another_api/api_token_contract.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/another_api/api_token_contract.rb', line 17

def active?
  !revoked? && !expired?
end

#allows?(requested_scope) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/another_api/api_token_contract.rb', line 9

def allows?(requested_scope)
  parsed_scopes.any? { |s| s.matches?(requested_scope) }
end

#expired?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/another_api/api_token_contract.rb', line 25

def expired?
  expires_at&.past? || false
end

#parsed_scopesObject



13
14
15
# File 'lib/another_api/api_token_contract.rb', line 13

def parsed_scopes
  @parsed_scopes ||= scopes.map { |s| AnotherApi::Scope.parse(s) }
end

#revoked?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/another_api/api_token_contract.rb', line 21

def revoked?
  revoked_at.present?
end

#token_previewObject



29
30
31
# File 'lib/another_api/api_token_contract.rb', line 29

def token_preview
  "#{token_prefix}#{"*" * 12}#{token_suffix}"
end