-
Notifications
You must be signed in to change notification settings - Fork 2
/
chatroom.rb
156 lines (132 loc) · 5.94 KB
/
chatroom.rb
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
module RongCloud
module Services
# apis for chatroom http://www.rongcloud.cn/docs/server.html#聊天室服务
module Chatroom
# create a new chatroom,support creating multiple ones
# http://www.rongcloud.cn/docs/server.html#创建聊天室_方法
#
# @param chatrooms [Hash] created chatrooms
#
def create_chatroom(chatrooms)
params = {}
chatrooms.each { |room_id, room_name| params["chatroom[#{room_id}]"] = room_name }
request("/chatroom/create", params)
end
# join a chatroom http://www.rongcloud.cn/docs/server.html#加入聊天室_方法
#
# @param user_id [String, Array] one or more user ids
# @param chatroom_id [String] the id of the chatroom
#
def join_chatroom(user_id, chatroom_id)
request("/chatroom/join", userId: user_id, chatroomId: chatroom_id)
end
# dismiss a chatroom http://www.rongcloud.cn/docs/server.html#销毁聊天室_方法
#
# @param chatroom_ids [String, Array] one or more chatroom ids
#
def destroy_chatroom(chatroom_ids)
request("/chatroom/destroy", chatroomId: chatroom_ids)
end
# Query one or more chatroom details http://www.rongcloud.cn/docs/server.html#查询聊天室信息_方法
#
# @param chatroom_ids [String, Array] one or more chatroom ids
#
def query_chatroom(chatroom_ids)
request("/chatroom/query", chatroomId: chatroom_ids)
end
def query_chatroom_user_existence(chatroom_id, user_id)
request("/chatroom/user/exist", chatroomId: chatroom_id, userId: user_id)
end
def query_chatroom_users_existence(chatroom_id, user_id)
request("/chatroom/users/exist", chatroomId: chatroom_id, userId: user_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_gag_add
#
def add_chatroom_gag_user(chatroom_id, user_id, minute)
request("/chatroom/user/gag/add", chatroomId: chatroom_id, userId: user_id, minute: minute)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_gag_rollback
#
def rollback_chatroom_gag_user(chatroom_id, user_id)
request("/chatroom/user/gag/rollback", chatroomId: chatroom_id, userId: user_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_gag_list
#
def chatroom_gag_users(chatroom_id)
request("/chatroom/user/gag/list", chatroomId: chatroom_id)
end
# Fetch members list in a specified chatroom
#
# @param chatroom_id [String] chatroom id
# @param count [String, Fixnum] the number of members to fetch, the maximum number is 500
# @param order [String] order direction based on the time when users join the chatroom,
# 1 for asc ordering, while 2 for desc ordering
#
def query_chatroom_users(chatroom_id, count, order = "1")
request("chatroom/user/query", chatroomId: chatroom_id, count: count, order: order)
end
# http://www.rongcloud.cn/docs/server.html#聊天室消息停止分发_方法
#
def stop_chatroom_distribution(chatroom_id)
request("/chatroom/message/stopDistribution", chatroomId: chatroom_id)
end
# http://www.rongcloud.cn/docs/server.html#聊天室消息恢复分发_方法
#
def resume_chatroom_distribution(chatroom_id)
request("/chatroom/message/resumeDistribution", chatroomId: chatroom_id)
end
# 添加聊天室白名单成员 http://www.rongcloud.cn/docs/server.html#添加聊天室白名单成员_方法
#
def add_chatroom_whitelist(chatroom_id, user_id)
request("/chatroom/user/whitelist/add", chatroomId: chatroom_id, userId: user_id)
end
# http://www.rongcloud.cn/docs/server.html#移除聊天室白名单成员_方法
def remove_chatroom_whitelist(chatroom_id, user_id)
request("/chatroom/user/whitelist/remove", chatroomId: chatroom_id, userId: user_id)
end
# http://www.rongcloud.cn/docs/server.html#查询聊天室白名单成员_方法
def whitelisted_chatroom_users(chatroom_id)
request("/chatroom/user/whitelist/query", chatroomId: chatroom_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_ban
def ban_chatroom_user(user_id, minute)
request("/chatroom/user/ban/add", userId: user_id, minute: minute)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_ban_remove
def unban_chatroom_user(user_id)
request("/chatroom/user/ban/remove", userId: user_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_ban_query
def banned_chatroom_users
request("/chatroom/user/ban/query")
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_block_add
#
def block_chatroom_user(chatroom_id, user_id, minute)
request("/chatroom/user/block/add", chatroomId: chatroom_id, userId: user_id, minute: minute)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_block_rollback
#
def unblock_chatroom_user(chatroom_id, user_id)
request("/chatroom/user/block/rollback", chatroomId: chatroom_id, userId: user_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_user_block_list
#
def blocked_chatroom_users(chatroom_id)
request("/chatroom/user/block/list", chatroomId: chatroom_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_keepalive_add
def add_keepalive_chatroom(chatroom_id)
request("/chatroom/keepalive/add", chatroomId: chatroom_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_keepalive_remove
def remove_keepalive_chatroom(chatroom_id)
request("/chatroom/keepalive/remove", chatroomId: chatroom_id)
end
# http://www.rongcloud.cn/docs/server.html#chatroom_keepalive_query
def keepalive_chatrooms
request("/chatroom/keepalive/query")
end
end
end
end