Skip to content

Commit

Permalink
Add support for listAllPads
Browse files Browse the repository at this point in the history
  • Loading branch information
jhollinger committed Jan 18, 2013
1 parent 92a818f commit 02152b4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/etherpad-lite/models/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def initialize(url_or_port, api_key_or_file, api_version=1)
@client = Client.new(url_or_port, api_key_or_file, api_version)
end

# Returns an array of all pad IDs
def pad_ids
@client.listAllPads[:padIDs]
end

# Returns an array of all Pad objects
def pads
pad_ids.map { |id| Pad.new self, id }
end

# Returns, creating if necessary, a Group mapped to your foreign system's group
def group(mapper)
create_group(:mapper => mapper)
Expand Down
2 changes: 2 additions & 0 deletions lib/etherpad-lite/models/pad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def initialize(instance, id, options={})
if options[:groupID]
@group_id = options[:groupID]
@id = "#{@group_id}$#{@id}" unless @id =~ Group::GROUP_ID_REGEX
elsif @id =~ Group::GROUP_ID_REGEX
@group_id = id.split('$').first
end
@group = options[:group]
@rev = options[:rev]
Expand Down
2 changes: 1 addition & 1 deletion spec/author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
author.pads.should == []
end

if TEST_CONFIG[:api_version] > 1
if TEST_CONFIG[:api_version].to_s > '1'
it "should get the name" do
author = @eth.create_author :mapper => 'Author B', :name => 'Jim Jimmers'
author.name.should == 'Jim Jimmers'
Expand Down
2 changes: 1 addition & 1 deletion spec/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
:api_key: your api key
# Full filesystem path to APIKEY.txt, may be used instead of the above :api_key setting
:api_key_file:
:api_version: 1.1
:api_version: "1.1"
2 changes: 1 addition & 1 deletion spec/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
pad.text.should == "abc\n"
end

if TEST_CONFIG[:api_version] > 1
if TEST_CONFIG[:api_version].to_s > '1'
it "should list all group ids" do
group_ids = @eth.group_ids
group_ids.size.should == 4
Expand Down
6 changes: 5 additions & 1 deletion spec/pad_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
e.message.should == 'padID does already exist'
end

it "should list all pad ids" do
@eth.pad_ids.should == ["my_new_pad"]
end

it "should automatically create a Pad" do
pad = @eth.pad 'another new pad'
pad.text = "The initial text"
Expand Down Expand Up @@ -119,7 +123,7 @@
@eth.create_pad('another new pad').id.should_not == nil
end

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

0 comments on commit 02152b4

Please sign in to comment.