Permalink
Browse files

Add new API 1.2.8 methods

  • Loading branch information...
jhollinger committed Sep 28, 2013
1 parent 233bbbb commit bdce05941e5867d9ed8bcfd4cb08c74b78dfca3a
View
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
spec.summary = "A Ruby client library for Etherpad Lite"
spec.description = "etherpad-lite is a Ruby interface to Etherpad Lite's HTTP JSON API"
spec.authors = ['Jordan Hollinger']
- spec.date = '2013-04-11'
+ spec.date = '2013-09-27'
spec.email = 'jordan@jordanhollinger.com'
spec.homepage = 'http://github.com/jhollinger/ruby-etherpad-lite'
@@ -1,6 +1,7 @@
require 'etherpad-lite/models/padded'
require 'etherpad-lite/models/instance'
require 'etherpad-lite/models/pad'
+require 'etherpad-lite/models/diff'
require 'etherpad-lite/models/chat_message'
require 'etherpad-lite/models/group'
require 'etherpad-lite/models/author'
@@ -0,0 +1,43 @@
+module EtherpadLite
+ # Represents a diff between two Pad revisions.
+ class Diff
+ # The EtherpadLite::Instance object
+ attr_accessor :instance
+ # The EtherpadLite::Pad object
+ attr_accessor :pad
+ # Diff start revision
+ attr_accessor :start_rev
+ # Diff end revision
+ attr_accessor :end_rev
+
+ # If end_rev is not specified, the latest revision will be used
+ def initialize(pad, start_rev, end_rev=nil)
+ @instance = pad.instance
+ @pad = pad
+ @start_rev = start_rev
+ @end_rev = end_rev || pad.revision_numbers.last
+ end
+
+ # Returns the diff as html
+ def html
+ diff[:html]
+ end
+
+ # Returns the IDs of the authors who were involved in the diff
+ def author_ids
+ diff[:authors]
+ end
+
+ # Returns Authors who were involved in the diff
+ def authors
+ @authors ||= author_ids.map { |id| Author.new(instance, id) }
+ end
+
+ private
+
+ # Queries and caches the diff
+ def diff
+ @diff ||= instance.client.createDiffHTML(padID: pad.id, startRev: start_rev, endRev: end_rev)
+ end
+ end
+end
@@ -121,6 +121,16 @@ def revisions
revision_numbers.map { |n| Pad.new(@instance, @id, :rev => n) }
end
+ # Returns a Diff. If end_rev is not specified, the latest revision will be used
+ def diff(start_rev, end_rev=nil)
+ Diff.new(self, start_rev, end_rev)
+ end
+
+ # Returns the changeset for the given revision
+ def changeset(rev)
+ @instance.client.getRevisionChangeset(padID: @id, rev: rev)
+ end
+
# Returns an array of users hashes, representing users currently using the pad
def users
@instance.client.padUsers(padID: @id)[:padUsers]
@@ -1,4 +1,6 @@
module EtherpadLite
- # The library version
- VERSION = '0.2.3'
+ # Library version
+ VERSION = '0.3.0'
+ # API target version
+ API_VERSION = '1.2.8'
end
View
@@ -0,0 +1,12 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe EtherpadLite::Diff do
+ before do
+ @eth = EtherpadLite.connect TEST_CONFIG[:url], TEST_CONFIG[:api_key_file] || TEST_CONFIG[:api_key], TEST_CONFIG[:api_version]
+ end
+
+ it "should return a diff" do
+ pad = @eth.create_pad 'my new diffed pad', :text => 'The initial text'
+ pad.diff(0, 1).html.should =~ /The initial text/
+ end
+end

0 comments on commit bdce059

Please sign in to comment.