etherpad-lite 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +13 -0
- data/README.rdoc +3 -3
- data/lib/etherpad-lite/client.rb +47 -12
- data/lib/etherpad-lite/models/chat_message.rb +61 -0
- data/lib/etherpad-lite/models/diff.rb +43 -0
- data/lib/etherpad-lite/models/instance.rb +2 -2
- data/lib/etherpad-lite/models/pad.rb +24 -0
- data/lib/etherpad-lite/models.rb +2 -0
- data/lib/etherpad-lite/version.rb +4 -2
- metadata +19 -22
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e60ac28822b76594b6deefade5bc8dc793e7f8fda892862ed393061a8fc04d0
|
4
|
+
data.tar.gz: 6bdd88bd892d675dff75c9b44de75b751b84d446b75164fcc69d1f7edff60c6e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04ddf7130b280b8c12d594d2db43e920b10bf9d691313acc98f91f9f529d78039bdb1df433dc784c77fbf0118d184617b824889eae29caeef0b9a576b009f4cb
|
7
|
+
data.tar.gz: f90d5cefeb797c74bd2862e12b697ac7cc4a376000fda82470a97e3a2064230e5926b15bc8e10efa3ca5b9636c50f06e75b1f8ebdf86f76ea8cb4a12ebd08f34
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
** RELEASE 0.3.0 (2013-08-27) **
|
2
|
+
|
3
|
+
* 100th commit, woot!
|
4
|
+
* Target version 1.2.8 of API
|
5
|
+
* Added EtherpadLite::API_VERSION constant to reflect the above
|
6
|
+
* Added EtherpadLite::Pad#diff (EtherpadLite::Diff)
|
7
|
+
* Added EtherpadLite::Pad#changeset
|
8
|
+
|
9
|
+
** RELEASE 0.2.3 (2013-04-11) **
|
10
|
+
|
11
|
+
* Add support for Chat API
|
12
|
+
* Default to the latest supported API version on the server
|
13
|
+
|
1
14
|
** RELEASE 0.2.2 (2013-01-20) **
|
2
15
|
|
3
16
|
* Support for Etherpad Lite API v1.2.1
|
data/README.rdoc
CHANGED
@@ -39,7 +39,7 @@ The above example deals with public pads, accessible to anyone through the Web U
|
|
39
39
|
Examples are documented in EtherpadLite::Group, EtherpadLite::Author, and EtherpadLite::Session.
|
40
40
|
|
41
41
|
== Example use in Rails
|
42
|
-
For your view, I recommend the jQuery plugin at {github.com/
|
42
|
+
For your view, I recommend the jQuery plugin at {github.com/ether/etherpad-lite-jquery-plugin}[https://github.com/ether/etherpad-lite-jquery-plugin].
|
43
43
|
Also, I recommend reading the docs for EtherpadLite::Group first.
|
44
44
|
|
45
45
|
Add the following to your Gemfile
|
@@ -74,7 +74,7 @@ Some example controller actions:
|
|
74
74
|
@group = ether.get_group(params[:ep_group_id])
|
75
75
|
@pad = @group.pad(params[:ep_pad_name])
|
76
76
|
# Map the user to an EtherpadLite Author
|
77
|
-
author = ether.author("my_app_user_#{current_user.id}", :
|
77
|
+
author = ether.author("my_app_user_#{current_user.id}", name: current_user.name)
|
78
78
|
# Get or create an hour-long session for this Author in this Group
|
79
79
|
sess = session[:ep_sessions][@group.id] ? ether.get_session(session[:ep_sessions][@group.id]) : @group.create_session(author, 60)
|
80
80
|
if sess.expired?
|
@@ -83,7 +83,7 @@ Some example controller actions:
|
|
83
83
|
end
|
84
84
|
session[:ep_sessions][@group.id] = sess.id
|
85
85
|
# Set the EtherpadLite session cookie. This will automatically be picked up by the jQuery plugin's iframe.
|
86
|
-
cookies[:sessionID] = {:
|
86
|
+
cookies[:sessionID] = {value: sess.id, domain: ".yourdomain.com"}
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
data/lib/etherpad-lite/client.rb
CHANGED
@@ -27,7 +27,7 @@ module EtherpadLite
|
|
27
27
|
# client = EtherpadLite.client('https://etherpad.yoursite.com', 'your api key', '1.1')
|
28
28
|
#
|
29
29
|
# client = EtherpadLite.client(9001, 'your api key', '1.1') # Alias to http://localhost:9001
|
30
|
-
def self.client(url_or_port, api_key_or_file, api_version=
|
30
|
+
def self.client(url_or_port, api_key_or_file, api_version=nil)
|
31
31
|
Client.new(url_or_port, api_key_or_file, api_version)
|
32
32
|
end
|
33
33
|
|
@@ -41,31 +41,43 @@ module EtherpadLite
|
|
41
41
|
attr_reader :api_version
|
42
42
|
|
43
43
|
# Instantiate a new Etherpad Lite Client. You may pass a full url or just a port number. The api key may be a string
|
44
|
-
# or a File object. If you do not specify an API version, it will default to the latest version
|
45
|
-
def initialize(url_or_port, api_key_or_file, api_version=
|
44
|
+
# or a File object. If you do not specify an API version, it will default to the latest version.
|
45
|
+
def initialize(url_or_port, api_key_or_file, api_version=nil)
|
46
46
|
url_or_port = "http://localhost:#{url_or_port}" if url_or_port.is_a? Integer
|
47
47
|
@uri = URI.parse(url_or_port)
|
48
48
|
@api_key = api_key_or_file.is_a?(IO) ? api_key_or_file.read : api_key_or_file
|
49
|
-
@api_version = api_version.to_s
|
49
|
+
@api_version = api_version ? api_version.to_s : current_api_version.to_s
|
50
|
+
@ssl_verify = OpenSSL::SSL::VERIFY_PEER
|
51
|
+
end
|
52
|
+
|
53
|
+
# Whether peer must be verified if the API URL is SSL
|
54
|
+
def ssl_verify(mode)
|
55
|
+
@ssl_verify = mode
|
50
56
|
end
|
51
57
|
|
52
58
|
# Call an API method
|
53
59
|
def method_missing(method, params={})
|
54
|
-
|
55
|
-
? ->(url, params) { RestClient.post(url, params) } \
|
56
|
-
: ->(url, params) { RestClient.get(url, :params => params) }
|
57
|
-
call(method, params, &request)
|
60
|
+
call(method, params)
|
58
61
|
end
|
59
62
|
|
60
63
|
private
|
61
64
|
|
65
|
+
# Returns the latest api version. Defaults to "1" if anything goes wrong.
|
66
|
+
def current_api_version
|
67
|
+
JSON.parse(get('/api').to_s)['currentVersion'] rescue 1
|
68
|
+
end
|
69
|
+
|
62
70
|
# Calls the EtherpadLite API and returns the :data portion of the response Hash.
|
63
71
|
# If the API response contains an error code, an exception is raised.
|
64
72
|
def call(api_method, params={}, &request)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
path = "/api/#{api_version}/#{api_method}"
|
74
|
+
|
75
|
+
begin
|
76
|
+
result = api_method =~ /^(set|create|delete)/ ? post(path, params) : get(path, params)
|
77
|
+
response = JSON.parse(result.to_s, :symbolize_names => true)
|
78
|
+
rescue JSON::ParserError => e
|
79
|
+
raise Error, "Unable to parse JSON response: #{json}"
|
80
|
+
end
|
69
81
|
|
70
82
|
case response[:code]
|
71
83
|
when 0 then response[:data]
|
@@ -73,5 +85,28 @@ module EtherpadLite
|
|
73
85
|
else raise Error, "An unknown error ocurrced while handling the API response: #{response.to_s}"
|
74
86
|
end
|
75
87
|
end
|
88
|
+
|
89
|
+
# Makes a GET request
|
90
|
+
def get(path, params={})
|
91
|
+
params[:apikey] = self.api_key
|
92
|
+
RestClient::Request.execute(
|
93
|
+
:method => :get,
|
94
|
+
:url => "#{self.uri}#{path}",
|
95
|
+
:headers => {
|
96
|
+
:params => params
|
97
|
+
},
|
98
|
+
:verify_ssl=> @ssl_verify )
|
99
|
+
end
|
100
|
+
|
101
|
+
# Makes a POST request
|
102
|
+
def post(path, params={})
|
103
|
+
params[:apikey] = self.api_key
|
104
|
+
RestClient::Request.execute(
|
105
|
+
:method => :post,
|
106
|
+
:url => "#{self.uri}#{path}",
|
107
|
+
:headers=> {},
|
108
|
+
:payload=> params,
|
109
|
+
:verify_ssl=> @ssl_verify )
|
110
|
+
end
|
76
111
|
end
|
77
112
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module EtherpadLite
|
2
|
+
# An Etherpad Lite Chat message
|
3
|
+
class ChatMessage
|
4
|
+
# The EtherpadLite::Instance object
|
5
|
+
attr_reader :instance
|
6
|
+
# The pad id
|
7
|
+
attr_reader :pad_id
|
8
|
+
# The message text
|
9
|
+
attr_reader :text
|
10
|
+
# User/Author id
|
11
|
+
attr_reader :user_id
|
12
|
+
# Unix timestamp
|
13
|
+
attr_reader :timestamp
|
14
|
+
# User/Author name
|
15
|
+
attr_reader :user_name
|
16
|
+
|
17
|
+
# Instantiate a ChatMessage
|
18
|
+
def initialize(instance, attrs)
|
19
|
+
@instance = instance
|
20
|
+
@pad_id = attrs[:padID]
|
21
|
+
@text = attrs[:text]
|
22
|
+
@user_id = attrs[:userId]
|
23
|
+
@timestamp = attrs[:time] / 1000 if attrs[:time]
|
24
|
+
@user_name = attrs[:userName]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns this message's Pad
|
28
|
+
def pad
|
29
|
+
if pad_id
|
30
|
+
@pad ||= Pad.new(instance, pad_id)
|
31
|
+
else
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the Author that sent this message
|
37
|
+
def author
|
38
|
+
if user_id
|
39
|
+
@author ||= Author.new(instance, user_id)
|
40
|
+
else
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :user, :author
|
46
|
+
|
47
|
+
# Time object
|
48
|
+
def time
|
49
|
+
if timestamp
|
50
|
+
@time ||= Time.at(timestamp)
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the message text
|
57
|
+
def to_s
|
58
|
+
text.to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module EtherpadLite
|
2
|
+
# Represents a diff between two Pad revisions.
|
3
|
+
class Diff
|
4
|
+
# The EtherpadLite::Instance object
|
5
|
+
attr_accessor :instance
|
6
|
+
# The EtherpadLite::Pad object
|
7
|
+
attr_accessor :pad
|
8
|
+
# Diff start revision
|
9
|
+
attr_accessor :start_rev
|
10
|
+
# Diff end revision
|
11
|
+
attr_accessor :end_rev
|
12
|
+
|
13
|
+
# If end_rev is not specified, the latest revision will be used
|
14
|
+
def initialize(pad, start_rev, end_rev=nil)
|
15
|
+
@instance = pad.instance
|
16
|
+
@pad = pad
|
17
|
+
@start_rev = start_rev
|
18
|
+
@end_rev = end_rev || pad.revision_numbers.last
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the diff as html
|
22
|
+
def html
|
23
|
+
diff[:html]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the IDs of the authors who were involved in the diff
|
27
|
+
def author_ids
|
28
|
+
diff[:authors]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns Authors who were involved in the diff
|
32
|
+
def authors
|
33
|
+
@authors ||= author_ids.map { |id| Author.new(instance, id) }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Queries and caches the diff
|
39
|
+
def diff
|
40
|
+
@diff ||= instance.client.createDiffHTML(padID: pad.id, startRev: start_rev, endRev: end_rev)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -4,7 +4,7 @@ module EtherpadLite
|
|
4
4
|
# ether = EtherpadLite.client('https://etherpad.yoursite.com', 'your api key', '1.1')
|
5
5
|
#
|
6
6
|
# ether = EtherpadLite.client(9001, 'your api key', '1.1') # Alias to http://localhost:9001
|
7
|
-
def self.connect(url_or_port, api_key_or_file, api_version=
|
7
|
+
def self.connect(url_or_port, api_key_or_file, api_version=nil)
|
8
8
|
Instance.new(url_or_port, api_key_or_file, api_version)
|
9
9
|
end
|
10
10
|
|
@@ -16,7 +16,7 @@ module EtherpadLite
|
|
16
16
|
|
17
17
|
# Instantiate a new Etherpad Lite Instance. You may pass a full url or just a port number. The api key may be a string
|
18
18
|
# or a File object.
|
19
|
-
def initialize(url_or_port, api_key_or_file, api_version=
|
19
|
+
def initialize(url_or_port, api_key_or_file, api_version=nil)
|
20
20
|
@client = Client.new(url_or_port, api_key_or_file, api_version)
|
21
21
|
end
|
22
22
|
|
@@ -121,6 +121,16 @@ module EtherpadLite
|
|
121
121
|
revision_numbers.map { |n| Pad.new(@instance, @id, :rev => n) }
|
122
122
|
end
|
123
123
|
|
124
|
+
# Returns a Diff. If end_rev is not specified, the latest revision will be used
|
125
|
+
def diff(start_rev, end_rev=nil)
|
126
|
+
Diff.new(self, start_rev, end_rev)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Returns the changeset for the given revision
|
130
|
+
def changeset(rev)
|
131
|
+
@instance.client.getRevisionChangeset(padID: @id, rev: rev)
|
132
|
+
end
|
133
|
+
|
124
134
|
# Returns an array of users hashes, representing users currently using the pad
|
125
135
|
def users
|
126
136
|
@instance.client.padUsers(padID: @id)[:padUsers]
|
@@ -152,6 +162,20 @@ module EtherpadLite
|
|
152
162
|
author_ids.map { |id| Author.new(@instance, id) }
|
153
163
|
end
|
154
164
|
|
165
|
+
# Returns an array of chat message Hashes
|
166
|
+
def chat_messages(start_index=nil, end_index=nil)
|
167
|
+
messages = @instance.client.getChatHistory(:padID => @id, :start => start_index, :end => end_index)[:messages]
|
168
|
+
messages.map do |msg|
|
169
|
+
attrs = {padID: @id}.merge(msg)
|
170
|
+
ChatMessage.new(@instance, attrs)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Returns the number of chat messages
|
175
|
+
def chat_size
|
176
|
+
@instance.client.getChatHead(padID: @id)[:chatHead] + 1
|
177
|
+
end
|
178
|
+
|
155
179
|
# Returns true if this is a public Pad (opposite of private?).
|
156
180
|
# This only applies to Pads belonging to a Group.
|
157
181
|
def public?
|
data/lib/etherpad-lite/models.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'etherpad-lite/models/padded'
|
2
2
|
require 'etherpad-lite/models/instance'
|
3
3
|
require 'etherpad-lite/models/pad'
|
4
|
+
require 'etherpad-lite/models/diff'
|
5
|
+
require 'etherpad-lite/models/chat_message'
|
4
6
|
require 'etherpad-lite/models/group'
|
5
7
|
require 'etherpad-lite/models/author'
|
6
8
|
require 'etherpad-lite/models/session'
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etherpad-lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jordan Hollinger
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rest-client
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.6'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.6'
|
30
27
|
description: etherpad-lite is a Ruby interface to Etherpad Lite's HTTP JSON API
|
@@ -34,41 +31,41 @@ extensions: []
|
|
34
31
|
extra_rdoc_files:
|
35
32
|
- README.rdoc
|
36
33
|
files:
|
34
|
+
- CHANGELOG
|
35
|
+
- LICENSE
|
36
|
+
- README.rdoc
|
37
37
|
- lib/etherpad-lite.rb
|
38
|
-
- lib/etherpad-lite/
|
39
|
-
- lib/etherpad-lite/models
|
40
|
-
- lib/etherpad-lite/models/pad.rb
|
38
|
+
- lib/etherpad-lite/client.rb
|
39
|
+
- lib/etherpad-lite/models.rb
|
41
40
|
- lib/etherpad-lite/models/author.rb
|
41
|
+
- lib/etherpad-lite/models/chat_message.rb
|
42
|
+
- lib/etherpad-lite/models/diff.rb
|
43
|
+
- lib/etherpad-lite/models/group.rb
|
42
44
|
- lib/etherpad-lite/models/instance.rb
|
45
|
+
- lib/etherpad-lite/models/pad.rb
|
46
|
+
- lib/etherpad-lite/models/padded.rb
|
43
47
|
- lib/etherpad-lite/models/session.rb
|
44
|
-
- lib/etherpad-lite/client.rb
|
45
48
|
- lib/etherpad-lite/version.rb
|
46
|
-
- lib/etherpad-lite/models.rb
|
47
|
-
- README.rdoc
|
48
|
-
- CHANGELOG
|
49
|
-
- LICENSE
|
50
49
|
homepage: http://github.com/jhollinger/ruby-etherpad-lite
|
51
50
|
licenses: []
|
51
|
+
metadata: {}
|
52
52
|
post_install_message:
|
53
53
|
rdoc_options: []
|
54
54
|
require_paths:
|
55
55
|
- lib
|
56
56
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
57
|
requirements:
|
59
|
-
- -
|
58
|
+
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '0'
|
62
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
62
|
requirements:
|
65
|
-
- -
|
63
|
+
- - ">="
|
66
64
|
- !ruby/object:Gem::Version
|
67
65
|
version: '0'
|
68
66
|
requirements: []
|
69
|
-
|
70
|
-
rubygems_version: 1.8.23
|
67
|
+
rubygems_version: 3.0.3.1
|
71
68
|
signing_key:
|
72
|
-
specification_version:
|
69
|
+
specification_version: 4
|
73
70
|
summary: A Ruby client library for Etherpad Lite
|
74
71
|
test_files: []
|