rong_cloud_server 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/rong_cloud/configuration.rb +6 -1
- data/lib/rong_cloud/errors.rb +3 -1
- data/lib/rong_cloud/request.rb +5 -1
- data/lib/rong_cloud/service.rb +8 -2
- data/lib/rong_cloud/services/chatroom.rb +64 -8
- data/lib/rong_cloud/services/conversation_notification.rb +23 -0
- data/lib/rong_cloud/services/group.rb +3 -1
- data/lib/rong_cloud/services/history_message.rb +1 -1
- data/lib/rong_cloud/services/message.rb +12 -1
- data/lib/rong_cloud/services/message/message_channel.rb +2 -1
- data/lib/rong_cloud/services/message_priority.rb +32 -0
- data/lib/rong_cloud/services/message_recall.rb +18 -0
- data/lib/rong_cloud/services/sensitive_word.rb +30 -0
- data/rong_cloud.gemspec +1 -1
- data/test/rong_cloud/request_test.rb +12 -0
- data/test/rong_cloud/services/chatroom_test.rb +105 -4
- data/test/rong_cloud/services/conversation_notification_test.rb +27 -0
- data/test/rong_cloud/services/history_message_test.rb +1 -1
- data/test/rong_cloud/services/message/message_channel_test.rb +1 -2
- data/test/rong_cloud/services/message_priority_test.rb +50 -0
- data/test/rong_cloud/services/message_recall_test.rb +27 -0
- data/test/rong_cloud/services/message_test.rb +18 -0
- data/test/rong_cloud/services/sensitive_word_test.rb +44 -0
- data/test/test_helper.rb +1 -0
- metadata +10 -5
- data/README.zh-CN.md +0 -50
- data/lib/rong_cloud/services/wordfilter.rb +0 -18
- data/test/rong_cloud/services/wordfilter_test.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8851d724f0063d44b4baec6498e55dbcb584ce2
|
4
|
+
data.tar.gz: 46cbca45d889185c5e3a2062c17d99f9d8a7df83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8f62f13ef18c5c4541c34fae5df6969c73855f9955b910ebc1c3955d2688e0892dabe8d2a077bb8685bf9f7d805f082c1a0f214539448a81b2835415d5cfe97
|
7
|
+
data.tar.gz: 994b4805135d4b3113cf2638ad072f28fd9293be0329f3c61d5d048830f32e6e6f9f4f8a4f22bbcca330f8e60d978a142d7becf41f08baec84b9b39a9c5d9b09
|
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
===
|
3
3
|
[](https://travis-ci.org/Martin91/rong_cloud)
|
4
4
|
[](https://coveralls.io/github/Martin91/rong_cloud?branch=master)
|
5
|
-
|
6
|
-
To view the README in Chinese, visit [README.zh-CN.md](./README.zh-CN.md)
|
5
|
+
[](https://codeclimate.com/github/Martin91/rong_cloud)
|
7
6
|
|
8
7
|
This repository implements most essential apis for [RongCloud Server API](http://www.rongcloud.cn/docs/server.html) in Ruby programming language.
|
9
8
|
|
@@ -50,7 +49,15 @@ Just include `RongCloud::Signature` in your codes to validate api signature and
|
|
50
49
|
|
51
50
|
More infos about parameters, refer to the [official documents](http://www.rongcloud.cn/docs/server.html#服务端实时消息路由).
|
52
51
|
|
52
|
+
### Run tests
|
53
|
+
```sh
|
54
|
+
ruby -Ilib -Itest -e 'ARGV.each { |f| require f }' ./test/**/*_test.rb
|
55
|
+
```
|
56
|
+
|
53
57
|
### How to contribute
|
54
58
|
1. Fork this repo;
|
55
59
|
2. Write your code and test;
|
56
|
-
3. Open a new Pull Request.
|
60
|
+
3. Open a new Pull Request.
|
61
|
+
|
62
|
+
### TODO
|
63
|
+
1. Logger support
|
@@ -6,16 +6,21 @@ module RongCloud
|
|
6
6
|
module Configuration
|
7
7
|
# The default host to accept connections, use a https protocol
|
8
8
|
DEFAULT_HOST = "https://api.cn.ronghub.com".freeze
|
9
|
+
DEFAULT_TIMEOUT = 2
|
9
10
|
|
10
11
|
module ModuleMethods
|
11
12
|
attr_accessor :app_key, :app_secret
|
12
|
-
attr_writer :host
|
13
|
+
attr_writer :host, :timeout
|
13
14
|
|
14
15
|
# Fetch the api host, the default is: https://api.cn.ronghub.com
|
15
16
|
#
|
16
17
|
def host
|
17
18
|
@host || DEFAULT_HOST
|
18
19
|
end
|
20
|
+
|
21
|
+
def timeout
|
22
|
+
@timeout || DEFAULT_TIMEOUT
|
23
|
+
end
|
19
24
|
end
|
20
25
|
extend ModuleMethods
|
21
26
|
end
|
data/lib/rong_cloud/errors.rb
CHANGED
@@ -6,7 +6,7 @@ module RongCloud
|
|
6
6
|
class RequestError < ::StandardError
|
7
7
|
# @!attribute [rw] business_code
|
8
8
|
# extended attribute, recording the return codes defined by RongCloud,
|
9
|
-
#
|
9
|
+
# refer to: http://www.rongcloud.cn/docs/server.html#api_code
|
10
10
|
attr_accessor :business_code
|
11
11
|
end
|
12
12
|
|
@@ -20,6 +20,8 @@ module RongCloud
|
|
20
20
|
class InternalServerError < RequestError;end
|
21
21
|
class Timeout < RequestError;end
|
22
22
|
|
23
|
+
# http://www.rongcloud.cn/docs/server.html#api
|
24
|
+
# API 返回值
|
23
25
|
HTTP_CODE_TO_ERRORS_MAP = {
|
24
26
|
"400" => BadRequest,
|
25
27
|
"401" => AuthenticationFailed,
|
data/lib/rong_cloud/request.rb
CHANGED
@@ -17,8 +17,12 @@ module RongCloud
|
|
17
17
|
def request(path, params = nil, content_type = :form_data)
|
18
18
|
uri = get_uri(path)
|
19
19
|
req = initialize_request(uri, params, content_type)
|
20
|
+
|
20
21
|
use_ssl = uri.scheme == 'https'
|
21
|
-
|
22
|
+
timeout = RongCloud::Configuration.timeout
|
23
|
+
request_options = { use_ssl: use_ssl, open_timeout: timeout, read_timeout: timeout }
|
24
|
+
|
25
|
+
res = Net::HTTP.start(uri.hostname, uri.port, request_options) do |http|
|
22
26
|
http.request(req)
|
23
27
|
end
|
24
28
|
|
data/lib/rong_cloud/service.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'rong_cloud/request'
|
2
2
|
require 'rong_cloud/services/user'
|
3
|
+
require 'rong_cloud/services/conversation_notification'
|
3
4
|
require 'rong_cloud/services/message'
|
4
|
-
require 'rong_cloud/services/
|
5
|
+
require 'rong_cloud/services/message_recall'
|
6
|
+
require 'rong_cloud/services/message_priority'
|
7
|
+
require 'rong_cloud/services/sensitive_word'
|
5
8
|
require 'rong_cloud/services/group'
|
6
9
|
require 'rong_cloud/services/chatroom'
|
7
10
|
require 'rong_cloud/services/history_message'
|
@@ -10,9 +13,12 @@ module RongCloud
|
|
10
13
|
class Service
|
11
14
|
include RongCloud::Request
|
12
15
|
include RongCloud::Services::User
|
16
|
+
include RongCloud::Services::ConversationNotification
|
13
17
|
include RongCloud::Services::Message
|
18
|
+
include RongCloud::Services::MessageRecall
|
19
|
+
include RongCloud::Services::MessagePriority
|
14
20
|
include RongCloud::Services::HistoryMessage
|
15
|
-
include RongCloud::Services::
|
21
|
+
include RongCloud::Services::SensitiveWord
|
16
22
|
include RongCloud::Services::Group
|
17
23
|
include RongCloud::Services::Chatroom
|
18
24
|
end
|
@@ -39,22 +39,30 @@ module RongCloud
|
|
39
39
|
request("/chatroom/query", chatroomId: chatroom_ids)
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
def query_chatroom_user_existence(chatroom_id, user_id)
|
43
|
+
request("/chatroom/user/exist", chatroomId: chatroom_id, userId: user_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def query_chatroom_users_existence(chatroom_id, user_id)
|
47
|
+
request("/chatroom/users/exist", chatroomId: chatroom_id, userId: user_id)
|
48
|
+
end
|
49
|
+
|
50
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_gag_add
|
43
51
|
#
|
44
|
-
def
|
52
|
+
def add_chatroom_gag_user(chatroom_id, user_id, minute)
|
45
53
|
request("/chatroom/user/gag/add", chatroomId: chatroom_id, userId: user_id, minute: minute)
|
46
54
|
end
|
47
55
|
|
48
|
-
# http://www.rongcloud.cn/docs/server.html
|
56
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_gag_rollback
|
49
57
|
#
|
50
|
-
def
|
51
|
-
request("/chatroom/user/
|
58
|
+
def rollback_chatroom_gag_user(chatroom_id, user_id)
|
59
|
+
request("/chatroom/user/gag/rollback", chatroomId: chatroom_id, userId: user_id)
|
52
60
|
end
|
53
61
|
|
54
|
-
# http://www.rongcloud.cn/docs/server.html
|
62
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_gag_list
|
55
63
|
#
|
56
|
-
def
|
57
|
-
request("/chatroom/user/
|
64
|
+
def chatroom_gag_users(chatroom_id)
|
65
|
+
request("/chatroom/user/gag/list", chatroomId: chatroom_id)
|
58
66
|
end
|
59
67
|
|
60
68
|
# Fetch members list in a specified chatroom
|
@@ -95,6 +103,54 @@ module RongCloud
|
|
95
103
|
def whitelisted_chatroom_users(chatroom_id)
|
96
104
|
request("/chatroom/user/whitelist/query", chatroomId: chatroom_id)
|
97
105
|
end
|
106
|
+
|
107
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_ban
|
108
|
+
def ban_chatroom_user(user_id, minute)
|
109
|
+
request("/chatroom/user/ban/add", userId: user_id, minute: minute)
|
110
|
+
end
|
111
|
+
|
112
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_ban_remove
|
113
|
+
def unban_chatroom_user(user_id)
|
114
|
+
request("/chatroom/user/ban/remove", userId: user_id)
|
115
|
+
end
|
116
|
+
|
117
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_ban_query
|
118
|
+
def banned_chatroom_users
|
119
|
+
request("/chatroom/user/ban/query")
|
120
|
+
end
|
121
|
+
|
122
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_block_add
|
123
|
+
#
|
124
|
+
def block_chatroom_user(chatroom_id, user_id, minute)
|
125
|
+
request("/chatroom/user/block/add", chatroomId: chatroom_id, userId: user_id, minute: minute)
|
126
|
+
end
|
127
|
+
|
128
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_block_rollback
|
129
|
+
#
|
130
|
+
def unblock_chatroom_user(chatroom_id, user_id)
|
131
|
+
request("/chatroom/user/block/rollback", chatroomId: chatroom_id, userId: user_id)
|
132
|
+
end
|
133
|
+
|
134
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_user_block_list
|
135
|
+
#
|
136
|
+
def blocked_chatroom_users(chatroom_id)
|
137
|
+
request("/chatroom/user/block/list", chatroomId: chatroom_id)
|
138
|
+
end
|
139
|
+
|
140
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_keepalive_add
|
141
|
+
def add_keepalive_chatroom(chatroom_id)
|
142
|
+
request("/chatroom/keepalive/add", chatroomId: chatroom_id)
|
143
|
+
end
|
144
|
+
|
145
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_keepalive_remove
|
146
|
+
def remove_keepalive_chatroom(chatroom_id)
|
147
|
+
request("/chatroom/keepalive/remove", chatroomId: chatroom_id)
|
148
|
+
end
|
149
|
+
|
150
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_keepalive_query
|
151
|
+
def keepalive_chatrooms
|
152
|
+
request("/chatroom/keepalive/query")
|
153
|
+
end
|
98
154
|
end
|
99
155
|
end
|
100
156
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RongCloud
|
2
|
+
module Services
|
3
|
+
# http://www.rongcloud.cn/docs/server.html#conversation_notification
|
4
|
+
module ConversationNotification
|
5
|
+
def set_conversation_notification(conversation_type, request_id, target_id, is_muted)
|
6
|
+
request("/conversation/notification/set", {
|
7
|
+
conversationType: conversation_type,
|
8
|
+
requestId: request_id,
|
9
|
+
targetId: target_id,
|
10
|
+
isMuted: is_muted
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_conversation_notification(conversation_type, request_id, target_id)
|
15
|
+
request("/conversation/notification/get", {
|
16
|
+
conversationType: conversation_type,
|
17
|
+
requestId: request_id,
|
18
|
+
targetId: target_id
|
19
|
+
})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module RongCloud
|
2
2
|
module Services
|
3
|
-
# http://www.rongcloud.cn/docs/server.html
|
3
|
+
# http://www.rongcloud.cn/docs/server.html#group
|
4
4
|
module Group
|
5
|
+
# @param user_id [String] user id
|
6
|
+
# @param groups [Hash] store group id as hash key, while group name as value, e.g. { 132 => "欢天喜地一家亲" }
|
5
7
|
def sync_group(user_id, groups)
|
6
8
|
params = {userId: user_id}
|
7
9
|
groups.each do |id, name|
|
@@ -2,7 +2,7 @@ require 'rong_cloud/services/message/message_channel'
|
|
2
2
|
|
3
3
|
module RongCloud
|
4
4
|
module Services
|
5
|
-
# http://www.rongcloud.cn/docs/server.html
|
5
|
+
# http://www.rongcloud.cn/docs/server.html#message
|
6
6
|
module Message
|
7
7
|
# General method to send messages
|
8
8
|
# @param from_user_id [String] sender id
|
@@ -14,6 +14,7 @@ module RongCloud
|
|
14
14
|
# @option content [Object] :content the body of message
|
15
15
|
# @option content [Object] :extra the extras of message,passed as a string
|
16
16
|
# and should be parsed by the message consumer
|
17
|
+
# @option content [Object] :user the informations for user, see: http://www.rongcloud.cn/docs/server.html#user_info
|
17
18
|
# @param args [Array] additional params,when it includes only one param,
|
18
19
|
# the args is a options; when 2 params, the first one is the `values` of
|
19
20
|
# a template message, the the last one is a options
|
@@ -21,6 +22,8 @@ module RongCloud
|
|
21
22
|
# total supported options determined by the message type
|
22
23
|
# @option options [String] :pushContent push content
|
23
24
|
# @option options [Hash] :pushData push data as payload
|
25
|
+
# @option options [Hash] :verifyBlacklist verify sender's blacklist
|
26
|
+
# @option options [Hash] :contentAvailable for iOS devices, see docs for more details
|
24
27
|
#
|
25
28
|
def send_message(from_user_id, target_id, channel_name, object_name, content, *args)
|
26
29
|
options = args.extract_options!
|
@@ -67,6 +70,14 @@ module RongCloud
|
|
67
70
|
send_message(from_user_id, to_discussion_id, :discussion, object_name, content, options)
|
68
71
|
end
|
69
72
|
|
73
|
+
def send_chatroom_message(from_user_id, to_chatroom_id, object_name, content, options = {})
|
74
|
+
send_message(from_user_id, to_chatroom_id, :chatroom, object_name, content, options)
|
75
|
+
end
|
76
|
+
|
77
|
+
def send_chatroom_broadcast_message(from_user_id, object_name, content, options = {})
|
78
|
+
send_message(from_user_id, nil, :chatroom_broadcast, object_name, content, options)
|
79
|
+
end
|
80
|
+
|
70
81
|
def send_broadcast_message(from_user_id, object_name, content, options = {})
|
71
82
|
send_message(from_user_id, nil, :broadcast, object_name, content, options)
|
72
83
|
end
|
@@ -6,13 +6,14 @@ module RongCloud
|
|
6
6
|
# 各消息渠道各自对应请求路径以及特殊参数名
|
7
7
|
#
|
8
8
|
CHANNEL_TO_REQUEST_DETAILS_MAP = {
|
9
|
-
|
9
|
+
private: { target_param_name: "toUserId", api_path: "/message/private/publish" },
|
10
10
|
private_template: { target_param_name: "toUserId", api_path: "/message/private/publish_template" },
|
11
11
|
system: { target_param_name: "toUserId", api_path: "/message/system/publish" },
|
12
12
|
system_template: { target_param_name: "toUserId", api_path: "/message/system/publish_template" },
|
13
13
|
group: { target_param_name: 'toGroupId', api_path: "/message/group/publish" },
|
14
14
|
discussion: { target_param_name: "toDiscussionId", api_path: "/message/discussion/publish" },
|
15
15
|
chatroom: { target_param_name: "toChatroomId", api_path: "/message/chatroom/publish" },
|
16
|
+
chatroom_broadcast: { api_path: "/message/chatroom/broadcast" },
|
16
17
|
broadcast: { api_path: "/message/broadcast" }
|
17
18
|
}.freeze
|
18
19
|
# 支持的消息渠道的列表
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rong_cloud/services/message/message_channel'
|
2
|
+
|
3
|
+
module RongCloud
|
4
|
+
module Services
|
5
|
+
# http://www.rongcloud.cn/docs/server.html#chatroom_message_priority
|
6
|
+
module MessagePriority
|
7
|
+
def add_chatroom_message_priority(object_name)
|
8
|
+
request("/chatroom/message/priority/add", objectName: object_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def remove_chatroom_message_priority(object_name)
|
12
|
+
request("/chatroom/message/priority/remove", objectName: object_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def chatroom_message_priorities
|
16
|
+
request("/chatroom/message/priority/query")
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_chatroom_message_whitelist(object_names)
|
20
|
+
request("/chatroom/whitelist/add", objectnames: object_names)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_chatroom_message_whitelist(object_names)
|
24
|
+
request("/chatroom/whitelist/delete", objectnames: object_names)
|
25
|
+
end
|
26
|
+
|
27
|
+
def chatroom_message_whitelist
|
28
|
+
request("/chatroom/whitelist/query")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rong_cloud/services/message/message_channel'
|
2
|
+
|
3
|
+
module RongCloud
|
4
|
+
module Services
|
5
|
+
# http://www.rongcloud.cn/docs/server.html#message_recall
|
6
|
+
module MessageRecall
|
7
|
+
def message_recall(from_user_id, conversation_type, target_id, message_uid, sent_time)
|
8
|
+
request("/message/recall", {
|
9
|
+
fromUserId: from_user_id,
|
10
|
+
conversationType: conversation_type,
|
11
|
+
targetId: target_id,
|
12
|
+
messageUID: message_uid,
|
13
|
+
sentTime: sent_time
|
14
|
+
})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RongCloud
|
2
|
+
module Services
|
3
|
+
# http://www.rongcloud.cn/docs/server.html#sensitiveword
|
4
|
+
module SensitiveWord
|
5
|
+
def add_sensitive_word(word, replace_word = nil)
|
6
|
+
arguments = { word: word }
|
7
|
+
if replace_word.is_a?(String) && replace_word.length > 0
|
8
|
+
arguments.merge!(replaceWord: replace_word)
|
9
|
+
end
|
10
|
+
|
11
|
+
request("/sensitiveword/add", arguments)
|
12
|
+
end
|
13
|
+
alias_method :add_wordfilter, :add_sensitive_word
|
14
|
+
|
15
|
+
def delete_sensitive_word(word)
|
16
|
+
request("/sensitiveword/delete", { word: word })
|
17
|
+
end
|
18
|
+
alias_method :delete_wordfilter, :delete_sensitive_word
|
19
|
+
|
20
|
+
def batch_delete_sensitive_word(words)
|
21
|
+
request("/sensitiveword/batch/delete", words: [*words])
|
22
|
+
end
|
23
|
+
|
24
|
+
def sensitive_word_list
|
25
|
+
request("/sensitiveword/list")
|
26
|
+
end
|
27
|
+
alias_method :wordfilter_list, :sensitive_word_list
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/rong_cloud.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.require_path = 'lib'
|
5
5
|
s.summary = 'RongCloud Server API SDK'
|
6
6
|
s.description = 'RongCloud Server API in Ruby,http://www.rongcloud.cn/docs/server.html'
|
7
|
-
s.version = '0.
|
7
|
+
s.version = '0.2.0'
|
8
8
|
s.files = `git ls-files`.split("\n")
|
9
9
|
s.authors = ['Martin Hong']
|
10
10
|
s.email = 'hongzeqin@gmail.com'
|
@@ -52,5 +52,17 @@ module RongCloud
|
|
52
52
|
assert_equal "user", response["userId"]
|
53
53
|
assert response["token"]
|
54
54
|
end
|
55
|
+
|
56
|
+
def test_request_with_timeout_set
|
57
|
+
original_timeout = RongCloud::Configuration.timeout
|
58
|
+
RongCloud::Configuration.timeout = 0.001
|
59
|
+
|
60
|
+
service = RongCloud::Service.new
|
61
|
+
assert_raises Net::OpenTimeout do
|
62
|
+
response = request("/user/getToken", { userId: 'user', name: "User", portraitUri: "uri" })
|
63
|
+
end
|
64
|
+
|
65
|
+
RongCloud::Configuration.timeout = original_timeout
|
66
|
+
end
|
55
67
|
end
|
56
68
|
end
|
@@ -86,18 +86,48 @@ module RongCloud
|
|
86
86
|
assert_equal 2, users.count
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
89
|
+
def test_query_chatroom_user_existence_for_existed_user
|
90
|
+
create_chatrooms({10009 => "room9"})
|
91
|
+
@service.join_chatroom("user3", 10009)
|
92
|
+
|
93
|
+
response = @service.query_chatroom_user_existence("10009", "user3")
|
94
|
+
assert response["isInChrm"]
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_query_chatroom_user_existence_for_unexisted_user
|
98
|
+
create_chatrooms({10009 => "room9"})
|
99
|
+
@service.join_chatroom("user3", 10009)
|
100
|
+
|
101
|
+
response = @service.query_chatroom_user_existence("10009", "unexisted_user_id")
|
102
|
+
refute response["isInChrm"]
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_query_chatroom_users_existence
|
106
|
+
create_chatrooms({10009 => "room9"})
|
107
|
+
@service.join_chatroom("user3", 10009)
|
108
|
+
|
109
|
+
response = @service.query_chatroom_users_existence("10009", ["user3", "unexisted_user_id"])
|
110
|
+
result = response["result"]
|
111
|
+
|
112
|
+
user3_result = result.detect{ |r| r["userId"] == "user3" }
|
113
|
+
assert_equal 1, user3_result["isInChrm"]
|
114
|
+
|
115
|
+
unexisted_user_result = result.detect{ |r| r["userId"] == "unexisted_user_id" }
|
116
|
+
assert_equal 0, unexisted_user_result["isInChrm"]
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_gag_chatroom_user_flow
|
90
120
|
create_chatrooms({10010 => "room10"})
|
91
121
|
@service.join_chatroom("user5", 10010)
|
92
122
|
|
93
|
-
response = @service.
|
123
|
+
response = @service.add_chatroom_gag_user(10010, "user5", 60)
|
94
124
|
assert_equal 200, response["code"]
|
95
125
|
|
96
|
-
response = @service.
|
126
|
+
response = @service.chatroom_gag_users(10010)
|
97
127
|
assert_equal 200, response["code"]
|
98
128
|
assert response["users"]
|
99
129
|
|
100
|
-
response = @service.
|
130
|
+
response = @service.rollback_chatroom_gag_user(10010, "user5")
|
101
131
|
assert_equal 200, response["code"]
|
102
132
|
end
|
103
133
|
|
@@ -130,6 +160,77 @@ module RongCloud
|
|
130
160
|
assert_equal 200, response["code"]
|
131
161
|
end
|
132
162
|
|
163
|
+
def test_ban_chatroom_user
|
164
|
+
error = assert_raises RongCloud::RequestError do
|
165
|
+
@service.ban_chatroom_user(1, 60)
|
166
|
+
end
|
167
|
+
|
168
|
+
# 聊天室全局禁言功能未开通。
|
169
|
+
assert_equal 1009, error.business_code
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_unban_chatroom_user
|
173
|
+
error = assert_raises RongCloud::RequestError do
|
174
|
+
@service.unban_chatroom_user(1)
|
175
|
+
end
|
176
|
+
|
177
|
+
# 聊天室全局禁言功能未开通。
|
178
|
+
assert_equal 1009, error.business_code
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_banned_chatroom_users
|
182
|
+
error = assert_raises RongCloud::RequestError do
|
183
|
+
@service.banned_chatroom_users
|
184
|
+
end
|
185
|
+
|
186
|
+
# 聊天室全局禁言功能未开通。
|
187
|
+
assert_equal 1009, error.business_code
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_block_chatroom_user_flow
|
191
|
+
create_chatrooms({10010 => "room10"})
|
192
|
+
@service.join_chatroom("user5", 10010)
|
193
|
+
|
194
|
+
response = @service.block_chatroom_user(10010, "user5", 60)
|
195
|
+
assert_equal 200, response["code"]
|
196
|
+
|
197
|
+
response = @service.blocked_chatroom_users(10010)
|
198
|
+
assert response["users"].detect{ |u| u["userId"] == "user5" }
|
199
|
+
|
200
|
+
response = @service.unblock_chatroom_user(10010, "user5")
|
201
|
+
assert_equal 200, response["code"]
|
202
|
+
|
203
|
+
response = @service.blocked_chatroom_users(10010)
|
204
|
+
refute response["users"].detect{ |u| u["userId"] == "user5" }
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_add_keepalive_chatroom
|
208
|
+
error = assert_raises RongCloud::RequestError do
|
209
|
+
@service.add_keepalive_chatroom(10011)
|
210
|
+
end
|
211
|
+
|
212
|
+
assert_equal "聊天室保活服务未开通。", error.message
|
213
|
+
assert_equal 1009, error.business_code
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_remove_keepalive_chatroom
|
217
|
+
error = assert_raises RongCloud::RequestError do
|
218
|
+
@service.remove_keepalive_chatroom(10011)
|
219
|
+
end
|
220
|
+
|
221
|
+
assert_equal "聊天室保活服务未开通。", error.message
|
222
|
+
assert_equal 1009, error.business_code
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_keepalive_chatrooms
|
226
|
+
error = assert_raises RongCloud::RequestError do
|
227
|
+
@service.keepalive_chatrooms
|
228
|
+
end
|
229
|
+
|
230
|
+
assert_equal "聊天室保活服务未开通。", error.message
|
231
|
+
assert_equal 1009, error.business_code
|
232
|
+
end
|
233
|
+
|
133
234
|
private
|
134
235
|
def create_chatrooms(chatrooms = { 10000001 => "super chatroom"})
|
135
236
|
@service.create_chatroom(chatrooms)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
3
|
+
module RongCloud
|
4
|
+
module Services
|
5
|
+
class ConversationNotificationTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
8
|
+
def test_set_conversation_notification
|
9
|
+
response = @service.set_conversation_notification(1, 2, 99, 1)
|
10
|
+
assert_equal 200, response["code"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_conversation_notification
|
14
|
+
@service.set_conversation_notification(1, 2, 99, 1)
|
15
|
+
response = @service.get_conversation_notification(1, 2, 99)
|
16
|
+
assert_equal 1, response["isMuted"]
|
17
|
+
|
18
|
+
@service.set_conversation_notification(1, 2, 99, 0)
|
19
|
+
response = @service.get_conversation_notification(1, 2, 99)
|
20
|
+
assert_equal 0, response["isMuted"]
|
21
|
+
|
22
|
+
response = @service.get_conversation_notification(1, 2, "unexisted_id")
|
23
|
+
assert_equal 0, response["isMuted"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -13,8 +13,7 @@ module RongCloud
|
|
13
13
|
error = assert_raises RongCloud::UnsupportedMessageChannelName do
|
14
14
|
RongCloud::Services::Message::MessageChannel.new(:nothing)
|
15
15
|
end
|
16
|
-
|
17
|
-
assert_equal expected_error, error.message
|
16
|
+
assert error.message =~ /^support\sonly\schannels:/
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_target_param_name_for_private
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
3
|
+
module RongCloud
|
4
|
+
module Services
|
5
|
+
class MessagePriorityTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
8
|
+
def test_chatroom_message_priority_flow
|
9
|
+
response = @service.add_chatroom_message_priority("RC:CmdMsg")
|
10
|
+
assert_equal 200, response["code"]
|
11
|
+
|
12
|
+
response = @service.add_chatroom_message_priority(["RC:DizNtf", "RC:CmdNtf"])
|
13
|
+
assert_equal 200, response["code"]
|
14
|
+
|
15
|
+
response = @service.chatroom_message_priorities
|
16
|
+
assert_equal ["RC:CmdMsg", "RC:DizNtf", "RC:CmdNtf"].sort, response["objectNames"].sort
|
17
|
+
|
18
|
+
response = @service.remove_chatroom_message_priority(["RC:DizNtf", "RC:CmdNtf"])
|
19
|
+
assert_equal 200, response["code"]
|
20
|
+
|
21
|
+
response = @service.remove_chatroom_message_priority("RC:CmdMsg")
|
22
|
+
assert_equal 200, response["code"]
|
23
|
+
|
24
|
+
response = @service.chatroom_message_priorities
|
25
|
+
assert_empty response["objectNames"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_chatroom_message_whitelist_flow
|
29
|
+
response = @service.add_chatroom_message_whitelist("RC:TxtMsg")
|
30
|
+
assert_equal 200, response["code"]
|
31
|
+
|
32
|
+
response = @service.add_chatroom_message_whitelist(["RC:ImgMsg", "RC:LBSMsg"])
|
33
|
+
assert_equal 200, response["code"]
|
34
|
+
|
35
|
+
response = @service.chatroom_message_whitelist
|
36
|
+
whitelist = response["whitlistMsgType"].sort.select{ |i| !i.empty? }
|
37
|
+
assert_equal ["RC:TxtMsg", "RC:ImgMsg", "RC:LBSMsg"].sort, whitelist
|
38
|
+
|
39
|
+
response = @service.remove_chatroom_message_whitelist(["RC:ImgMsg", "RC:LBSMsg"])
|
40
|
+
assert_equal 200, response["code"]
|
41
|
+
|
42
|
+
response = @service.remove_chatroom_message_whitelist("RC:TxtMsg")
|
43
|
+
assert_equal 200, response["code"]
|
44
|
+
|
45
|
+
response = @service.chatroom_message_whitelist
|
46
|
+
assert_equal [""], response["whitlistMsgType"]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
3
|
+
module RongCloud
|
4
|
+
module Services
|
5
|
+
class MessageRecallTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
8
|
+
# conversationType = 1
|
9
|
+
def test_message_recall_for_private_session
|
10
|
+
response = @service.message_recall(1, 1, 2, "MESSAGE_UUID", (Time.now.to_f * 1000).to_i)
|
11
|
+
assert_equal 200, response["code"]
|
12
|
+
end
|
13
|
+
|
14
|
+
# conversationType = 2
|
15
|
+
def test_message_recall_for_discussion_session
|
16
|
+
response = @service.message_recall(1, 2, 2, "MESSAGE_UUID", (Time.now.to_f * 1000).to_i)
|
17
|
+
assert_equal 200, response["code"]
|
18
|
+
end
|
19
|
+
|
20
|
+
# conversationType = 3
|
21
|
+
def test_message_recall_for_group_session
|
22
|
+
response = @service.message_recall(1, 3, 2, "MESSAGE_UUID", (Time.now.to_f * 1000).to_i)
|
23
|
+
assert_equal 200, response["code"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -118,6 +118,24 @@ module RongCloud
|
|
118
118
|
assert_equal 200, response["code"]
|
119
119
|
end
|
120
120
|
|
121
|
+
def test_send_chatroom_message_with_single_to_chatroom_id
|
122
|
+
response = @service.send_chatroom_message(1, 2, "RC:TxtMsg", { content: "hello world", extra: "nothing" })
|
123
|
+
assert_equal 200, response["code"]
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_send_chatroom_message_with_multiple_to_chatroom_ids
|
127
|
+
response = @service.send_chatroom_message(1, [2, 3, 4], "RC:TxtMsg", { content: "hello world", extra: "nothing" })
|
128
|
+
assert_equal 200, response["code"]
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_send_chatroom_broadcast_message
|
132
|
+
error = assert_raises RongCloud::RequestError do
|
133
|
+
@service.send_chatroom_broadcast_message(1, "RC:TxtMsg", { content: "hello world", extra: "nothing" })
|
134
|
+
end
|
135
|
+
# 未开通该服务,请到开发者管理后台开通或提交工单申请。
|
136
|
+
assert_equal 1009, error.business_code
|
137
|
+
end
|
138
|
+
|
121
139
|
def test_send_broadcast_message
|
122
140
|
response = @service.send_broadcast_message(1, "RC:TxtMsg", { content: "hello world", extra: "nothing" })
|
123
141
|
assert_equal 200, response["code"]
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
3
|
+
module RongCloud
|
4
|
+
module Services
|
5
|
+
class SensitiveWordTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
8
|
+
def test_add_sensitive_word_with_single_word
|
9
|
+
response = @service.add_sensitive_word("敏感词")
|
10
|
+
assert_equal 200, response["code"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_add_sensitive_word_with_single_word_and_replace_word
|
14
|
+
response = @service.add_sensitive_word("敏感词", "***")
|
15
|
+
assert_equal 200, response["code"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_delete_exist_sensitive_word
|
19
|
+
@service.add_sensitive_word("hello")
|
20
|
+
response = @service.delete_sensitive_word("hello")
|
21
|
+
assert_equal 200, response["code"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_delete_unexist_sensitive_word
|
25
|
+
response = @service.delete_sensitive_word("unexistedWord")
|
26
|
+
assert_equal 200, response["code"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_batch_delete_sensitive_word
|
30
|
+
response = @service.batch_delete_sensitive_word(["hello", "敏感词"])
|
31
|
+
assert_equal 200, response["code"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_sensitive_word_list
|
35
|
+
@service.add_sensitive_word("乱")
|
36
|
+
response = @service.sensitive_word_list
|
37
|
+
words = response["words"].map{|word| word["word"]}
|
38
|
+
assert_includes words, "乱"
|
39
|
+
|
40
|
+
@service.delete_sensitive_word("乱")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rong_cloud_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Hong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -62,7 +62,6 @@ files:
|
|
62
62
|
- ".travis.yml"
|
63
63
|
- Gemfile
|
64
64
|
- README.md
|
65
|
-
- README.zh-CN.md
|
66
65
|
- Rakefile
|
67
66
|
- lib/core_ext/array.rb
|
68
67
|
- lib/rong_cloud.rb
|
@@ -71,24 +70,30 @@ files:
|
|
71
70
|
- lib/rong_cloud/request.rb
|
72
71
|
- lib/rong_cloud/service.rb
|
73
72
|
- lib/rong_cloud/services/chatroom.rb
|
73
|
+
- lib/rong_cloud/services/conversation_notification.rb
|
74
74
|
- lib/rong_cloud/services/group.rb
|
75
75
|
- lib/rong_cloud/services/history_message.rb
|
76
76
|
- lib/rong_cloud/services/message.rb
|
77
77
|
- lib/rong_cloud/services/message/message_channel.rb
|
78
|
+
- lib/rong_cloud/services/message_priority.rb
|
79
|
+
- lib/rong_cloud/services/message_recall.rb
|
80
|
+
- lib/rong_cloud/services/sensitive_word.rb
|
78
81
|
- lib/rong_cloud/services/user.rb
|
79
|
-
- lib/rong_cloud/services/wordfilter.rb
|
80
82
|
- lib/rong_cloud/signature.rb
|
81
83
|
- rong_cloud.gemspec
|
82
84
|
- test/rong_cloud/configuration_test.rb
|
83
85
|
- test/rong_cloud/request_test.rb
|
84
86
|
- test/rong_cloud/service_test_setup.rb
|
85
87
|
- test/rong_cloud/services/chatroom_test.rb
|
88
|
+
- test/rong_cloud/services/conversation_notification_test.rb
|
86
89
|
- test/rong_cloud/services/group_test.rb
|
87
90
|
- test/rong_cloud/services/history_message_test.rb
|
88
91
|
- test/rong_cloud/services/message/message_channel_test.rb
|
92
|
+
- test/rong_cloud/services/message_priority_test.rb
|
93
|
+
- test/rong_cloud/services/message_recall_test.rb
|
89
94
|
- test/rong_cloud/services/message_test.rb
|
95
|
+
- test/rong_cloud/services/sensitive_word_test.rb
|
90
96
|
- test/rong_cloud/services/user_test.rb
|
91
|
-
- test/rong_cloud/services/wordfilter_test.rb
|
92
97
|
- test/rong_cloud/signature_test.rb
|
93
98
|
- test/rong_cloud_test.rb
|
94
99
|
- test/test_helper.rb
|
data/README.zh-CN.md
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
融云 Server SDK
|
2
|
-
===
|
3
|
-
|
4
|
-
此 gem 实现了[融云 Server API](http://www.rongcloud.cn/docs/server.html)的大部分接口的 Ruby 实现。
|
5
|
-
|
6
|
-
### Getting Started
|
7
|
-
1. 安装此 gem:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
$ gem install rong_cloud_server
|
11
|
-
```
|
12
|
-
|
13
|
-
or, install in Gemfile:
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'rong_cloud_server', '~> 0.0.2'
|
17
|
-
```
|
18
|
-
|
19
|
-
2. 在项目中添加配置:
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
RongCloud.configure do |config|
|
23
|
-
config.app_key = "APP_KEY"
|
24
|
-
config.app_secret = "SECRET_KEY"
|
25
|
-
config.host = "http://api.cn.ronghub.com" # default: https://api.cn.ronghub.com, use http is convenient for debugging
|
26
|
-
end
|
27
|
-
```
|
28
|
-
3. 通过 service 对象使用:
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
service = RongCloud::Service.new
|
32
|
-
|
33
|
-
# 更多方法,请查看测试用例 https://github.com/Martin91/rong_cloud/tree/master/test/rong_cloud/services
|
34
|
-
service.get_token(..., ..., ...)
|
35
|
-
```
|
36
|
-
|
37
|
-
### 特点
|
38
|
-
1. **轻量**:无其他依赖;
|
39
|
-
2. **简洁**:不过分封装,仅做必要的请求实现,使用方自行处理响应的 JSON 解析后的 Hash 对象,各字段释义请自行查阅融云文档;
|
40
|
-
3. **丰富的异常类型**:针对不同的 HTTP 状态码,抛出相对应的异常类型,同时可以通过异常对象的 `business_code` 方法获取错误业务码,可以参考[request test 的代码](https://github.com/Martin91/rong_cloud/blob/master/test/rong_cloud/request_test.rb)。
|
41
|
-
|
42
|
-
### TODOs for v0.1.0
|
43
|
-
1. 实时消息路由;
|
44
|
-
2. 消息历史记录;
|
45
|
-
3. 在线状态订阅。
|
46
|
-
|
47
|
-
### How to contribute
|
48
|
-
1. Fork this repo;
|
49
|
-
2. Write your code and test;
|
50
|
-
3. Open a new Pull Request.
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module RongCloud
|
2
|
-
module Services
|
3
|
-
# http://www.rongcloud.cn/docs/server.html#敏感词服务
|
4
|
-
module Wordfilter
|
5
|
-
def add_wordfilter(word)
|
6
|
-
request("/wordfilter/add", { word: word })
|
7
|
-
end
|
8
|
-
|
9
|
-
def delete_wordfilter(word)
|
10
|
-
request("/wordfilter/delete", { word: word })
|
11
|
-
end
|
12
|
-
|
13
|
-
def wordfilter_list
|
14
|
-
request("/wordfilter/list")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'rong_cloud/service_test_setup'
|
2
|
-
|
3
|
-
module RongCloud
|
4
|
-
module Services
|
5
|
-
class WordfilterTest < Minitest::Test
|
6
|
-
include RongCloud::ServiceTestSetup
|
7
|
-
|
8
|
-
def test_add_wordfilter_with_single_word
|
9
|
-
response = @service.add_wordfilter("敏感词")
|
10
|
-
assert_equal 200, response["code"]
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_delete_exist_wordfilter
|
14
|
-
@service.add_wordfilter("hello")
|
15
|
-
response = @service.delete_wordfilter("hello")
|
16
|
-
assert_equal 200, response["code"]
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_delete_unexist_wordfilter
|
20
|
-
response = @service.delete_wordfilter("unexistedWord")
|
21
|
-
assert_equal 500, response["code"] # TODO: 500 非期待,后边修复
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_wordfilter_list
|
25
|
-
@service.add_wordfilter("乱")
|
26
|
-
response = @service.wordfilter_list
|
27
|
-
words = response["words"].map{|word| word["word"]}
|
28
|
-
assert_includes words, "乱"
|
29
|
-
|
30
|
-
@service.delete_wordfilter("乱")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|