Class: EtherpadLite::Instance

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

Overview

A high-level interface to EtherpadLite::Client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Padded

#create_pad, #get_pad, #pad

Constructor Details

#initialize(url_or_port, api_key_or_file, api_version = nil) ⇒ Instance

Instantiate a new Etherpad Lite Instance. You may pass a full url or just a port number. The api key may be a string or a File object.



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

def initialize(url_or_port, api_key_or_file, api_version=nil)
  @client = Client.new(url_or_port, api_key_or_file, api_version)
end

Instance Attribute Details

#clientObject (readonly)

Stores the EtherpadLite::Client object used to power this Instance



15
16
17
# File 'lib/etherpad-lite/models/instance.rb', line 15

def client
  @client
end

Instance Method Details

#author(mapper, options = {}) ⇒ Object

Returns, creating if necessary, a Author mapped to your foreign system’s author

Options:

name => the Author’s name



68
69
70
71
# File 'lib/etherpad-lite/models/instance.rb', line 68

def author(mapper, options={})
  options[:mapper] = mapper
  create_author options
end

#create_author(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.

Options:

mapper => your foreign author id

name => the Author's name


86
87
88
# File 'lib/etherpad-lite/models/instance.rb', line 86

def create_author(options={})
  Author.create self, options
end

#create_group(options = {}) ⇒ Object

Creates a new Group. Optionally, you may pass the :mapper option your third party system’s group id. This will allow you to find your Group again later using the same identifier as your foreign system.

Options:

mapper => your foreign group id



49
50
51
# File 'lib/etherpad-lite/models/instance.rb', line 49

def create_group(options={})
  Group.create self, options
end

#get_author(id) ⇒ Object

Returns an Author with the given id (it is presumed to already exist).



74
75
76
# File 'lib/etherpad-lite/models/instance.rb', line 74

def get_author(id)
  Author.new self, id
end

#get_group(id) ⇒ Object

Returns a Group with the given id (it is presumed to already exist).



39
40
41
# File 'lib/etherpad-lite/models/instance.rb', line 39

def get_group(id)
  Group.new self, id
end

#get_session(session_id) ⇒ Object

Returns a Session (presumed to already exist).



91
92
93
# File 'lib/etherpad-lite/models/instance.rb', line 91

def get_session(session_id)
  Session.new self, session_id
end

#group(mapper) ⇒ Object

Returns, creating if necessary, a Group mapped to your foreign system’s group



34
35
36
# File 'lib/etherpad-lite/models/instance.rb', line 34

def group(mapper)
  create_group(:mapper => mapper)
end

#group_idsObject

Returns an array of all group IDs



54
55
56
# File 'lib/etherpad-lite/models/instance.rb', line 54

def group_ids
  @client.listAllGroups[:groupIDs]
end

#groupsObject

Returns an array of all Group objects



59
60
61
# File 'lib/etherpad-lite/models/instance.rb', line 59

def groups
  group_ids.map { |id| Group.new self, id }
end

#instanceObject

Returns itself



96
# File 'lib/etherpad-lite/models/instance.rb', line 96

def instance; self; end

#pad_idsObject

Returns an array of all pad IDs



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

def pad_ids
  @client.listAllPads[:padIDs]
end

#padsObject

Returns an array of all Pad objects



29
30
31
# File 'lib/etherpad-lite/models/instance.rb', line 29

def pads
  pad_ids.map { |id| Pad.new self, id }
end