Class: Kraut::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/kraut/application.rb

Overview

Kraut::Application

Represents an application registered with Crowd.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.authenticated_atObject

Returns the value of attribute authenticated_at.



20
21
22
# File 'lib/kraut/application.rb', line 20

def authenticated_at
  @authenticated_at
end

.nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/kraut/application.rb', line 20

def name
  @name
end

.passwordObject

Returns the value of attribute password.



20
21
22
# File 'lib/kraut/application.rb', line 20

def password
  @password
end

.tokenObject

Returns the value of attribute token.



20
21
22
# File 'lib/kraut/application.rb', line 20

def token
  @token
end

Class Method Details

.authenticate(name, password) ⇒ Object

Authenticates an application with a given name and password.



12
13
14
15
16
17
18
# File 'lib/kraut/application.rb', line 12

def authenticate(name, password)
  response = Client.request :authenticate_application,
    :in0 => { "aut:credential" => { "aut:credential" => password }, "aut:name" => name }
  
  self.authenticated_at = Time.now
  self.name, self.password, self.token = name, password, response[:out][:token]
end

.authentication_required?(timeout = 10) ⇒ Boolean

Returns whether the application needs to (re-)authenticate itself. Defaults to a timeout of 10 minutes.

Returns:

  • (Boolean)


24
25
26
# File 'lib/kraut/application.rb', line 24

def authentication_required?(timeout = 10)
  !authenticated_at || authenticated_at < Time.now - (60 * timeout)
end