Skip to content

Commit

Permalink
Add all API v1.1 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jhollinger committed Sep 24, 2012
1 parent 140eb85 commit 5b23472
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/etherpad-lite/models/author.rb
Expand Up @@ -45,8 +45,6 @@ class Author
attr_reader :instance
# The author's id
attr_reader :id
# The author's name (if any)
attr_reader :name
# The author's foreign mapper (if any)
attr_reader :mapper

Expand Down Expand Up @@ -77,7 +75,11 @@ def initialize(instance, id, options={})
@instance = instance
@id = id
@mapper = options[:mapper]
@name = options[:name]
end

# Returns the author's name
def name
@name ||= @instance.client.getAuthorName(authorID: @id)
end

# Returns an array of pad ids that this author has edited
Expand Down
10 changes: 10 additions & 0 deletions lib/etherpad-lite/models/instance.rb
Expand Up @@ -40,6 +40,16 @@ def create_group(options={})
Group.create self, options
end

# Returns an array of all group IDs
def group_ids
@client.listAllGroups[:groupIDs]
end

# Returns an array of all Group objects
def groups
group_ids.map { |id| Group.new self, id }
end

# Returns, creating if necessary, a Author mapped to your foreign system's author
#
# Options:
Expand Down
5 changes: 5 additions & 0 deletions lib/etherpad-lite/models/pad.rb
Expand Up @@ -121,6 +121,11 @@ def revisions
revision_numbers.map { |n| Pad.new(@instance, @id, :rev => n) }
end

# Returns an array of users hashes, representing users currently using the pad
def users
@instance.client.padUsers(padID: @id)[:padUsers]
end

# Returns the number of users currently editing a pad
def user_count
@instance.client.padUsersCount(padID: @id)[:padUsersCount]
Expand Down
7 changes: 7 additions & 0 deletions spec/author_spec.rb
Expand Up @@ -27,4 +27,11 @@
author.pad_ids.should == []
author.pads.should == []
end

if TEST_CONFIG[:api_version] > 1
it "should get the name" do
author = @eth.create_author :mapper => 'Author B', :name => 'Jim Jimmers'
author.name.should == 'Jim Jimmers'
end
end
end
13 changes: 13 additions & 0 deletions spec/group_spec.rb
Expand Up @@ -81,6 +81,19 @@
pad.text.should == "abc\n"
end

if TEST_CONFIG[:api_version] > 1
it "should list all group ids" do
group_ids = @eth.group_ids
group_ids.size.should == 4
end

it "should list all groups" do
groups = @eth.groups
groups.size.should == 4
groups.first.class.name.should == 'EtherpadLite::Group'
end
end

context 'Group Pad' do
context 'Privacy' do
it "should be private" do
Expand Down
7 changes: 7 additions & 0 deletions spec/pad_spec.rb
Expand Up @@ -118,4 +118,11 @@
@eth.get_pad('another new pad').delete
@eth.create_pad('another new pad').id.should_not == nil
end

if TEST_CONFIG[:api_version] > 1
it "should get the pad users" do
puts @eth.pad('pad with users').users
@eth.pad('pad with users').users.should == []
end
end
end

0 comments on commit 5b23472

Please sign in to comment.