rong_cloud_im 0.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: cc8cbc51f47ca4fc8a86f889a9feb624e782d000
4
+ data.tar.gz: b80dbe71d2a0f43a74ac5c6c6fee760b4c48792d
5
+ SHA512:
6
+ metadata.gz: d1e9f1cee7452fce6441a5b3e07b791670ac1d31ad2be70e4200959dc4f29e419c9be652f9da1c9c89bd0db93971d649511c488cdfa6219b90b59ac362d3d27d
7
+ data.tar.gz: b1d095c89916478e0c6433a3cec3f900a71c9dc7bb30ba57ae8791c9a04b45afca402a60756d791ca0a0a84af2e5b3e37e6715a7465ae2d2a2d8463c8d599cd3
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rong_cloud_im.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Fwshun8023
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,41 @@
1
+ # 融云IM
2
+
3
+ 融云IM Server API 调用
4
+ API文档 http://www.rongcloud.cn/docs/server.html
5
+
6
+ # 安装
7
+
8
+ 添加下面代码到Gemfile:
9
+ ```ruby
10
+ gem 'alipay', '~> 0.12.0'
11
+ ```
12
+
13
+ 然后执行:
14
+ ```console
15
+ $ bundle
16
+ ```
17
+
18
+ # 配置
19
+
20
+ ```ruby
21
+ RongCloudIM.app_key = 'YOUR APP KEY'
22
+ RongCloudIM.app_secret = 'YOUR APP SECRET'
23
+ # RongCloudIM.response_type = 'RESPONSE TYPE' # 可选,默认json。可选值: json、xml
24
+ ```
25
+
26
+ # 已实现API
27
+ - 用户获取 Token
28
+ - 刷新用户信息
29
+ - 消息历史记录下载地址获取
30
+ - 创建群组
31
+ - 解散群组
32
+ - 刷新群组信息
33
+ - 查询群成员
34
+
35
+ # 使用
36
+
37
+ ```ruby
38
+ RongCloudIM::User.get_token user_id: "f1", name: "xxx", portrait_uri: ''
39
+ ```
40
+
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
1
+ module RongCloudIM
2
+ class Group < Service
3
+ ACTION_GROUP_CREATE = "/group/create"
4
+ ACTION_GROUP_DISMISS = "/group/dismiss"
5
+ ACTION_GROUP_REFRESH = "/group/refresh"
6
+ ACTION_GROUP_USER_QUERY = "/group/user/query"
7
+
8
+ class << self
9
+ def create(params)
10
+ data = {
11
+ userId: params[:user_id],
12
+ groupId: params[:group_id],
13
+ groupName: params[:group_name]
14
+ }
15
+
16
+ get_response(data, ACTION_GROUP_CREATE)
17
+ end
18
+
19
+ def dismiss(params)
20
+ data = {
21
+ userId: params[:user_id],
22
+ groupId: params[:group_id],
23
+ }
24
+
25
+ get_response(data, ACTION_GROUP_DISMISS)
26
+ end
27
+
28
+ def refresh(params)
29
+ data = {
30
+ groupId: params[:group_id],
31
+ groupName: params[:group_name]
32
+ }
33
+
34
+ get_response(data, ACTION_GROUP_REFRESH)
35
+ end
36
+
37
+ def user_query(params)
38
+ data = {
39
+ groupId: params[:group_id]
40
+ }
41
+
42
+ get_response(data, ACTION_GROUP_USER_QUERY)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ module RongCloudIM
2
+ class Message < Service
3
+ ACTION_MESSAGE_HISTORY = "/message/history"
4
+
5
+ class << self
6
+ def history(params)
7
+ data = {
8
+ date: params[:date]
9
+ }
10
+
11
+ get_response(data, ACTION_MESSAGE_HISTORY)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ module RongCloudIM
2
+ class User < Service
3
+ ACTION_USER_TOKEN = "/user/getToken"
4
+ ACTION_USER_REFRESH = "/user/refresh"
5
+
6
+ class << self
7
+ def get_token(params)
8
+ data = {
9
+ userId: params[:user_id],
10
+ name: params[:name],
11
+ portraitUri: params[:portrait_uri]
12
+ }
13
+
14
+ get_response(data, ACTION_USER_TOKEN)
15
+ end
16
+
17
+ def refresh(params)
18
+ data = {
19
+ userId: params[:user_id],
20
+ name: params[:name],
21
+ portraitUri: params[:portrait_uri]
22
+ }
23
+
24
+ get_response(data, ACTION_USER_TOKEN)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,61 @@
1
+ module RongCloudIM
2
+ class Service
3
+ API_HOST = "http://api.cn.ronghub.com"
4
+
5
+ class << self
6
+
7
+ def get_response(data, path)
8
+ uri = URI(API_HOST + path + "." + response_type)
9
+
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+
12
+ request = Net::HTTP::Post.new(uri.path)
13
+
14
+ headers.each do |key, value|
15
+ request.add_field(key, value)
16
+ end
17
+
18
+ request.set_form_data(data)
19
+ response = http.request(request)
20
+
21
+ result response.body
22
+ end
23
+
24
+ private
25
+
26
+ def sign(data)
27
+ OpenSSL::Digest::SHA1.new(data).to_s
28
+ end
29
+
30
+ def headers
31
+ nonce = Random.new_seed.to_s
32
+ timestamp = Time.now.to_i.to_s
33
+ app_secret = RongCloudIM.app_secret || ""
34
+ signature = sign(app_secret + nonce + timestamp)
35
+ {
36
+ 'RC-App-Key': RongCloudIM.app_key || "",
37
+ 'RC-Nonce': nonce,
38
+ 'RC-Timestamp': timestamp,
39
+ 'RC-Signature': signature
40
+ }
41
+ end
42
+
43
+ def response_type
44
+ RongCloudIM.response_type || 'json'
45
+ end
46
+
47
+ def result body
48
+ begin
49
+ JSON.parse body
50
+ rescue => e
51
+ {
52
+ code: 502,
53
+ msg: "内容解析错误",
54
+ detail: e.to_s
55
+ }
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module RongCloudIM
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'openssl'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'rong_cloud_im/version'
5
+ require 'rong_cloud_im/service'
6
+ require 'rong_cloud_im/service/user'
7
+ require 'rong_cloud_im/service/group'
8
+ require 'rong_cloud_im/service/message'
9
+
10
+ module RongCloudIM
11
+
12
+ class << self
13
+ attr_accessor :app_key, :app_secret, :response_type
14
+ end
15
+
16
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rong_cloud_im/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'rong_cloud_im'
8
+ s.version = RongCloudIM::VERSION
9
+ s.date = '2016-06-13'
10
+ s.summary = "融云IM API"
11
+ s.description = "融云IM server接口调用"
12
+ s.authors = ["fwshun8023"]
13
+ s.email = ['fwshun8023@gmai.com']
14
+ s.homepage = 'https://github.com/fwshun8023/rong_cloud_im'
15
+ s.license = 'MIT'
16
+
17
+ s.files = `git ls-files`.split($/)
18
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "bundler", "~> 1.3"
23
+ s.add_development_dependency "rake", "~> 10.0"
24
+ s.add_development_dependency 'rspec', "~> 3.4"
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RongCloudIM" do
4
+
5
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "RongCloudIM::Group" do
5
+ let(:user_id) { 'f1' }
6
+ let(:user_id2) { 'f2' }
7
+ let(:group_id) { 'g1' }
8
+ let(:group_name) { '群' }
9
+ let(:name) { '测试' }
10
+ let(:portrait_uri) { '' }
11
+
12
+ describe "#create" do
13
+
14
+ it "should create success" do
15
+ params = { user_id: user_id, group_id: group_id, group_name: group_name }
16
+ result = RongCloudIM::Group.create(params)
17
+
18
+ expect(result["code"]).to eq(200)
19
+ end
20
+
21
+ it "should create args error" do
22
+ params = { group_id: group_id, group_name: group_name }
23
+ result = RongCloudIM::Group.create(params)
24
+
25
+ expect(result["code"]).to eq(1002)
26
+ end
27
+
28
+ it "should create args error" do
29
+ params = { group_name: group_name }
30
+ result = RongCloudIM::Group.create(params)
31
+
32
+ expect(result["code"]).to eq(1002)
33
+ end
34
+
35
+ end
36
+
37
+
38
+
39
+
40
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "RongCloudIM::Message" do
5
+
6
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "RongCloudIM::User" do
5
+ let(:user_id) { 'f1' }
6
+ let(:name) { '测试' }
7
+ let(:portrait_uri) { '' }
8
+
9
+ describe "#get_token" do
10
+
11
+ it "should get token success" do
12
+ params = { user_id: user_id, name: name, portrait_uri: portrait_uri }
13
+ result = RongCloudIM::User.get_token(params)
14
+
15
+ expect(result["code"]).to eq(200)
16
+ expect(result["userId"]).to eq('f1')
17
+ end
18
+
19
+ end
20
+
21
+ describe "#refresh" do
22
+
23
+ it "should refresh success" do
24
+ params = { user_id: user_id, name: name, portrait_uri: portrait_uri }
25
+ result = RongCloudIM::User.refresh(params)
26
+
27
+ expect(result["code"]).to eq(200)
28
+ end
29
+
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "RongCloudIM::Service" do
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rong_cloud_im'
5
+
6
+
7
+ RongCloudIM.app_key = 'c9kqb3rdklwcj'
8
+ RongCloudIM.app_secret = 'RcSM2RQcHP5k'
9
+
10
+ RSpec.configure do |config|
11
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rong_cloud_im
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fwshun8023
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-13 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: 融云IM server接口调用
56
+ email:
57
+ - fwshun8023@gmai.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rong_cloud_im.rb
68
+ - lib/rong_cloud_im/service.rb
69
+ - lib/rong_cloud_im/service/group.rb
70
+ - lib/rong_cloud_im/service/message.rb
71
+ - lib/rong_cloud_im/service/user.rb
72
+ - lib/rong_cloud_im/version.rb
73
+ - rong_cloud_im.gemspec
74
+ - spec/rong_cloud_im_spec.rb
75
+ - spec/service/group_spec.rb
76
+ - spec/service/message_spec.rb
77
+ - spec/service/user_spec.rb
78
+ - spec/service_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: https://github.com/fwshun8023/rong_cloud_im
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.5.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: 融云IM API
104
+ test_files:
105
+ - spec/rong_cloud_im_spec.rb
106
+ - spec/service/group_spec.rb
107
+ - spec/service/message_spec.rb
108
+ - spec/service/user_spec.rb
109
+ - spec/service_spec.rb
110
+ - spec/spec_helper.rb