Class: Nexo::Integration

Inherits:
ApplicationRecord show all
Defined in:
app/models/nexo/integration.rb

Instance Method Summary collapse

Instance Method Details

#credentialsObject



61
62
63
64
# File 'app/models/nexo/integration.rb', line 61

def credentials
  service = ServiceBuilder.instance.build_auth_service(self)
  @credentials ||= service.get_credentials
end

#expires_inObject



39
40
41
42
43
# File 'app/models/nexo/integration.rb', line 39

def expires_in
  return unless credentials.present?

  (credentials.expires_at - Time.current).to_i
end

#external_api_scopeObject



29
30
31
32
33
34
35
36
37
# File 'app/models/nexo/integration.rb', line 29

def external_api_scope
  if scope.blank?
    # :nocov: borderline
    raise "scope must be present"
    # :nocov:
  end

  scope.map { |permission| client.service_scopes[permission.to_sym] }
end

#token?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/nexo/integration.rb', line 57

def token?
  token_status.in? [ :active_token, :expired_token ]
end

#token_statusObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/nexo/integration.rb', line 45

def token_status
  if credentials.present?
    if credentials.expires_at > Time.current
      :active_token
    else
      :expired_token
    end
  else
    :no_token
  end
end