-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathKeepalive.java
More file actions
100 lines (86 loc) · 3.82 KB
/
Copy pathKeepalive.java
File metadata and controls
100 lines (86 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package io.rong.methods.chatroom.keepalive;
import io.rong.RongCloud;
import io.rong.models.CheckMethod;
import io.rong.models.chatroom.ChatroomModel;
import io.rong.models.response.ChatroomKeepaliveResult;
import io.rong.models.response.ResponseResult;
import io.rong.util.CommonUtil;
import io.rong.util.GsonUtil;
import io.rong.util.HttpUtil;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
/**
* Chatroom Keepalive Service
*/
public class Keepalive {
private static final String UTF8 = "UTF-8";
private static final String PATH = "chatroom/keepalive";
private String appKey;
private String appSecret;
private RongCloud rongCloud;
public RongCloud getRongCloud() {
return rongCloud;
}
public void setRongCloud(RongCloud rongCloud) {
this.rongCloud = rongCloud;
}
public Keepalive(String appKey, String appSecret) {
this.appKey = appKey;
this.appSecret = appSecret;
}
/**
* Add Chatroom Keepalive Method
*
* @param chatroom: Chatroom information, id (required)
*
* @return ResponseResult
**/
public ResponseResult add(ChatroomModel chatroom) throws Exception {
String message = CommonUtil.checkFiled(chatroom,PATH,CheckMethod.ADD);
if(null != message){
return (ResponseResult)GsonUtil.fromJson(message,ResponseResult.class);
}
StringBuilder sb = new StringBuilder();
sb.append("&chatroomId=").append(URLEncoder.encode(chatroom.getId().toString(), UTF8));
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1, body.length());
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/chatroom/keepalive/add.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
return (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.ADD,HttpUtil.returnResult(conn, rongCloud.getConfig())), ResponseResult.class);
}
/**
* Removes the chatroom keepalive method
*
* @param chatroom: Chatroom information, id (required)
*
* @return ResponseResult
**/
public ResponseResult remove(ChatroomModel chatroom) throws Exception {
String message = CommonUtil.checkFiled(chatroom,PATH,CheckMethod.REMOVE);
if(null != message){
return (ResponseResult)GsonUtil.fromJson(message,ResponseResult.class);
}
StringBuilder sb = new StringBuilder();
sb.append("&chatroomId=").append(URLEncoder.encode(chatroom.getId().toString(), UTF8));
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1, body.length());
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/chatroom/keepalive/remove.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
return (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.REMOVE,HttpUtil.returnResult(conn, rongCloud.getConfig())), ResponseResult.class);
}
/**
* Retrieves the chatroom keepalive
*
*
* @return ResponseResult
**/
public ChatroomKeepaliveResult getList() throws Exception {
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/chatroom/keepalive/query.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter("", conn, rongCloud.getConfig());
return (ChatroomKeepaliveResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.GETLIST,HttpUtil.returnResult(conn, rongCloud.getConfig())), ChatroomKeepaliveResult.class);
}
}