class Rongyun::Client
Constants
- ACTION_CHATROOM_CREATE
- ACTION_CHATROOM_DESTROY
- ACTION_CHATROOM_QUERY
- ACTION_GROUP_CREATE
- ACTION_GROUP_DISMISS
- ACTION_GROUP_JOIN
- ACTION_GROUP_QUIT
- ACTION_GROUP_REFRESH
- ACTION_GROUP_SYNC
- ACTION_GROUP_USER_GAG_ADD
- ACTION_GROUP_USER_GAG_LIST
- ACTION_GROUP_USER_GAG_ROLLBACK
- ACTION_GROUP_USER_QUERY
- ACTION_MESSAGE_BROADCAST
- ACTION_MESSAGE_CHATROOM_PUBLISH
- ACTION_MESSAGE_GROUP_PUBLISH
- ACTION_MESSAGE_HISTORY
- ACTION_MESSAGE_HISTORY_DELETE
- ACTION_MESSAGE_PUBLISH
- ACTION_MESSAGE_SYSTEM_PUBLISH
- ACTION_PUSH
- ACTION_USER_BLACKLIST_ADD
- ACTION_USER_BLACKLIST_REMOVE
- ACTION_USER_BLOCK
- ACTION_USER_BLOCK_QUERY
- ACTION_USER_CHECKONLINE
- ACTION_USER_REFRESH
- ACTION_USER_TAG_SET
- ACTION_USER_TOKEN
- ACTION_USER_UNBLOCK
- ACTION_WORDFILTER_ADD
- ACTION_WORDFILTER_DELETE
- ACTION_WORDFILTER_LIST
Public Class Methods
new(app_key = nil, app_secret = nil, verify = true)
click to toggle source
# File lib/rongyun.rb, line 50 def initialize(app_key = nil, app_secret = nil, verify = true) @version = 1.0 @api_host = 'https://api.cn.rong.io' @response_type = 'json' @user_agent = "RongCloudSdk/RongCloud-Ruby-Sdk #{RUBY_VERSION} (#{@version})" @app_key = app_key || ENV['rongcloud_app_key'] @app_secret = app_secret || ENV['rongcloud_app_secret'] @verify = verify end
Public Instance Methods
add_blacklist(user_id, black_user_id)
click to toggle source
# File lib/rongyun.rb, line 125 def add_blacklist(user_id, black_user_id) post( ACTION_USER_BLACKLIST_ADD, { userId: user_id, blackUserId: black_user_id } ) post( ACTION_USER_BLACKLIST_ADD, { userId: black_user_id, blackUserId: user_id } ) end
add_wordfilter(word)
click to toggle source
# File lib/rongyun.rb, line 151 def add_wordfilter(word) post( ACTION_WORDFILTER_ADD, { word: word } ) end
body(content_type, data)
click to toggle source
# File lib/rongyun.rb, line 101 def body(content_type, data) content_type == 'application/x-www-form-urlencoded' ? URI.encode_www_form(data) : data.to_json end
chatroom_create(chatrooms)
click to toggle source
# File lib/rongyun.rb, line 276 def chatroom_create(chatrooms) chatrooms.each { |k, v| chatroom_mapping["charoom[#{k}]"] = v } post( ACTION_CHATROOM_CREATE, chatroom_mapping ) end
chatroom_destroy(chatroom_id_list = nil)
click to toggle source
# File lib/rongyun.rb, line 281 def chatroom_destroy(chatroom_id_list = nil) post( ACTION_CHATROOM_DESTROY, { chatroomId: chatroom_id_list.to_a } ) end
chatroom_query(chatroom_id_list = nil)
click to toggle source
# File lib/rongyun.rb, line 285 def chatroom_query(chatroom_id_list = nil) post( ACTION_CHATROOM_QUERY, { chatroomId: chatroom_id_list.to_a } ) end
delete_wordfilter(word)
click to toggle source
# File lib/rongyun.rb, line 155 def delete_wordfilter(word) post( ACTION_WORDFILTER_DELETE, { word: word } ) end
group_create(user_ids, group_id, group_name)
click to toggle source
# File lib/rongyun.rb, line 240 def group_create(user_ids, group_id, group_name) post( ACTION_GROUP_CREATE, { userId: user_ids, groupId: group_id, groupName: group_name } ) end
group_dismiss(user_id, group_id)
click to toggle source
# File lib/rongyun.rb, line 264 def group_dismiss(user_id, group_id) post( ACTION_GROUP_DISMISS, { userId: user_id, groupId: group_id } ) end
group_join(user_ids, group_id, group_name)
click to toggle source
# File lib/rongyun.rb, line 250 def group_join(user_ids, group_id, group_name) post( ACTION_GROUP_JOIN, { userId: user_ids, groupId: group_id, groupName: group_name } ) end
group_quit(user_ids, group_id)
click to toggle source
# File lib/rongyun.rb, line 260 def group_quit(user_ids, group_id) post( ACTION_GROUP_QUIT, { userId: user_ids, groupId: group_id } ) end
group_refresh(group_id, group_name)
click to toggle source
# File lib/rongyun.rb, line 268 def group_refresh(group_id, group_name) post( ACTION_GROUP_REFRESH, { groupId: group_id, groupName: group_name } ) end
group_sync(user_id, groups)
click to toggle source
# File lib/rongyun.rb, line 233 def group_sync(user_id, groups) groups.each { |k, v| group_mapping["group[#{k}]"] = v } group_mapping[:userId] = user_id post( ACTION_GROUP_SYNC, group_mapping ) end
group_user_gag_add(user_ids, group_id, minute = 120)
click to toggle source
# File lib/rongyun.rb, line 289 def group_user_gag_add(user_ids, group_id, minute = 120) post( ACTION_GROUP_USER_GAG_ADD, { userId: user_ids, groupId: group_id, minute: minute.to_i } ) end
group_user_gag_list(group_id)
click to toggle source
# File lib/rongyun.rb, line 297 def group_user_gag_list(group_id) post( ACTION_GROUP_USER_GAG_LIST, { groupId: group_id } ) end
group_user_gag_rollback(user_ids, group_id)
click to toggle source
# File lib/rongyun.rb, line 293 def group_user_gag_rollback(user_ids, group_id) post( ACTION_GROUP_USER_GAG_ROLLBACK, { userId: user_ids, groupId: group_id } ) end
group_user_query(group_id)
click to toggle source
# File lib/rongyun.rb, line 272 def group_user_query(group_id) post( ACTION_GROUP_USER_QUERY, { groupId: group_id } ) end
headers(content_type='application/x-www-form-urlencoded')
click to toggle source
# File lib/rongyun.rb, line 74 def headers(content_type='application/x-www-form-urlencoded') header = { 'content-type' => content_type, 'user-agent' => @user_agent} header.merge!(make_signature) end
http_call(url, headers, data)
click to toggle source
# File lib/rongyun.rb, line 80 def http_call(url, headers, data) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') # enable SSL/TLS http.ssl_version = :TLSv1 http.ciphers = ['RC4-SHA'] http.verify_mode = OpenSSL::SSL::VERIFY_NONE # 这个也很重要 req = Net::HTTP::Post.new(uri.path, initheader = headers) req.body = body(headers['content-type'], data) res = http.request(req) response_object(JSON.parse(res.body)) end
make_signature()
click to toggle source
# File lib/rongyun.rb, line 61 def make_signature nonce = "#{Random.new(Time.now.to_i).rand(100000000000000)}" timestamp = "#{Time.now.to_i}" signature = Digest::SHA1.hexdigest(@app_secret + nonce + timestamp) { 'app-key' => @app_key, 'nonce' => nonce, 'timestamp' => timestamp, 'signature' => signature } end
message_broadcast(from_user_id, object_name, content, push_content, push_data, os)
click to toggle source
# File lib/rongyun.rb, line 212 def message_broadcast(from_user_id, object_name, content, push_content, push_data, os) post( ACTION_MESSAGE_BROADCAST, { fromUserId: from_user_id, objectName: object_name, content: content, pushContent: push_content, pushData: push_data, os: os } ) end
message_chatroom_publish(from_user_id, to_chatroom_id, object_name, content)
click to toggle source
# File lib/rongyun.rb, line 202 def message_chatroom_publish(from_user_id, to_chatroom_id, object_name, content) post( ACTION_MESSAGE_CHATROOM_PUBLISH, { fromUserId: from_user_id, toGroupId: to_chatroom_id, objectName: object_name, content: content } ) end
message_group_publish(from_user_id, to_group_id, object_name, content, push_content, push_data)
click to toggle source
# File lib/rongyun.rb, line 189 def message_group_publish(from_user_id, to_group_id, object_name, content, push_content, push_data) post( ACTION_MESSAGE_GROUP_PUBLISH, { fromUserId: from_user_id, toGroupId: to_group_id, objectName: object_name, content: content, pushContent: push_content.to_s, pushData: push_data.to_s } ) end
message_history(date)
click to toggle source
# File lib/rongyun.rb, line 229 def message_history(date) post( ACTION_MESSAGE_HISTORY, { date: date } ) end
message_history_delete(date)
click to toggle source
# File lib/rongyun.rb, line 225 def message_history_delete(date) post( ACTION_MESSAGE_HISTORY_DELETE, { date: date } ) end
message_publish(from_user_id, to_user_id, object_name, content, push_content, push_data)
click to toggle source
# File lib/rongyun.rb, line 163 def message_publish(from_user_id, to_user_id, object_name, content, push_content, push_data) post( ACTION_MESSAGE_PUBLISH, { fromUserId: from_user_id, toUserId: to_user_id, objectName: object_name, content: content, pushContent: push_content.to_s, pushData: push_data.to_s } ) end
message_system_publish(from_user_id, to_user_id, object_name, content, push_content, push_data)
click to toggle source
# File lib/rongyun.rb, line 176 def message_system_publish(from_user_id, to_user_id, object_name, content, push_content, push_data) post( ACTION_MESSAGE_SYSTEM_PUBLISH, { fromUserId: from_user_id, toUserId: to_user_id, objectName: object_name, content: content, pushContent: push_content.to_s, pushData: push_data.to_s } ) end
post(action, params = nil)
click to toggle source
# File lib/rongyun.rb, line 105 def post(action, params = nil) http_call(@api_host + action + "." + @response_type, headers, params) end
post_json(action, params = nil)
click to toggle source
# File lib/rongyun.rb, line 109 def post_json(action, params = nil) http_call(@api_host + action + "." + @response_type, headers('application/json'), params) end
push(platform, audience, notification)
click to toggle source
# File lib/rongyun.rb, line 301 def push(platform, audience, notification) post_json( ACTION_PUSH, { platform: platform, audience: audience, notification: notification } ) end
remove_blacklist(user_id, black_user_id)
click to toggle source
# File lib/rongyun.rb, line 130 def remove_blacklist(user_id, black_user_id) post( ACTION_USER_BLACKLIST_REMOVE, { userId: user_id, blackUserId: black_user_id } ) post( ACTION_USER_BLACKLIST_REMOVE, { userId: black_user_id, blackUserId: user_id } ) end
response_object(body)
click to toggle source
# File lib/rongyun.rb, line 94 def response_object(body) response = Struct.new(:success, :data).new response.success = body['code'] == 200 response.data = body response end
user_block(user_id, minute = 10)
click to toggle source
# File lib/rongyun.rb, line 135 def user_block(user_id, minute = 10) post( ACTION_USER_BLOCK, { userId: user_id } ) end
user_block_query()
click to toggle source
# File lib/rongyun.rb, line 143 def user_block_query post( ACTION_USER_BLOCK_QUERY ) end
user_check_online(user_id)
click to toggle source
# File lib/rongyun.rb, line 121 def user_check_online(user_id) post( ACTION_USER_CHECKONLINE, { userId: user_id } ) end
user_get_token(user_id, name, portrait_uri)
click to toggle source
# File lib/rongyun.rb, line 113 def user_get_token(user_id, name, portrait_uri) post( ACTION_USER_TOKEN, { userId: user_id, name: name, portraitUri: portrait_uri } ) end
user_refresh(user_id, name, portrait_uri)
click to toggle source
# File lib/rongyun.rb, line 117 def user_refresh(user_id, name, portrait_uri) post( ACTION_USER_REFRESH, { userId: user_id, name: name, portraitUri: portrait_uri } ) end
user_tag_set(user_id, tags)
click to toggle source
# File lib/rongyun.rb, line 147 def user_tag_set(user_id, tags) post_json( ACTION_USER_TAG_SET, { userId: user_id, tags: tags } ) end
user_unblock(user_id)
click to toggle source
# File lib/rongyun.rb, line 139 def user_unblock(user_id) post( ACTION_USER_UNBLOCK, { userId: user_id } ) end
wordfilter_list(word)
click to toggle source
# File lib/rongyun.rb, line 159 def wordfilter_list(word) post( ACTION_WORDFILTER_LIST ) end