rong_cloud_server 0.0.2 → 0.1.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 +28 -15
- data/README.zh-CN.md +50 -0
- data/lib/rong_cloud.rb +2 -2
- data/lib/rong_cloud/configuration.rb +4 -4
- data/lib/rong_cloud/errors.rb +5 -13
- data/lib/rong_cloud/request.rb +19 -19
- data/lib/rong_cloud/service.rb +2 -2
- data/lib/rong_cloud/services/chatroom.rb +23 -21
- data/lib/rong_cloud/services/group.rb +1 -23
- data/lib/rong_cloud/services/history_message.rb +22 -0
- data/lib/rong_cloud/services/message.rb +18 -21
- data/lib/rong_cloud/services/user.rb +6 -24
- data/lib/rong_cloud/services/wordfilter.rb +1 -9
- data/lib/rong_cloud/signature.rb +8 -8
- data/rong_cloud.gemspec +3 -3
- data/test/rong_cloud/service_test_setup.rb +10 -0
- data/test/rong_cloud/services/chatroom_test.rb +5 -1
- data/test/rong_cloud/services/group_test.rb +5 -1
- data/test/rong_cloud/services/history_message_test.rb +23 -0
- data/test/rong_cloud/services/message_test.rb +5 -1
- data/test/rong_cloud/services/user_test.rb +5 -1
- data/test/rong_cloud/services/wordfilter_test.rb +5 -1
- metadata +8 -5
- data/test/rong_cloud/service_test.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82f88e70a08efe992ba2736c8db0ab8b4425589a
|
4
|
+
data.tar.gz: d9efa695a5402e686f0d942836dcd4d6c027874e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 964d72d2a924d9e8b5c11328fd67fc4a90fae37cede3640c3b18ebd6bef3a241d5fece396b802aeb1c35fb82e10dad66c72ceff003595b95277723467ea4e888
|
7
|
+
data.tar.gz: 4ab2768d2e86928f927ef3b5da23bbe1d82aaf36240f73703599d9e0cb294b91ddbabc003ae2926e02cdbfd8e162e1d5a35bc709cf92f797c26646a02b22b9dd
|
data/README.md
CHANGED
@@ -1,37 +1,50 @@
|
|
1
|
-
|
1
|
+
[RongCloud](http://rongcloud.cn/) Server API SDK in Ruby
|
2
2
|
===
|
3
3
|
|
4
|
-
|
4
|
+
To view the README in Chinese, visit [README.zh-CN.md](./README.zh-CN.md)
|
5
|
+
|
6
|
+
This repository implements most essential apis for [RongCloud Server API](http://www.rongcloud.cn/docs/server.html) in Ruby programming language.
|
5
7
|
|
6
8
|
### Getting Started
|
7
|
-
1.
|
8
|
-
|
9
|
+
1. Install the gem:
|
10
|
+
|
11
|
+
```sh
|
12
|
+
$ gem install rong_cloud_server
|
13
|
+
```
|
14
|
+
|
15
|
+
or, install it in Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'rong_cloud_server', '~> 0.0.2'
|
19
|
+
```
|
20
|
+
|
21
|
+
2. Append the following configurations in a initializer file:
|
9
22
|
|
10
23
|
```ruby
|
11
24
|
RongCloud.configure do |config|
|
12
25
|
config.app_key = "APP_KEY"
|
13
26
|
config.secret_key = "SECRET_KEY"
|
14
|
-
config.host = "http://api.cn.ronghub.com" # default: https://api.cn.ronghub.com, use http is convenient for debugging
|
27
|
+
config.host = "http://api.cn.ronghub.com" # default: https://api.cn.ronghub.com, use http here is just convenient for debugging
|
15
28
|
end
|
16
29
|
```
|
17
|
-
3.
|
30
|
+
3. Use the instance of `RongCloud::Service` to talk to RongCloud Server:
|
18
31
|
|
19
32
|
```ruby
|
20
33
|
service = RongCloud::Service.new
|
21
34
|
|
22
|
-
#
|
35
|
+
# Find more usage from test files under https://github.com/Martin91/rong_cloud/tree/master/test/rong_cloud/services
|
23
36
|
service.get_token(..., ..., ...)
|
24
37
|
```
|
25
38
|
|
26
|
-
###
|
27
|
-
1.
|
28
|
-
2.
|
29
|
-
3.
|
39
|
+
### Features
|
40
|
+
1. **Lightweight**:No other third-party gems dependences;
|
41
|
+
2. **Straight and Simple**:Just wrap api connections in Ruby, no any DSL and so that you do not learn too many new syntax, no any process on response;
|
42
|
+
3. **Detailed Exceptions**:Detailed and different exceptions according to the http status code,and you can get the [detailed error code](http://www.rongcloud.cn/docs/server.html#业务返回码), officially defined by RongCloud, through calling the extended method `business_code` on a exception, please refer to [request test](https://github.com/Martin91/rong_cloud/blob/master/test/rong_cloud/request_test.rb).
|
43
|
+
|
44
|
+
### How to work with Realtime Message Forward or Online Status Subscription
|
45
|
+
Just include `RongCloud::Signature` in your codes to validate api signature and then parse params.
|
30
46
|
|
31
|
-
|
32
|
-
1. 实时消息路由;
|
33
|
-
2. 消息历史记录;
|
34
|
-
3. 在线状态订阅。
|
47
|
+
More infos about parameters, refer to the [official documents](http://www.rongcloud.cn/docs/server.html#服务端实时消息路由).
|
35
48
|
|
36
49
|
### How to contribute
|
37
50
|
1. Fork this repo;
|
data/README.zh-CN.md
ADDED
@@ -0,0 +1,50 @@
|
|
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.
|
data/lib/rong_cloud.rb
CHANGED
@@ -3,9 +3,9 @@ require 'rong_cloud/errors'
|
|
3
3
|
require 'rong_cloud/service'
|
4
4
|
require 'core_ext/array'
|
5
5
|
|
6
|
-
#
|
6
|
+
# global namespace for this SDK
|
7
7
|
module RongCloud
|
8
|
-
#
|
8
|
+
# Use this method for connection settings
|
9
9
|
#
|
10
10
|
def self.configure(&block)
|
11
11
|
yield RongCloud::Configuration
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require "logger"
|
2
2
|
|
3
3
|
module RongCloud
|
4
|
-
#
|
4
|
+
# The main class to maintain connection settings
|
5
5
|
#
|
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
9
|
|
10
10
|
module ModuleMethods
|
11
11
|
attr_accessor :app_key, :app_secret, :host, :logger
|
12
12
|
|
13
|
-
#
|
13
|
+
# Fetch the api host, the default is: https://api.cn.ronghub.com
|
14
14
|
#
|
15
15
|
def host
|
16
16
|
@host || DEFAULT_HOST
|
17
17
|
end
|
18
18
|
|
19
|
-
#
|
19
|
+
# Fetch the logger, the default is STDOUT
|
20
20
|
def logger
|
21
21
|
@logger || default_logger
|
22
22
|
end
|
data/lib/rong_cloud/errors.rb
CHANGED
@@ -1,33 +1,25 @@
|
|
1
1
|
module RongCloud
|
2
|
-
# 不支持的消息类型错误
|
3
2
|
class UnsupportedMessageChannelName < ::StandardError;end
|
4
|
-
#
|
3
|
+
# Missing required settings for setup this gem
|
5
4
|
class MissingOptionError < ::StandardError;end
|
6
|
-
#
|
5
|
+
# The root exception for those related to RongCloud API
|
7
6
|
class RequestError < ::StandardError
|
8
7
|
# @!attribute [rw] business_code
|
9
|
-
#
|
8
|
+
# extended attribute, recording the return codes defined by RongCloud,
|
9
|
+
# View http://www.rongcloud.cn/docs/server.html#API_方法返回值说明
|
10
10
|
attr_accessor :business_code
|
11
11
|
end
|
12
12
|
|
13
|
-
# 错误请求
|
14
13
|
class BadRequest < RequestError;end
|
15
|
-
# 验证错误
|
16
14
|
class AuthenticationFailed < RequestError;end
|
17
|
-
# 被拒绝
|
18
15
|
class RequestForbidden < RequestError;end
|
19
|
-
# 资源不存在
|
20
16
|
class ResourceNotFound < RequestError;end
|
21
|
-
#
|
17
|
+
# Exceed group members limit
|
22
18
|
class ExceedLimit < RequestError;end
|
23
|
-
# 过多的请求
|
24
19
|
class TooManyRequests < RequestError;end
|
25
|
-
# 内部服务器错误
|
26
20
|
class InternalServerError < RequestError;end
|
27
|
-
# 内部服务器响应超时
|
28
21
|
class Timeout < RequestError;end
|
29
22
|
|
30
|
-
# 融云服务器响应状态码到 Ruby 错误类型的映射
|
31
23
|
HTTP_CODE_TO_ERRORS_MAP = {
|
32
24
|
"400" => BadRequest,
|
33
25
|
"401" => AuthenticationFailed,
|
data/lib/rong_cloud/request.rb
CHANGED
@@ -3,17 +3,17 @@ require 'json'
|
|
3
3
|
require 'rong_cloud/signature'
|
4
4
|
|
5
5
|
module RongCloud
|
6
|
-
#
|
6
|
+
# Handle api request, based on Ruby's built-in Net::HTTP,
|
7
|
+
# support both HTTP and HTTPS
|
7
8
|
#
|
8
9
|
module Request
|
9
10
|
include Signature
|
10
11
|
|
11
|
-
#
|
12
|
-
# @param
|
13
|
-
# @param
|
14
|
-
# @
|
15
|
-
# @
|
16
|
-
# @raise [RongCloud::BadRequest] 请求参数有误,缺失或者不正确等,详见官方文档
|
12
|
+
# @param path [String] The api endpoint
|
13
|
+
# @param params [Hash] api params
|
14
|
+
# @param content_type [Symbol] required formatting for request data, :form_data or :json
|
15
|
+
# @return [Hash] the parsed response represented by JSON
|
16
|
+
# @raise [RongCloud::BadRequest] when request params is invalid or other situations
|
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)
|
@@ -26,22 +26,22 @@ module RongCloud
|
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
|
-
#
|
29
|
+
# construct the api endpoint url
|
30
30
|
#
|
31
|
-
# @param path [String]
|
32
|
-
# @return [URI]
|
31
|
+
# @param path [String] the relative path for api endpoint,e.g. "/user/getToken" or "user/getToken"
|
32
|
+
# @return [URI] full url for the endpoint
|
33
33
|
#
|
34
34
|
def get_uri(path)
|
35
35
|
url = "#{RongCloud::Configuration.host}/#{path.gsub(/^\//, "")}"
|
36
36
|
URI(url.end_with?(".json") ? url : "#{url}.json")
|
37
37
|
end
|
38
38
|
|
39
|
-
#
|
39
|
+
# construct a new request
|
40
40
|
#
|
41
|
-
# @param uri [URI]
|
42
|
-
# @param params [Hash]
|
43
|
-
# @param content_type [Symbol]
|
44
|
-
# @return [Net::HTTP::Post]
|
41
|
+
# @param uri [URI] the relative path for api endpoint
|
42
|
+
# @param params [Hash] the request params
|
43
|
+
# @param content_type [Symbol] required formatting for request data, :form_data or :json
|
44
|
+
# @return [Net::HTTP::Post] the request object
|
45
45
|
#
|
46
46
|
def initialize_request(uri, params, content_type)
|
47
47
|
req = Net::HTTP::Post.new(uri)
|
@@ -58,11 +58,11 @@ module RongCloud
|
|
58
58
|
req
|
59
59
|
end
|
60
60
|
|
61
|
-
#
|
61
|
+
# parse the raw response
|
62
62
|
#
|
63
|
-
# @param res [HTTPResponse]
|
64
|
-
# @return [Hash] JSON
|
65
|
-
# @raise [RongCloud::BadRequest]
|
63
|
+
# @param res [HTTPResponse] the response
|
64
|
+
# @return [Hash] response data parsed as JSON
|
65
|
+
# @raise [RongCloud::BadRequest] when params are invalid or other situations
|
66
66
|
#
|
67
67
|
def handle_response(res)
|
68
68
|
json = JSON.parse(res.body)
|
data/lib/rong_cloud/service.rb
CHANGED
@@ -4,14 +4,14 @@ require 'rong_cloud/services/message'
|
|
4
4
|
require 'rong_cloud/services/wordfilter'
|
5
5
|
require 'rong_cloud/services/group'
|
6
6
|
require 'rong_cloud/services/chatroom'
|
7
|
+
require 'rong_cloud/services/history_message'
|
7
8
|
|
8
9
|
module RongCloud
|
9
|
-
# 封装所有接口的 Service 类,所有业务接口通过 Service 的实例完成调用
|
10
|
-
#
|
11
10
|
class Service
|
12
11
|
include RongCloud::Request
|
13
12
|
include RongCloud::Services::User
|
14
13
|
include RongCloud::Services::Message
|
14
|
+
include RongCloud::Services::HistoryMessage
|
15
15
|
include RongCloud::Services::Wordfilter
|
16
16
|
include RongCloud::Services::Group
|
17
17
|
include RongCloud::Services::Chatroom
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module RongCloud
|
2
2
|
module Services
|
3
|
-
#
|
3
|
+
# apis for chatroom http://www.rongcloud.cn/docs/server.html#聊天室服务
|
4
4
|
module Chatroom
|
5
|
-
#
|
5
|
+
# create a new chatroom,support creating multiple ones
|
6
|
+
# http://www.rongcloud.cn/docs/server.html#创建聊天室_方法
|
6
7
|
#
|
7
|
-
# @param chatrooms [Hash]
|
8
|
+
# @param chatrooms [Hash] created chatrooms
|
8
9
|
#
|
9
10
|
def create_chatroom(chatrooms)
|
10
11
|
params = {}
|
@@ -13,66 +14,67 @@ module RongCloud
|
|
13
14
|
request("/chatroom/create", params)
|
14
15
|
end
|
15
16
|
|
16
|
-
#
|
17
|
+
# join a chatroom http://www.rongcloud.cn/docs/server.html#加入聊天室_方法
|
17
18
|
#
|
18
|
-
# @param user_id [String, Array]
|
19
|
-
# @param chatroom_id [String]
|
19
|
+
# @param user_id [String, Array] one or more user ids
|
20
|
+
# @param chatroom_id [String] the id of the chatroom
|
20
21
|
#
|
21
22
|
def join_chatroom(user_id, chatroom_id)
|
22
23
|
request("/chatroom/join", userId: user_id, chatroomId: chatroom_id)
|
23
24
|
end
|
24
25
|
|
25
|
-
#
|
26
|
+
# dismiss a chatroom http://www.rongcloud.cn/docs/server.html#销毁聊天室_方法
|
26
27
|
#
|
27
|
-
# @param chatroom_ids [String, Array]
|
28
|
+
# @param chatroom_ids [String, Array] one or more chatroom ids
|
28
29
|
#
|
29
30
|
def destroy_chatroom(chatroom_ids)
|
30
31
|
request("/chatroom/destroy", chatroomId: chatroom_ids)
|
31
32
|
end
|
32
33
|
|
33
|
-
#
|
34
|
+
# Query one or more chatroom details http://www.rongcloud.cn/docs/server.html#查询聊天室信息_方法
|
34
35
|
#
|
35
|
-
# @param chatroom_ids [String, Array]
|
36
|
+
# @param chatroom_ids [String, Array] one or more chatroom ids
|
36
37
|
#
|
37
38
|
def query_chatroom(chatroom_ids)
|
38
39
|
request("/chatroom/query", chatroomId: chatroom_ids)
|
39
40
|
end
|
40
41
|
|
41
|
-
#
|
42
|
+
# http://www.rongcloud.cn/docs/server.html#添加禁言聊天室成员_方法
|
42
43
|
#
|
43
44
|
def block_chatroom_user(chatroom_id, user_id, minute)
|
44
45
|
request("/chatroom/user/gag/add", chatroomId: chatroom_id, userId: user_id, minute: minute)
|
45
46
|
end
|
46
47
|
|
47
|
-
#
|
48
|
+
# http://www.rongcloud.cn/docs/server.html#移除封禁聊天室成员_方法
|
48
49
|
#
|
49
50
|
def unblock_chatroom_user(chatroom_id, user_id)
|
50
51
|
request("/chatroom/user/block/rollback", chatroomId: chatroom_id, userId: user_id)
|
51
52
|
end
|
52
53
|
|
53
|
-
#
|
54
|
+
# http://www.rongcloud.cn/docs/server.html#查询被封禁聊天室成员_方法
|
54
55
|
#
|
55
56
|
def blocked_chatroom_users(chatroom_id)
|
56
57
|
request("/chatroom/user/block/list", chatroomId: chatroom_id)
|
57
58
|
end
|
58
59
|
|
59
|
-
#
|
60
|
+
# Fetch members list in a specified chatroom
|
60
61
|
#
|
61
|
-
# @param chatroom_id [String]
|
62
|
-
# @param count [String, Fixnum]
|
63
|
-
# @param order [String]
|
62
|
+
# @param chatroom_id [String] chatroom id
|
63
|
+
# @param count [String, Fixnum] the number of members to fetch, the maximum number is 500
|
64
|
+
# @param order [String] order direction based on the time when users join the chatroom,
|
65
|
+
# 1 for asc ordering, while 2 for desc ordering
|
64
66
|
#
|
65
67
|
def query_chatroom_users(chatroom_id, count, order = "1")
|
66
68
|
request("chatroom/user/query", chatroomId: chatroom_id, count: count, order: order)
|
67
69
|
end
|
68
70
|
|
69
|
-
#
|
71
|
+
# http://www.rongcloud.cn/docs/server.html#聊天室消息停止分发_方法
|
70
72
|
#
|
71
73
|
def stop_chatroom_distribution(chatroom_id)
|
72
74
|
request("/chatroom/message/stopDistribution", chatroomId: chatroom_id)
|
73
75
|
end
|
74
76
|
|
75
|
-
#
|
77
|
+
# http://www.rongcloud.cn/docs/server.html#聊天室消息恢复分发_方法
|
76
78
|
#
|
77
79
|
def resume_chatroom_distribution(chatroom_id)
|
78
80
|
request("/chatroom/message/resumeDistribution", chatroomId: chatroom_id)
|
@@ -84,12 +86,12 @@ module RongCloud
|
|
84
86
|
request("/chatroom/user/whitelist/add", chatroomId: chatroom_id, userId: user_id)
|
85
87
|
end
|
86
88
|
|
87
|
-
#
|
89
|
+
# http://www.rongcloud.cn/docs/server.html#移除聊天室白名单成员_方法
|
88
90
|
def remove_chatroom_whitelist(chatroom_id, user_id)
|
89
91
|
request("/chatroom/user/whitelist/remove", chatroomId: chatroom_id, userId: user_id)
|
90
92
|
end
|
91
93
|
|
92
|
-
#
|
94
|
+
# http://www.rongcloud.cn/docs/server.html#查询聊天室白名单成员_方法
|
93
95
|
def whitelisted_chatroom_users(chatroom_id)
|
94
96
|
request("/chatroom/user/whitelist/query", chatroomId: chatroom_id)
|
95
97
|
end
|
@@ -1,12 +1,7 @@
|
|
1
1
|
module RongCloud
|
2
2
|
module Services
|
3
|
-
#
|
3
|
+
# http://www.rongcloud.cn/docs/server.html#群组服务
|
4
4
|
module Group
|
5
|
-
# 同步用户所属群组
|
6
|
-
#
|
7
|
-
# @param user_id [String] 用户在融云的 id
|
8
|
-
# @param groups [Hash] 用户需要同步的群组信息,以群组 id 为键,以群组名称为值
|
9
|
-
#
|
10
5
|
def sync_group(user_id, groups)
|
11
6
|
params = {userId: user_id}
|
12
7
|
groups.each do |id, name|
|
@@ -16,55 +11,38 @@ module RongCloud
|
|
16
11
|
request("/group/sync", params)
|
17
12
|
end
|
18
13
|
|
19
|
-
# 创建群组
|
20
|
-
#
|
21
14
|
def create_group(user_id, group_id, group_name)
|
22
15
|
request("/group/create", userId: user_id, groupId: group_id, groupName: group_name)
|
23
16
|
end
|
24
17
|
|
25
|
-
# 加入群组
|
26
|
-
#
|
27
18
|
def join_group(user_id, group_id, group_name)
|
28
19
|
request("/group/join", userId: user_id, groupId: group_id, groupName: group_name)
|
29
20
|
end
|
30
21
|
|
31
|
-
# 退出群组
|
32
|
-
#
|
33
22
|
def quit_group(user_id, group_id)
|
34
23
|
request("/group/quit", userId: user_id, groupId: group_id)
|
35
24
|
end
|
36
25
|
|
37
|
-
# 解散群组
|
38
|
-
#
|
39
26
|
def dismiss_group(user_id, group_id)
|
40
27
|
request("/group/dismiss", userId: user_id, groupId: group_id)
|
41
28
|
end
|
42
29
|
|
43
|
-
# 刷新群组信息
|
44
30
|
def refresh_group(group_id, group_name)
|
45
31
|
request("/group/refresh", groupId: group_id, groupName: group_name)
|
46
32
|
end
|
47
33
|
|
48
|
-
# 查询群成员
|
49
|
-
#
|
50
34
|
def group_members(group_id)
|
51
35
|
request("/group/user/query", groupId: group_id)
|
52
36
|
end
|
53
37
|
|
54
|
-
# 添加禁言群成员
|
55
|
-
#
|
56
38
|
def block_group_member(user_id, group_id, minute)
|
57
39
|
request("/group/user/gag/add", userId: user_id, groupId: group_id, minute: minute)
|
58
40
|
end
|
59
41
|
|
60
|
-
# 移除禁言群成员
|
61
|
-
#
|
62
42
|
def unblock_group_member(user_id, group_id)
|
63
43
|
request("/group/user/gag/rollback", userId: user_id, groupId: group_id)
|
64
44
|
end
|
65
45
|
|
66
|
-
# 查询被禁言群成员
|
67
|
-
#
|
68
46
|
def blocked_group_members(group_id)
|
69
47
|
request("/group/user/gag/list", groupId: group_id)
|
70
48
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RongCloud
|
2
|
+
module Services
|
3
|
+
# http://www.rongcloud.cn/docs/server.html#消息历史记录服务
|
4
|
+
module HistoryMessage
|
5
|
+
# Get the download url for history messages within specified hour
|
6
|
+
#
|
7
|
+
# @param date [String] the date and hour represented in format "YYYYmmddHH"
|
8
|
+
#
|
9
|
+
def get_history(date)
|
10
|
+
request "/message/history", { date: date }
|
11
|
+
end
|
12
|
+
|
13
|
+
# Delete all history message whithin specified date and hour
|
14
|
+
#
|
15
|
+
# @param date [String] the date and hour represented in format "YYYYmmddHH"
|
16
|
+
#
|
17
|
+
def delete_history(date)
|
18
|
+
request "/message/history/delete", { date: date }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,20 +2,25 @@ require 'rong_cloud/services/message/message_channel'
|
|
2
2
|
|
3
3
|
module RongCloud
|
4
4
|
module Services
|
5
|
-
#
|
5
|
+
# http://www.rongcloud.cn/docs/server.html#消息发送服务
|
6
6
|
module Message
|
7
|
-
#
|
8
|
-
# @param from_user_id [String]
|
9
|
-
# @param target_id [String, Integer]
|
10
|
-
#
|
11
|
-
# @param
|
12
|
-
# @param [
|
13
|
-
# @
|
14
|
-
# @option content [Object] :
|
15
|
-
# @
|
16
|
-
#
|
17
|
-
# @
|
18
|
-
#
|
7
|
+
# General method to send messages
|
8
|
+
# @param from_user_id [String] sender id
|
9
|
+
# @param target_id [String, Integer] receiver id,might be a user id,
|
10
|
+
# group id, discussion group id or chatroom id
|
11
|
+
# @param channel_name [String] the message channel
|
12
|
+
# @param object_name [String] message type name, could be built-in or custome names
|
13
|
+
# @param [Hash] content Message object,view http://www.rongcloud.cn/docs/server.html#内置消息类型表 to learn more
|
14
|
+
# @option content [Object] :content the body of message
|
15
|
+
# @option content [Object] :extra the extras of message,passed as a string
|
16
|
+
# and should be parsed by the message consumer
|
17
|
+
# @param args [Array] additional params,when it includes only one param,
|
18
|
+
# the args is a options; when 2 params, the first one is the `values` of
|
19
|
+
# a template message, the the last one is a options
|
20
|
+
# @param [Hash] options options includes pushContent and pushData and so on,
|
21
|
+
# total supported options determined by the message type
|
22
|
+
# @option options [String] :pushContent push content
|
23
|
+
# @option options [Hash] :pushData push data as payload
|
19
24
|
#
|
20
25
|
def send_message(from_user_id, target_id, channel_name, object_name, content, *args)
|
21
26
|
options = args.extract_options!
|
@@ -38,38 +43,30 @@ module RongCloud
|
|
38
43
|
request(message_channel.api_path, params, content_type)
|
39
44
|
end
|
40
45
|
|
41
|
-
# 发送单聊消息 http://www.rongcloud.cn/docs/server.html#发送单聊消息_方法
|
42
|
-
#
|
43
46
|
def send_private_message(from_user_id, to_user_id, object_name, content, options = {})
|
44
47
|
send_message(from_user_id, to_user_id, :private, object_name, content, options)
|
45
48
|
end
|
46
49
|
|
47
|
-
# 发送单聊模板消息 http://www.rongcloud.cn/docs/server.html#发送单聊模板消息_方法
|
48
50
|
def send_private_template_message(from_user_id, to_user_id, object_name, content, values, options = {})
|
49
51
|
send_message(from_user_id, to_user_id, :private_template, object_name, content, values, options)
|
50
52
|
end
|
51
53
|
|
52
|
-
# 发送系统消息 http://www.rongcloud.cn/docs/server.html#发送系统消息_方法
|
53
54
|
def send_system_message(from_user_id, to_user_id, object_name, content, options = {})
|
54
55
|
send_message(from_user_id, to_user_id, :system, object_name, content, options)
|
55
56
|
end
|
56
57
|
|
57
|
-
# 发送系统模板消息 http://www.rongcloud.cn/docs/server.html#发送系统模板消息_方法
|
58
58
|
def send_system_template_message(from_user_id, to_user_id, object_name, content, values, options = {})
|
59
59
|
send_message(from_user_id, to_user_id, :system_template, object_name, content, values, options)
|
60
60
|
end
|
61
61
|
|
62
|
-
# 发送群组消息 http://www.rongcloud.cn/docs/server.html#发送群组消息_方法
|
63
62
|
def send_group_message(from_user_id, to_group_id, object_name, content, options = {})
|
64
63
|
send_message(from_user_id, to_group_id, :group, object_name, content, options)
|
65
64
|
end
|
66
65
|
|
67
|
-
# 发送讨论组消息 http://www.rongcloud.cn/docs/server.html#发送讨论组消息_方法
|
68
66
|
def send_discussion_message(from_user_id, to_discussion_id, object_name, content, options = {})
|
69
67
|
send_message(from_user_id, to_discussion_id, :discussion, object_name, content, options)
|
70
68
|
end
|
71
69
|
|
72
|
-
# 发送广播消息 http://www.rongcloud.cn/docs/server.html#发送广播消息_方法
|
73
70
|
def send_broadcast_message(from_user_id, object_name, content, options = {})
|
74
71
|
send_message(from_user_id, nil, :broadcast, object_name, content, options)
|
75
72
|
end
|
@@ -1,20 +1,18 @@
|
|
1
1
|
module RongCloud
|
2
2
|
module Services
|
3
|
-
#
|
3
|
+
# http://www.rongcloud.cn/docs/server.html#用户服务
|
4
4
|
module User
|
5
|
-
#
|
5
|
+
# Generate a new token to create a new RongCloud user
|
6
6
|
#
|
7
|
-
# @param user_id [String]
|
8
|
-
# @param name [String]
|
9
|
-
# @param portrait_uri [String]
|
10
|
-
# @return [Hash]
|
7
|
+
# @param user_id [String] user id
|
8
|
+
# @param name [String] user name
|
9
|
+
# @param portrait_uri [String] the url of user's avatar
|
10
|
+
# @return [Hash] the response data
|
11
11
|
#
|
12
12
|
def get_token(user_id, name, portrait_uri)
|
13
13
|
request("/user/getToken", {userId: user_id, name: name, portraitUri: portrait_uri})
|
14
14
|
end
|
15
15
|
|
16
|
-
# 刷新用户信息
|
17
|
-
#
|
18
16
|
def refresh_user(user_id, name = nil, portrait_uri = nil)
|
19
17
|
params = { userId: user_id, name: name, portraitUri: portrait_uri }
|
20
18
|
params.reject!{|key, value| value.nil?}
|
@@ -22,46 +20,30 @@ module RongCloud
|
|
22
20
|
request("/user/refresh", params)
|
23
21
|
end
|
24
22
|
|
25
|
-
# 检查用户在线状态
|
26
|
-
#
|
27
23
|
def check_online(user_id)
|
28
24
|
request("/user/checkOnline", { userId: user_id })
|
29
25
|
end
|
30
26
|
|
31
|
-
# 封禁用户
|
32
|
-
# @param user_id [String] 用户在融云的用户 id
|
33
|
-
# @param minute [Integer] 封禁时长
|
34
|
-
#
|
35
27
|
def block_user(user_id, minute)
|
36
28
|
request("/user/block", { userId: user_id, minute: minute })
|
37
29
|
end
|
38
30
|
|
39
|
-
# 解除用户封禁
|
40
|
-
#
|
41
31
|
def unblock_user(user_id)
|
42
32
|
request("/user/unblock", userId: user_id)
|
43
33
|
end
|
44
34
|
|
45
|
-
# 查询被封禁用户列表
|
46
|
-
#
|
47
35
|
def blocked_users
|
48
36
|
request("/user/block/query")
|
49
37
|
end
|
50
38
|
|
51
|
-
# 添加用户到黑名单
|
52
|
-
#
|
53
39
|
def blacklist_add(user_id, black_user_id)
|
54
40
|
request("/user/blacklist/add", userId: user_id, blackUserId: black_user_id)
|
55
41
|
end
|
56
42
|
|
57
|
-
# 从黑名单中移除用户
|
58
|
-
#
|
59
43
|
def blacklist_remove(user_id, black_user_id)
|
60
44
|
request("/user/blacklist/remove", userId: user_id, blackUserId: black_user_id)
|
61
45
|
end
|
62
46
|
|
63
|
-
# 获取某用户的黑名单列表
|
64
|
-
#
|
65
47
|
def blacklisted_users(user_id)
|
66
48
|
request("/user/blacklist/query", userId: user_id)
|
67
49
|
end
|
@@ -1,23 +1,15 @@
|
|
1
1
|
module RongCloud
|
2
2
|
module Services
|
3
|
-
#
|
3
|
+
# http://www.rongcloud.cn/docs/server.html#敏感词服务
|
4
4
|
module Wordfilter
|
5
|
-
# 添加敏感词
|
6
|
-
#
|
7
|
-
# @param word [String] 敏感词
|
8
|
-
#
|
9
5
|
def add_wordfilter(word)
|
10
6
|
request("/wordfilter/add", { word: word })
|
11
7
|
end
|
12
8
|
|
13
|
-
# 移除敏感词
|
14
|
-
#
|
15
9
|
def delete_wordfilter(word)
|
16
10
|
request("/wordfilter/delete", { word: word })
|
17
11
|
end
|
18
12
|
|
19
|
-
# 查询已有敏感词的列表
|
20
|
-
#
|
21
13
|
def wordfilter_list
|
22
14
|
request("/wordfilter/list")
|
23
15
|
end
|
data/lib/rong_cloud/signature.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'digest/sha1'
|
2
2
|
|
3
3
|
module RongCloud
|
4
|
-
#
|
4
|
+
# a seperate module to perform api signature
|
5
5
|
# http://www.rongcloud.cn/docs/server.html#通用_API_接口签名规则
|
6
6
|
#
|
7
7
|
module Signature
|
8
|
-
#
|
8
|
+
# generate the final signature
|
9
9
|
#
|
10
|
-
# @param nonce [String]
|
11
|
-
# @param timestamp [String]
|
12
|
-
# @return [String]
|
10
|
+
# @param nonce [String] a random string with a whatever length
|
11
|
+
# @param timestamp [String] timestamp, the elapsed seconds from 1970-01-01 00:00:00 UTC
|
12
|
+
# @return [String] the final signature
|
13
13
|
#
|
14
14
|
def signature(nonce, timestamp)
|
15
15
|
str = "#{RongCloud::Configuration.app_secret}#{nonce}#{timestamp}"
|
16
16
|
Digest::SHA1.hexdigest(str)
|
17
17
|
end
|
18
18
|
|
19
|
-
#
|
20
|
-
# @note
|
19
|
+
# get required request headers
|
20
|
+
# @note consist of the following request headers:
|
21
21
|
# App-Key
|
22
22
|
# Nonce
|
23
23
|
# Timestamp
|
24
24
|
# Signature
|
25
|
-
# @return [Hash]
|
25
|
+
# @return [Hash] headers represented as a Ruby hash
|
26
26
|
def signed_headers
|
27
27
|
nonce = rand(10**6)
|
28
28
|
timestamp = Time.now.to_i
|
data/rong_cloud.gemspec
CHANGED
@@ -2,9 +2,9 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'rong_cloud_server'
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.require_path = 'lib'
|
5
|
-
s.summary = '
|
6
|
-
s.description = '
|
7
|
-
s.version = '0.0
|
5
|
+
s.summary = 'RongCloud Server API SDK'
|
6
|
+
s.description = 'RongCloud Server API in Ruby,http://www.rongcloud.cn/docs/server.html'
|
7
|
+
s.version = '0.1.0'
|
8
8
|
s.files = `git ls-files`.split("\n")
|
9
9
|
s.authors = ['Martin Hong']
|
10
10
|
s.email = 'hongzeqin@gmail.com'
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
1
3
|
module RongCloud
|
2
4
|
module Services
|
3
|
-
|
5
|
+
class ChatroomTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
4
8
|
def test_create_chatroom
|
5
9
|
chatrooms = { 10001 => "name1", 10002 => "name2" }
|
6
10
|
response = @service.create_chatroom(chatrooms)
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
1
3
|
module RongCloud
|
2
4
|
module Services
|
3
|
-
|
5
|
+
class GroupTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
4
8
|
def test_sync_group
|
5
9
|
response = @service.sync_group('user1', '1' => 'group1', '2' => 'group2')
|
6
10
|
assert_equal 200, response['code']
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
3
|
+
module RongCloud
|
4
|
+
module Services
|
5
|
+
class HistoryMessageTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
8
|
+
def test_get_history
|
9
|
+
date = "2014010101"
|
10
|
+
response = @service.get_history(date)
|
11
|
+
assert_equal 200, response['code']
|
12
|
+
assert_equal date, response['date']
|
13
|
+
assert_includes response, 'url'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_delete_history
|
17
|
+
date = "2014010101"
|
18
|
+
response = @service.delete_history(date)
|
19
|
+
assert_equal 200, response['code']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
1
3
|
module RongCloud
|
2
4
|
module Services
|
3
|
-
|
5
|
+
class MessageTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
4
8
|
def test_send_private_message_with_single_to_user_id
|
5
9
|
response = @service.send_private_message(1, 2, "RC:TxtMsg", { content: "hello world", extra: "nothing" })
|
6
10
|
assert_equal 200, response["code"]
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
1
3
|
module RongCloud
|
2
4
|
module Services
|
3
|
-
|
5
|
+
class UserTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
4
8
|
def test_get_token_without_user_id
|
5
9
|
error = assert_raises RongCloud::BadRequest do
|
6
10
|
@service.get_token(nil, nil, nil)
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require 'rong_cloud/service_test_setup'
|
2
|
+
|
1
3
|
module RongCloud
|
2
4
|
module Services
|
3
|
-
|
5
|
+
class WordfilterTest < Minitest::Test
|
6
|
+
include RongCloud::ServiceTestSetup
|
7
|
+
|
4
8
|
def test_add_wordfilter_with_single_word
|
5
9
|
response = @service.add_wordfilter("敏感词")
|
6
10
|
assert_equal 200, response["code"]
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rong_cloud_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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: 2017-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: RongCloud Server API in Ruby,http://www.rongcloud.cn/docs/server.html
|
14
14
|
email: hongzeqin@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -18,6 +18,7 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- ".gitignore"
|
20
20
|
- README.md
|
21
|
+
- README.zh-CN.md
|
21
22
|
- config.example.yml
|
22
23
|
- lib/core_ext/array.rb
|
23
24
|
- lib/rong_cloud.rb
|
@@ -27,6 +28,7 @@ files:
|
|
27
28
|
- lib/rong_cloud/service.rb
|
28
29
|
- lib/rong_cloud/services/chatroom.rb
|
29
30
|
- lib/rong_cloud/services/group.rb
|
31
|
+
- lib/rong_cloud/services/history_message.rb
|
30
32
|
- lib/rong_cloud/services/message.rb
|
31
33
|
- lib/rong_cloud/services/message/message_channel.rb
|
32
34
|
- lib/rong_cloud/services/user.rb
|
@@ -36,9 +38,10 @@ files:
|
|
36
38
|
- run_tests.sh
|
37
39
|
- test/rong_cloud/configuration_test.rb
|
38
40
|
- test/rong_cloud/request_test.rb
|
39
|
-
- test/rong_cloud/
|
41
|
+
- test/rong_cloud/service_test_setup.rb
|
40
42
|
- test/rong_cloud/services/chatroom_test.rb
|
41
43
|
- test/rong_cloud/services/group_test.rb
|
44
|
+
- test/rong_cloud/services/history_message_test.rb
|
42
45
|
- test/rong_cloud/services/message/message_channel_test.rb
|
43
46
|
- test/rong_cloud/services/message_test.rb
|
44
47
|
- test/rong_cloud/services/user_test.rb
|
@@ -69,5 +72,5 @@ rubyforge_project:
|
|
69
72
|
rubygems_version: 2.6.6
|
70
73
|
signing_key:
|
71
74
|
specification_version: 4
|
72
|
-
summary:
|
75
|
+
summary: RongCloud Server API SDK
|
73
76
|
test_files: []
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rong_cloud/services/user_test'
|
3
|
-
require 'rong_cloud/services/message_test'
|
4
|
-
require 'rong_cloud/services/wordfilter_test'
|
5
|
-
require 'rong_cloud/services/group_test'
|
6
|
-
require 'rong_cloud/services/chatroom_test'
|
7
|
-
|
8
|
-
module RongCloud
|
9
|
-
class ServiceTest < Minitest::Test
|
10
|
-
include RongCloud::Services::UserTest
|
11
|
-
include RongCloud::Services::MessageTest
|
12
|
-
include RongCloud::Services::WordfilterTest
|
13
|
-
include RongCloud::Services::GroupTest
|
14
|
-
include RongCloud::Services::ChatroomTest
|
15
|
-
|
16
|
-
def setup
|
17
|
-
rong_cloud_configure_with_settings
|
18
|
-
@service = RongCloud::Service.new
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|