Class: EtherpadLite::Session
- Inherits:
-
Object
- Object
- EtherpadLite::Session
- 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
-
#id ⇒ Object
readonly
The session id.
-
#instance ⇒ Object
readonly
The EtherpadLite::Instance object.
Class Method Summary collapse
-
.create(instance, group_id, author_id, length_in_min) ⇒ Object
Creates a new Session between a Group and an Author.
Instance Method Summary collapse
-
#author ⇒ Object
Returns the Session’s author.
-
#author_id ⇒ Object
Returns the Session’s author id.
-
#delete ⇒ Object
Deletes the Session.
-
#expired? ⇒ Boolean
Returns true if the session is expired.
-
#group ⇒ Object
Returns the Session’s group.
-
#group_id ⇒ Object
Returns the Session’s group id.
-
#initialize(instance, id, info = nil) ⇒ Session
constructor
Instantiates a Session object (presumed to already exist).
-
#valid? ⇒ Boolean
Returns true if the session is not expired.
-
#valid_until ⇒ Object
Returns the Session’s expiration date is a Unix timestamp in seconds.
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
#id ⇒ Object (readonly)
The session id
14 15 16 |
# File 'lib/etherpad-lite/models/session.rb', line 14 def id @id end |
#instance ⇒ Object (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, , length_in_min) valid_until = Time.now.to_i + length_in_min * 60 result = instance.client.createSession(groupID: group_id, authorID: , validUntil: valid_until) new instance, result[:sessionID] end |
Instance Method Details
#author ⇒ Object
Returns the Session’s author
46 47 48 |
# File 'lib/etherpad-lite/models/session.rb', line 46 def @author ||= Author.new @instance, end |
#author_id ⇒ Object
Returns the Session’s author id
41 42 43 |
# File 'lib/etherpad-lite/models/session.rb', line 41 def get_info[:authorID] end |
#delete ⇒ Object
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
61 62 63 |
# File 'lib/etherpad-lite/models/session.rb', line 61 def expired? not valid? end |
#group ⇒ Object
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_id ⇒ Object
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
56 57 58 |
# File 'lib/etherpad-lite/models/session.rb', line 56 def valid? valid_until > Time.now.to_i end |
#valid_until ⇒ Object
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 |