Class: EtherpadLite::Author
- Inherits:
-
Object
- Object
- EtherpadLite::Author
- Defined in:
- lib/etherpad-lite/models/author.rb
Overview
An Author of Pad content
Authors are used to create a Session in a Group. Authors may be created with a name and a mapper. A mapper is usually an identifier stored in your third-party system, like a foreign key or username.
Author Examples:
@ether = EtherpadLite.connect(9001, 'api key')
# Create a new author with both a name and a mapper
= @ether.(:name => 'Theodor Seuss Geisel', :mapper => 'author_1')
# Load (and create, if necessary) a mapped author with a name
= @ether.('author_2', :name => 'Richard Bachman')
# Load (and create, if necessary) a author by mapper
= @ether.('author_3')
# Load author1 by id
= @ether.(.id)
Session examples:
# Create two hour-long session for author 1 in two different groups
group1 = @ether.group('my awesome group')
group2 = @ether.group('my other awesome group')
session1 = .create_session(group1, 60)
session2 = .create_session(group2, 60)
Attribute examples:
.name #> "Theodor Seuss Geisel"
.mapper #> "author_1"
.sessions #> [#<EtherpadLite::Session>, #<EtherpadLite::Session>]
.session_ids.include? session1.id #> true
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The author’s id.
-
#instance ⇒ Object
readonly
The EtherpadLite::Instance object.
-
#mapper ⇒ Object
readonly
The author’s foreign mapper (if any).
Class Method Summary collapse
-
.create(instance, options = {}) ⇒ Object
Creates a new Author.
Instance Method Summary collapse
-
#create_session(group, length_in_min) ⇒ Object
Create a new session for group that will last length_in_minutes.
-
#initialize(instance, id, options = {}) ⇒ Author
constructor
Instantiates an Author object (presumed it already exists).
-
#name ⇒ Object
Returns the author’s name.
-
#pad_ids ⇒ Object
Returns an array of pad ids that this author has edited.
-
#pads ⇒ Object
Returns an array of Pads that this author has edited.
-
#session_ids ⇒ Object
Returns all session ids from this Author.
-
#sessions ⇒ Object
Returns all sessions from this Author.
Constructor Details
#initialize(instance, id, options = {}) ⇒ Author
Instantiates an Author object (presumed it already exists)
Options:
mapper => the foreign author id it’s mapped to
name => the Author’s name
74 75 76 77 78 |
# File 'lib/etherpad-lite/models/author.rb', line 74 def initialize(instance, id, ={}) @instance = instance @id = id @mapper = [:mapper] end |
Instance Attribute Details
#id ⇒ Object (readonly)
The author’s id
47 48 49 |
# File 'lib/etherpad-lite/models/author.rb', line 47 def id @id end |
#instance ⇒ Object (readonly)
The EtherpadLite::Instance object
45 46 47 |
# File 'lib/etherpad-lite/models/author.rb', line 45 def instance @instance end |
#mapper ⇒ Object (readonly)
The author’s foreign mapper (if any)
49 50 51 |
# File 'lib/etherpad-lite/models/author.rb', line 49 def mapper @mapper end |
Class Method Details
.create(instance, options = {}) ⇒ Object
Creates a new Author. Optionally, you may pass the :mapper option your third party system’s author id. This will allow you to find the Author again later using the same identifier as your foreign system. If you pass the mapper option, the method behaves like “create author for <mapper> if it doesn’t already exist”.
Options:
mapper => uid of Author from another system
name => Author’s name
60 61 62 63 64 65 |
# File 'lib/etherpad-lite/models/author.rb', line 60 def self.create(instance, ={}) result = [:mapper] \ ? instance.client.createAuthorIfNotExistsFor(authorMapper: [:mapper], name: [:name]) \ : instance.client.createAuthor() new instance, result[:authorID], end |
Instance Method Details
#create_session(group, length_in_min) ⇒ Object
Create a new session for group that will last length_in_minutes.
96 97 98 |
# File 'lib/etherpad-lite/models/author.rb', line 96 def create_session(group, length_in_min) Session.create(@instance, group.id, @id, length_in_min) end |
#name ⇒ Object
Returns the author’s name
81 82 83 |
# File 'lib/etherpad-lite/models/author.rb', line 81 def name @name ||= @instance.client.getAuthorName(authorID: @id) end |
#pad_ids ⇒ Object
Returns an array of pad ids that this author has edited
86 87 88 |
# File 'lib/etherpad-lite/models/author.rb', line 86 def pad_ids @instance.client.listPadsOfAuthor(authorID: @id)[:padIDs] || [] end |
#pads ⇒ Object
Returns an array of Pads that this author has edited
91 92 93 |
# File 'lib/etherpad-lite/models/author.rb', line 91 def pads pad_ids.map { |id| Pad.new(@instance, id) } end |
#session_ids ⇒ Object
Returns all session ids from this Author
101 102 103 104 |
# File 'lib/etherpad-lite/models/author.rb', line 101 def session_ids s = @instance.client.listSessionsOfAuthor(authorID: @id) || {} s.keys end |