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.



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

def authenticated_at
  @authenticated_at
end

.nameObject

Returns the value of attribute name.



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

def name
  @name
end

.passwordObject

Returns the value of attribute password.



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

def password
  @password
end

.tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Class Method Details

.authenticate(name, password) ⇒ Object

Authenticates an application with a given name and password.



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

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)


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

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