Skip to content

Commit 4ee204c

Browse files
author
Markus Keunecke
committed
API implementation for updating current user's status (fix #6)
This class is capable of setting a custom user status via zulip API.
1 parent ed57e9d commit 4ee204c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.taliox.zulip.calls.users;
2+
3+
import io.taliox.zulip.ZulipRestExecutor;
4+
import io.taliox.zulip.calls.ZulipRestAPICall;
5+
import org.apache.http.client.methods.HttpPost;
6+
7+
/**
8+
* Updates the status for the currently authenticated user. See the API description for details on updating the status.
9+
*
10+
* @see <a href=
11+
* "https://zulip.com/api/update-status">https://zulip.com/api/update-status</a>
12+
*/
13+
public class PostUserStatus extends ZulipRestAPICall {
14+
15+
/**
16+
* The content of the status message.
17+
* @see <a href=
18+
* "https://zulip.com/api/update-status#parameter-status_text">API description</a>
19+
*/
20+
private final String statusText;
21+
/**
22+
* The name of the status emoji.
23+
* @see <a href=
24+
* "https://zulip.com/api/update-status#parameter-emoji_name">API description</a>
25+
*/
26+
private final String emojiName;
27+
28+
/**
29+
* Instantiate a new {@link PostUserStatus}.
30+
*
31+
* @param statusText
32+
* The content of the status message. If left empty, the status message will be cleared.
33+
* @param emojiName
34+
* The name of the status emoji for display in the client.
35+
*/
36+
public PostUserStatus(String statusText, String emojiName) {
37+
this.statusText = statusText;
38+
this.emojiName = emojiName;
39+
setZulipAPIUrl("/api/v1/users/me/status");
40+
}
41+
42+
@Override
43+
public String execute(ZulipRestExecutor executor) {
44+
setHttpController(executor.httpController);
45+
HttpPost post = new HttpPost(this.httpController.getServer() + getZulipAPIUrl());
46+
getParameters().put("status_text", this.statusText);
47+
getParameters().put("emoji_name", this.emojiName);
48+
return performRequest(getParameters(), post);
49+
}
50+
}

0 commit comments

Comments
 (0)