rongyun 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9b7536793a821f80a0ec5680906ae10ae6e3349
4
+ data.tar.gz: d4e171594c36ce5e87d0498565dc3ae85b701e2b
5
+ SHA512:
6
+ metadata.gz: 346f66168518a295cd201d5a18bb1b9f9f2c9ae9851104b597ecb30c02e1d68a898cc1920c5b8e77e64f1e2bbbd8c3054a435992805428644d8abb38c660a055
7
+ data.tar.gz: c97c4823a593a1d8f80f66cbea05047eb044096d8fcc76b33ba97a7fe0486b2d0a53fcdd99e14f4a43b3d72e2cefac6d7d04ad5b14a17b4c101e56e03cb4e32b
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rongyun.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Rongyun
2
+
3
+ * Rongyun Related Operation
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rongyun'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rongyun
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ client = Rongyun::Client.new
25
+ client.user_get_token(user_id, name, portrait_uri)
26
+ ...
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/yangxing-star/rongyun/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module Rongyun
2
+ VERSION = '1.1.0'
3
+ end
data/lib/rongyun.rb ADDED
@@ -0,0 +1,298 @@
1
+ require 'rongyun/version'
2
+
3
+ require 'digest/sha1'
4
+ require 'net/https'
5
+ require 'uri'
6
+ require 'json'
7
+
8
+ module Rongyun
9
+ class Client
10
+
11
+ ACTION_USER_TOKEN = '/user/getToken'
12
+ ACTION_USER_REFRESH = '/user/refresh'
13
+ ACTION_USER_BLOCK = '/user/block'
14
+ ACTION_USER_UNBLOCK = '/user/unblock'
15
+ ACTION_USER_BLOCK_QUERY = '/user/block/query'
16
+ ACTION_USER_CHECKONLINE = '/user/checkOnline'
17
+ ACTION_USER_BLACKLIST_ADD = '/user/blacklist/add'
18
+ ACTION_USER_BLACKLIST_REMOVE = '/user/blacklist/remove'
19
+ ACTION_USER_TAG_SET = '/user/tag/set'
20
+
21
+ ACTION_MESSAGE_PUBLISH = '/message/private/publish'
22
+ ACTION_MESSAGE_SYSTEM_PUBLISH = '/message/system/publish'
23
+ ACTION_MESSAGE_GROUP_PUBLISH = '/message/group/publish'
24
+ ACTION_MESSAGE_CHATROOM_PUBLISH = '/message/chatroom/publish'
25
+ ACTION_MESSAGE_BROADCAST = '/message/broadcast'
26
+ ACTION_MESSAGE_HISTORY = '/message/history'
27
+ ACTION_MESSAGE_HISTORY_DELETE = '/message/history/delete'
28
+
29
+ ACTION_GROUP_SYNC = '/group/sync'
30
+ ACTION_GROUP_CREATE = '/group/create'
31
+ ACTION_GROUP_JOIN = '/group/join'
32
+ ACTION_GROUP_QUIT = '/group/quit'
33
+ ACTION_GROUP_DISMISS = '/group/dismiss'
34
+ ACTION_GROUP_REFRESH = '/group/refresh'
35
+ ACTION_GROUP_USER_QUERY = '/group/user/query'
36
+ ACTION_GROUP_USER_GAG_ADD = '/group/user/gag/add'
37
+ ACTION_GROUP_USER_GAG_ROLLBACK = '/group/user/gag/rollback'
38
+ ACTION_GROUP_USER_GAG_LIST = '/group/user/gag/list'
39
+
40
+ ACTION_WORDFILTER_ADD = '/wordfilter/add'
41
+ ACTION_WORDFILTER_DELETE = '/wordfilter/delete'
42
+ ACTION_WORDFILTER_LIST = '/wordfilter/list'
43
+
44
+ ACTION_CHATROOM_CREATE = '/chatroom/create'
45
+ ACTION_CHATROOM_DESTROY = '/chatroom/destroy'
46
+ ACTION_CHATROOM_QUERY = '/chatroom/query'
47
+
48
+ ACTION_PUSH = '/push'
49
+
50
+ def initialize(app_key = nil, app_secret = nil, verify = true)
51
+ @version = 1.0
52
+ @api_host = 'https://api.cn.rong.io'
53
+ @response_type = 'json'
54
+ @user_agent = "RongCloudSdk/RongCloud-Ruby-Sdk #{RUBY_VERSION} (#{@version})"
55
+
56
+ @app_key = app_key || ENV['rongcloud_app_key']
57
+ @app_secret = app_secret || ENV['rongcloud_app_secret']
58
+ @verify = verify
59
+ end
60
+
61
+ def make_signature
62
+ nonce = "#{Random.new(Time.now.to_i).rand(100000000000000)}"
63
+ timestamp = "#{Time.now.to_i}"
64
+ signature = Digest::SHA1.hexdigest(@app_secret + nonce + timestamp)
65
+
66
+ {
67
+ 'app-key' => @app_key,
68
+ 'nonce' => nonce,
69
+ 'timestamp' => timestamp,
70
+ 'signature' => signature
71
+ }
72
+ end
73
+
74
+ def headers(content_type='application/x-www-form-urlencoded')
75
+ header = { 'content-type' => content_type,
76
+ 'user-agent' => @user_agent}
77
+ header.merge!(make_signature)
78
+ end
79
+
80
+ def http_call(url, headers, data)
81
+ uri = URI.parse(url)
82
+ http = Net::HTTP.new(uri.host, uri.port)
83
+ http.use_ssl = (uri.scheme == 'https') # enable SSL/TLS
84
+ http.ssl_version = :TLSv1
85
+ http.ciphers = ['RC4-SHA']
86
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE # 这个也很重要
87
+
88
+ req = Net::HTTP::Post.new(uri.path, initheader = headers)
89
+ req.body = body(headers['content-type'], data)
90
+ res = http.request(req)
91
+ JSON.parse(res.body)
92
+ end
93
+
94
+ def body(content_type, data)
95
+ content_type == 'application/x-www-form-urlencoded' ? URI.encode_www_form(data) : data.to_json
96
+ end
97
+
98
+ def post(action, params = nil)
99
+ http_call(@api_host + action + "." + @response_type, headers, params)
100
+ end
101
+
102
+ def post_json(action, params = nil)
103
+ http_call(@api_host + action + "." + @response_type, headers('application/json'), params)
104
+ end
105
+
106
+ def user_get_token(user_id, name, portrait_uri)
107
+ post( ACTION_USER_TOKEN, { userId: user_id, name: name, portraitUri: portrait_uri } )
108
+ end
109
+
110
+ def user_refresh(user_id, name, portrait_uri)
111
+ post( ACTION_USER_REFRESH, { userId: user_id, name: name, portraitUri: portrait_uri } )
112
+ end
113
+
114
+ def user_check_online(user_id)
115
+ post( ACTION_USER_CHECKONLINE, { userId: user_id } )
116
+ end
117
+
118
+ def add_blacklist(user_id, black_user_id)
119
+ post( ACTION_USER_BLACKLIST_ADD, { userId: user_id, blackUserId: black_user_id } )
120
+ post( ACTION_USER_BLACKLIST_ADD, { userId: black_user_id, blackUserId: user_id } )
121
+ end
122
+
123
+ def remove_blacklist(user_id, black_user_id)
124
+ post( ACTION_USER_BLACKLIST_REMOVE, { userId: user_id, blackUserId: black_user_id } )
125
+ post( ACTION_USER_BLACKLIST_REMOVE, { userId: black_user_id, blackUserId: user_id } )
126
+ end
127
+
128
+ def user_block(user_id, minute = 10)
129
+ post( ACTION_USER_BLOCK, { userId: user_id } )
130
+ end
131
+
132
+ def user_unblock(user_id)
133
+ post( ACTION_USER_UNBLOCK, { userId: user_id } )
134
+ end
135
+
136
+ def user_block_query
137
+ post( ACTION_USER_BLOCK_QUERY )
138
+ end
139
+
140
+ def user_tag_set(user_id, tags)
141
+ post_json( ACTION_USER_TAG_SET, { userId: user_id, tags: tags } )
142
+ end
143
+
144
+ def add_wordfilter(word)
145
+ post( ACTION_WORDFILTER_ADD, { word: word } )
146
+ end
147
+
148
+ def delete_wordfilter(word)
149
+ post( ACTION_WORDFILTER_DELETE, { word: word } )
150
+ end
151
+
152
+ def wordfilter_list(word)
153
+ post( ACTION_WORDFILTER_LIST )
154
+ end
155
+
156
+ def message_publish(from_user_id, to_user_id, object_name, content, push_content, push_data)
157
+ post( ACTION_MESSAGE_PUBLISH,
158
+ {
159
+ fromUserId: from_user_id,
160
+ toUserId: to_user_id,
161
+ objectName: object_name,
162
+ content: content,
163
+ pushContent: push_content.to_s,
164
+ pushData: push_data.to_s
165
+ }
166
+ )
167
+ end
168
+
169
+ def message_system_publish(from_user_id, to_user_id, object_name, content, push_content, push_data)
170
+ post( ACTION_MESSAGE_SYSTEM_PUBLISH,
171
+ {
172
+ fromUserId: from_user_id,
173
+ toUserId: to_user_id,
174
+ objectName: object_name,
175
+ content: content,
176
+ pushContent: push_content.to_s,
177
+ pushData: push_data.to_s
178
+ }
179
+ )
180
+ end
181
+
182
+ def message_group_publish(from_user_id, to_group_id, object_name, content, push_content, push_data)
183
+ post( ACTION_MESSAGE_GROUP_PUBLISH,
184
+ {
185
+ fromUserId: from_user_id,
186
+ toGroupId: to_group_id,
187
+ objectName: object_name,
188
+ content: content,
189
+ pushContent: push_content.to_s,
190
+ pushData: push_data.to_s
191
+ }
192
+ )
193
+ end
194
+
195
+ def message_chatroom_publish(from_user_id, to_chatroom_id, object_name, content)
196
+ post( ACTION_MESSAGE_CHATROOM_PUBLISH,
197
+ { fromUserId: from_user_id,
198
+ toGroupId: to_chatroom_id,
199
+ objectName: object_name,
200
+ content: content
201
+ }
202
+ )
203
+ end
204
+
205
+ def message_broadcast(from_user_id, object_name, content, push_content, push_data, os)
206
+ post( ACTION_MESSAGE_BROADCAST,
207
+ {
208
+ fromUserId: from_user_id,
209
+ objectName: object_name,
210
+ content: content,
211
+ pushContent: push_content,
212
+ pushData: push_data,
213
+ os: os
214
+ }
215
+ )
216
+ end
217
+
218
+ def message_history_delete(date)
219
+ post( ACTION_MESSAGE_HISTORY_DELETE, { date: date } )
220
+ end
221
+
222
+ def message_history(date)
223
+ post( ACTION_MESSAGE_HISTORY, { date: date } )
224
+ end
225
+
226
+ def group_sync(user_id, groups)
227
+ groups.each { |k, v| group_mapping["group[#{k}]"] = v }
228
+ group_mapping[:userId] = user_id
229
+
230
+ post( ACTION_GROUP_SYNC, group_mapping )
231
+ end
232
+
233
+ def group_create(user_ids, group_id, group_name)
234
+ post( ACTION_GROUP_CREATE,
235
+ {
236
+ userId: user_ids,
237
+ groupId: group_id,
238
+ groupName: group_name
239
+ }
240
+ )
241
+ end
242
+
243
+ def group_join(user_ids, group_id, group_name)
244
+ post( ACTION_GROUP_JOIN,
245
+ {
246
+ userId: user_ids,
247
+ groupId: group_id,
248
+ groupName: group_name
249
+ }
250
+ )
251
+ end
252
+
253
+ def group_quit(user_ids, group_id)
254
+ post( ACTION_GROUP_QUIT, { userId: user_ids, groupId: group_id } )
255
+ end
256
+
257
+ def group_dismiss(user_id, group_id)
258
+ post( ACTION_GROUP_DISMISS, { userId: user_id, groupId: group_id } )
259
+ end
260
+
261
+ def group_refresh(group_id, group_name)
262
+ post( ACTION_GROUP_REFRESH, { groupId: group_id, groupName: group_name } )
263
+ end
264
+
265
+ def group_user_query(group_id)
266
+ post( ACTION_GROUP_USER_QUERY, { groupId: group_id } )
267
+ end
268
+
269
+ def chatroom_create(chatrooms)
270
+ chatrooms.each { |k, v| chatroom_mapping["charoom[#{k}]"] = v }
271
+ post( ACTION_CHATROOM_CREATE, chatroom_mapping )
272
+ end
273
+
274
+ def chatroom_destroy(chatroom_id_list = nil)
275
+ post( ACTION_CHATROOM_DESTROY, { chatroomId: chatroom_id_list.to_a } )
276
+ end
277
+
278
+ def chatroom_query(chatroom_id_list = nil)
279
+ post( ACTION_CHATROOM_QUERY, { chatroomId: chatroom_id_list.to_a } )
280
+ end
281
+
282
+ def group_user_gag_add(user_ids, group_id, minute = 120)
283
+ post( ACTION_GROUP_USER_GAG_ADD, { userId: user_ids, groupId: group_id, minute: minute.to_i } )
284
+ end
285
+
286
+ def group_user_gag_rollback(user_ids, group_id)
287
+ post( ACTION_GROUP_USER_GAG_ROLLBACK, { userId: user_ids, groupId: group_id } )
288
+ end
289
+
290
+ def group_user_gag_list(group_id)
291
+ post( ACTION_GROUP_USER_GAG_LIST, { groupId: group_id } )
292
+ end
293
+
294
+ def push(platform, audience, notification)
295
+ post_json( ACTION_PUSH, { platform: platform, audience: audience, notification: notification } )
296
+ end
297
+ end
298
+ end
data/rongyun.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rongyun/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rongyun'
7
+ spec.version = Rongyun::VERSION
8
+ spec.authors = ['Star']
9
+ spec.email = ['137379612@qq.com']
10
+ spec.summary = 'Rong Yun Server Api'
11
+ spec.description = 'Rong Yun Server Api'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+ require 'rongyun'
3
+
4
+ class RongyunTest < Test::Unit::TestCase
5
+ def test_make_signature
6
+ client = Rongyun::Client.new 'pvxdm17jx5eqr', 'T6Kb5lVqeLz'
7
+ result = client.make_signature
8
+ assert true
9
+ end
10
+
11
+ def test_user_get_token
12
+ client = Rongyun::Client.new 'pvxdm17jx5eqr', 'T6Kb5lVqeLz'
13
+ result = client.user_get_token('1', 'test', 'http://test/1')
14
+ assert_equal result['code'], 200
15
+ result = client.user_get_token('U:8d4f905dae5c198d4cfe9f951cfdb0eb', '', 'http://test/2')
16
+ assert_equal result['code'], 200
17
+ end
18
+
19
+ def test_message_publish
20
+ client = Rongyun::Client.new 'pvxdm17jx5eqr', 'T6Kb5lVqeLz'
21
+ result = client.message_publish('2', '1', 'RC:TxtMsg', '{'content':'hello','extra':'helloExtra'}')
22
+ assert_equal result['code'], 200
23
+
24
+ result = client.message_publish('2', ['1'], 'RC:TxtMsg', '{'content':'hello','extra':'helloExtra'}')
25
+ assert_equal result['code'], 200
26
+ end
27
+
28
+ def test_message_system_publish
29
+ client = Rongyun::Client.new 'pvxdm17jx5eqr', 'T6Kb5lVqeLz'
30
+ result = client.message_system_publish('2', '1', 'RC:TxtMsg', '{'content':'hello','extra':'helloExtra'}')
31
+ assert_equal result['code'], 200
32
+ result = client.message_system_publish('2', ['1', '2'], 'RC:TxtMsg', '{'content':'hello','extra':'helloExtra'}')
33
+ assert_equal result['code'], 200
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rongyun
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Star
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Rong Yun Server Api
42
+ email:
43
+ - 137379612@qq.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/rongyun.rb
54
+ - lib/rongyun/version.rb
55
+ - rongyun.gemspec
56
+ - test/test_rongyun.rb
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Rong Yun Server Api
81
+ test_files:
82
+ - test/test_rongyun.rb