Class: EtherpadLite::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/etherpad-lite/models/session.rb

Overview

An Etherpad Lite Session between a Group and an Author. See those classes for examples of how to create a session.

Sessions are useful for embedding an Etherpad Lite Pad into a external application. For public pads, sessions are not necessary. However Group pads require a Session to access to the pad via the Web UI.

Generally, you will create the session server side, then pass its id to the embedded pad using a cookie. See the README for an example in a Rails app.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, id, info = nil) ⇒ Session

Instantiates a Session object (presumed to already exist)



24
25
26
27
28
# File 'lib/etherpad-lite/models/session.rb', line 24

def initialize(instance, id, info=nil)
  @instance = instance
  @id = id
  @info = info
end

Instance Attribute Details

#idObject (readonly)

The session id



14
15
16
# File 'lib/etherpad-lite/models/session.rb', line 14

def id
  @id
end

#instanceObject (readonly)

The EtherpadLite::Instance object



12
13
14
# File 'lib/etherpad-lite/models/session.rb', line 12

def instance
  @instance
end

Class Method Details

.create(instance, group_id, author_id, length_in_min) ⇒ Object

Creates a new Session between a Group and an Author. The session will expire after length_in_min.



17
18
19
20
21
# File 'lib/etherpad-lite/models/session.rb', line 17

def self.create(instance, group_id, author_id, length_in_min)
  valid_until = Time.now.to_i + length_in_min * 60
  result = instance.client.createSession(groupID: group_id, authorID: author_id, validUntil: valid_until)
  new instance, result[:sessionID]
end

Instance Method Details

#authorObject

Returns the Session’s author



46
47
48
# File 'lib/etherpad-lite/models/session.rb', line 46

def author
  @author ||= Author.new @instance, author_id
end

#author_idObject

Returns the Session’s author id



41
42
43
# File 'lib/etherpad-lite/models/session.rb', line 41

def author_id
  get_info[:authorID]
end

#deleteObject

Deletes the Session



66
67
68
# File 'lib/etherpad-lite/models/session.rb', line 66

def delete
  @instance.client.deleteSession(sessionID: @id)
end

#expired?Boolean

Returns true if the session is expired

Returns:

  • (Boolean)


61
62
63
# File 'lib/etherpad-lite/models/session.rb', line 61

def expired?
  not valid?
end

#groupObject

Returns the Session’s group



36
37
38
# File 'lib/etherpad-lite/models/session.rb', line 36

def group
  @group ||= Group.new @instance, group_id
end

#group_idObject

Returns the Session’s group id



31
32
33
# File 'lib/etherpad-lite/models/session.rb', line 31

def group_id
  get_info[:groupID]
end

#valid?Boolean

Returns true if the session is not expired

Returns:

  • (Boolean)


56
57
58
# File 'lib/etherpad-lite/models/session.rb', line 56

def valid?
  valid_until > Time.now.to_i
end

#valid_untilObject

Returns the Session’s expiration date is a Unix timestamp in seconds



51
52
53
# File 'lib/etherpad-lite/models/session.rb', line 51

def valid_until
  get_info[:validUntil]
end