Skip to content

Commit 06725c1

Browse files
author
Nils Fredrik Gjerull
committed
Add support for Etherpad API version 1.2.13.
1 parent 3c43b7d commit 06725c1

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The methods are 1:1 with the EPLite API methods.
3030
Depends on JSON.simple (https://github.com/fangyidong/json-simple).
3131

3232
### NOTES ###
33-
HEAD currently targets Etherpad Lite API v1.2.12.
33+
Latest release currently targets Etherpad Lite API v1.2.12.
3434
The plan is to keep up with the most recent version of the Etherpad Lite API.
3535
(Note that we're talking about API versions here, not release versions).
3636

Diff for: src/main/java/net/gjerull/etherpad/client/EPLiteClient.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* </code>
1717
*/
1818
public class EPLiteClient {
19-
private static final String DEFAULT_API_VERSION = "1.2.12";
19+
private static final String DEFAULT_API_VERSION = "1.2.13";
2020
private static final String DEFAULT_ENCODING = "UTF-8";
2121
private final EPLiteConnection connection;
2222

@@ -129,7 +129,8 @@ public Map listAllGroups() {
129129
}
130130

131131
// Authors
132-
// These authors are bound to the attributes the users choose (color and name). The author id is returned in "authorID".
132+
// These authors are bound to the attributes the users choose (color and name).
133+
// The author id is returned in "authorID".
133134

134135
/**
135136
* Create a new author.
@@ -153,7 +154,8 @@ public Map createAuthor(String name) {
153154
}
154155

155156
/**
156-
* Creates a new Author for authorMapper if one doesn't already exist. Helps you map your application's authors to Etherpad Lite's authors.
157+
* Creates a new Author for authorMapper if one doesn't already exist.
158+
* Helps you map your application's authors to Etherpad Lite's authors.
157159
* The author id is returned in "authorID".
158160
*
159161
* @param authorMapper string
@@ -166,7 +168,8 @@ public Map createAuthorIfNotExistsFor(String authorMapper) {
166168
}
167169

168170
/**
169-
* Creates a new Author for authorMapper if one doesn't already exist. Helps you map your application's authors to Etherpad Lite's authors.
171+
* Creates a new Author for authorMapper if one doesn't already exist.
172+
* Helps you map your application's authors to Etherpad Lite's authors.
170173
* The author id is returned in "authorID".
171174
*
172175
* @param authorMapper string
@@ -363,7 +366,7 @@ public Map getText(String padId, long rev) {
363366
}
364367

365368
/**
366-
* Creates a new revision with the given text (or creates a new pad).
369+
* Creates a new revision with the given text.
367370
*
368371
* @param padId the pad's id string
369372
* @param text the pad's new text
@@ -375,6 +378,21 @@ public void setText(String padId, String text) {
375378
this.connection.post("setText", args);
376379
}
377380

381+
/**
382+
* Creates a new revision with the given text appended to the existing text.
383+
*
384+
* API >= 1.2.13
385+
*
386+
* @param padId the pad's id string
387+
* @param text the pad's new text
388+
*/
389+
public void appendText(String padId, String text) {
390+
Map<String,Object> args = new HashMap<>();
391+
args.put("padID", padId);
392+
args.put("text", text);
393+
this.connection.post("appendText", args);
394+
}
395+
378396
/**
379397
* Returns a Map containing the current revision of the pad's text as HTML.
380398
* The html is stored under "html".
@@ -404,7 +422,7 @@ public Map getHTML(String padId, long rev) {
404422
}
405423

406424
/**
407-
* Creates a new revision with the given html (or creates a new pad).
425+
* Creates a new revision with the given html.
408426
*
409427
* @param padId the pad's id string
410428
* @param html the pad's new html text

Diff for: src/test/java/net/gjerull/etherpad/client/EPLiteClientIntegrationTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public void create_author_with_author_mapper() throws Exception {
143143

144144
assertEquals(secondAuthorName, thirdAuthorName);
145145
}
146-
147146
@Test
148147
public void create_and_delete_session() throws Exception {
149148
String authorMapper = "username";
@@ -169,7 +168,7 @@ public void create_and_delete_session() throws Exception {
169168
Map sessionInfo = client.getSessionInfo(secondSessionId);
170169
assertEquals(groupId, sessionInfo.get("groupID"));
171170
assertEquals(authorId, sessionInfo.get("authorID"));
172-
assertEquals(sessionValidUntil.getTime() / 1000, (long) sessionInfo.get("validUntil"));
171+
assertEquals(sessionValidUntil.getTime() / 1000L, (long) sessionInfo.get("validUntil"));
173172

174173
Map sessionsOfGroup = client.listSessionsOfGroup(groupId);
175174
sessionInfo = (Map) sessionsOfGroup.get(firstSessionId);
@@ -225,6 +224,10 @@ public void create_pad_set_and_get_content() {
225224
"<span class=\"removed\">g&#229; &#229; gj&#248;r et &#230;rend</span>"
226225
));
227226

227+
client.appendText(padID, "lagt til nå");
228+
text = (String) client.getText(padID).get("text");
229+
assertEquals("gå og gjøre et ærend igjen\nlagt til nå\n", text);
230+
228231
Map attributePool = (Map) client.getAttributePool(padID).get("pool");
229232
assertTrue(attributePool.containsKey("attribToNum"));
230233
assertTrue(attributePool.containsKey("nextNum"));
@@ -239,7 +242,7 @@ public void create_pad_set_and_get_content() {
239242
List savedRevisions = (List) client.listSavedRevisions(padID).get("savedRevisions");
240243
assertEquals(2, savedRevisions.size());
241244
assertEquals(2L, savedRevisions.get(0));
242-
assertEquals(3L, savedRevisions.get(1));
245+
assertEquals(4L, savedRevisions.get(1));
243246

244247
long padUsersCount = (long) client.padUsersCount(padID).get("padUsersCount");
245248
assertEquals(0, padUsersCount);

0 commit comments

Comments
 (0)