rongcloud 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +91 -5
- data/lib/rongcloud/service/message.rb +13 -1
- data/lib/rongcloud/service.rb +2 -1
- data/lib/rongcloud/version.rb +1 -1
- data/lib/rongcloud.rb +1 -0
- data/rongcloud.gemspec +3 -1
- metadata +32 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71db14d612f9142090dae9d4e92a27d4a73e24b0
|
4
|
+
data.tar.gz: c238fb06e27332feb441550afa9480dc7b0d6761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c51c3e73dd119c20342dec86d69d30c556c63fb5ab7d767cd38fe2a69bc6022ab369f46c7c3609553968254b5eef0d1fe389d503dc822649a3aef1bcaf8afbb
|
7
|
+
data.tar.gz: e45adb26c8f242c0e7d0aa400acd30941c99ef485b4c3dbf8ca86dc738a74e2c8a4a89726812cadb07931c3383d52a0a1faeff1c5a8a3d4a986b9141b6562e88
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Rongcloud
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
融云及时通讯server端api
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -20,9 +18,97 @@ Or install it yourself as:
|
|
20
18
|
|
21
19
|
$ gem install rongcloud
|
22
20
|
|
23
|
-
##
|
21
|
+
## 配置基本信息
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Rongcloud.app_key = 'YOUR_APPKEY' #融云APPKEY
|
25
|
+
Rongcloud.app_secret = 'YOUR_SECRET' #融云APP_SECRET
|
26
|
+
```
|
27
|
+
|
28
|
+
#### 获取用户TOKEN `/user/getToken`
|
29
|
+
```ruby
|
30
|
+
user = Rongcloud::Service::User.new
|
31
|
+
|
32
|
+
user.user_id = 2
|
33
|
+
user.name = 'RONGYUN_USERNAME'
|
34
|
+
user.portrait_uri = 'http://tp1.sinaimg.cn/1611305952/180/5683416585/1'
|
35
|
+
user.get_token
|
36
|
+
user.token
|
37
|
+
# => adfasdfwere=23/wrewelwerwe==werw
|
38
|
+
```
|
24
39
|
|
25
|
-
|
40
|
+
#### 刷新用户基本信息 `/user/refresh`
|
41
|
+
```ruby
|
42
|
+
user = Rongcloud::Service::User.new
|
43
|
+
|
44
|
+
user.user_id = 2
|
45
|
+
user.name = 'RONGYUN_USERNAME'
|
46
|
+
user.portrait_uri = 'http://tp1.sinaimg.cn/1611305952/180/5683416585/1'
|
47
|
+
user.refresh
|
48
|
+
# => true
|
49
|
+
```
|
50
|
+
|
51
|
+
#### 发送单聊消息 `/message/private/publish`
|
52
|
+
```ruby
|
53
|
+
model = Rongcloud::Service::Message.new
|
54
|
+
|
55
|
+
model.from_user_id = 2
|
56
|
+
model.to_user_id = 1
|
57
|
+
model.object_name = 'RC:TxtMsg'
|
58
|
+
txt_msg = Rongcloud::Service::RCTxtMsg.new
|
59
|
+
txt_msg.content = 'good job'
|
60
|
+
txt_msg.extra = 'hello extra'
|
61
|
+
model.private_publish txt_msg
|
62
|
+
# => true
|
63
|
+
```
|
64
|
+
|
65
|
+
#### 发送系统消息 `/message/system/publish`
|
66
|
+
```ruby
|
67
|
+
#多图文消息
|
68
|
+
model = Rongcloud::Service::Message.new
|
69
|
+
model.from_user_id = '10086'
|
70
|
+
model.to_user_id = '0fd11abae5ce150247bf95831ee2d939'
|
71
|
+
model.object_name = 'CU:MoreImgTextMsg'
|
72
|
+
|
73
|
+
txt_msg = Rongcloud::Service::RCImgTextMsg.new
|
74
|
+
txt_msg.title = '订单已签收,请留意!!!!'
|
75
|
+
txt_msg.image_uri = 'http://mmbiz.qpic.cn/mmbiz_jpg/sKpnItfibB47q01zqjHEu2B3Ffw9FIzDHk4r8d4p1PbSictuChRDDIPxBialQvmr2s9HAzkZWkYWRREYNZSgQOSKQ/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1'
|
76
|
+
txt_msg.url = 'http://mp.weixin.qq.com/s?__biz=MjM5MDU4Njg5Mw==&mid=2247484325&idx=1&sn=883a0e1e61550b994146fa35161e0d40&scene=0#rd'
|
77
|
+
txt_msg.extra = {data: [{
|
78
|
+
title: '【惊喜】送钱又送礼,没想到你是酱紫的?',
|
79
|
+
imageUri: 'http://mmbiz.qpic.cn/mmbiz_png/fJQfMRLCskZ1I8p2jic2twlAKQOsRicMtIxu8YqgmBzqXkNwy4577zEyqDFnNibqaIhEJPJUeXBchLbFGywp4vMxw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1',
|
80
|
+
url: 'http://mp.weixin.qq.com/s?__biz=MjM5MDU4Njg5Mw==&mid=2247484325&idx=3&sn=90e918570245390b065f3b6506d54a5c&scene=0#rd'
|
81
|
+
},
|
82
|
+
{
|
83
|
+
|
84
|
+
title: '【特惠】开学季精明家长备货清单,9.9元起包邮',
|
85
|
+
imageUri: 'http://mmbiz.qpic.cn/mmbiz_png/EEtCXiaicRt14LYqXlCLEK1xTvKFISNB1T948RhDctJuPHKjY03qXh4xKrFNaE9xZRUeMBaKlZnEPwkicLwoKfZMQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1',
|
86
|
+
url: 'http://mp.weixin.qq.com/s?__biz=MjM5MDU4Njg5Mw==&mid=2247484325&idx=4&sn=f73ab4afa29a9842324ae6f5d6e32e83&scene=0#rd'
|
87
|
+
}, {
|
88
|
+
title: '【拔草】快放开我,我控几不住我记几了!',
|
89
|
+
imageUri: 'http://mmbiz.qpic.cn/mmbiz_jpg/EEtCXiaicRt14LYqXlCLEK1xTvKFISNB1ToPw74J7Ra7qh9QsCnaBAp6I9U3Mso9eIYOPvBdtbUnmczhdhDm9snw/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1',
|
90
|
+
url: 'http://mp.weixin.qq.com/s?__biz=MjM5MDU4Njg5Mw==&mid=2247484325&idx=5&sn=312bbaedacd17220bc5ca73c49890070&scene=0#rd'
|
91
|
+
}]}.to_json
|
92
|
+
model.system_publish txt_msg
|
93
|
+
# => true
|
94
|
+
```
|
95
|
+
|
96
|
+
#### 获取聊天历史记录 `/message/history`
|
97
|
+
```ruby
|
98
|
+
model = Rongcloud::Service::Message.new
|
99
|
+
sync_msg = ->(date_str) do
|
100
|
+
('00'..'23').to_a.each { |h|
|
101
|
+
history = model.history("#{date_str}#{h}")
|
102
|
+
if history[:code]==200 && history[:url] && history[:url].include?('http')
|
103
|
+
system(" curl -o tmp/#{history[:date]}.zip #{history[:url]}")
|
104
|
+
system(" unzip -o tmp/#{history[:date]}.zip -d tmp/")
|
105
|
+
end
|
106
|
+
history[:code] # => true
|
107
|
+
}
|
108
|
+
end
|
109
|
+
sync_msg.call(Time.now.strftime('%Y%m%d'))
|
110
|
+
sync_msg.call(DateTime.parse((Time.now.to_time-24*60*60).to_s).strftime('%Y%m%d'))
|
111
|
+
```
|
26
112
|
|
27
113
|
## Development
|
28
114
|
|
@@ -16,6 +16,17 @@ module Rongcloud
|
|
16
16
|
res[:code]==200
|
17
17
|
end
|
18
18
|
|
19
|
+
#发送系统消息
|
20
|
+
def system_public(rc_msg)
|
21
|
+
post = {uri: Rongcloud::Service::API_URI[:MSG_SYSTEM_PUBLISH],
|
22
|
+
params: optional_params({fromUserId: self.from_user_id, toUserId: self.to_user_id,
|
23
|
+
objectName: self.object_name,
|
24
|
+
content: rc_msg.json_content})
|
25
|
+
}
|
26
|
+
res = Rongcloud::Service.req_post(post)
|
27
|
+
res[:code]==200
|
28
|
+
end
|
29
|
+
|
19
30
|
#消息历史记录
|
20
31
|
def history(date_str)
|
21
32
|
post = {uri: Rongcloud::Service::API_URI[:MSG_HISTORY],
|
@@ -62,9 +73,10 @@ module Rongcloud
|
|
62
73
|
class RCImgTextMsg< Rongcloud::Service::RCMsg
|
63
74
|
attr_accessor :title
|
64
75
|
attr_accessor :image_uri
|
76
|
+
attr_accessor :url
|
65
77
|
|
66
78
|
def necessary_attrs
|
67
|
-
{title: self.title, content: self.content, imageUri: self.image_uri, extra: self.extra}
|
79
|
+
{title: self.title, content: self.content, imageUri: self.image_uri, url: self.url, extra: self.extra}
|
68
80
|
end
|
69
81
|
end
|
70
82
|
|
data/lib/rongcloud/service.rb
CHANGED
@@ -5,6 +5,7 @@ module Rongcloud
|
|
5
5
|
USER_GET_TOKEN: '/user/getToken.json',
|
6
6
|
USER_REFRESH: '/user/refresh.json',
|
7
7
|
MSG_PRV_PUBLISH: '/message/private/publish.json',
|
8
|
+
MSG_SYSTEM_PUBLISH: '/message/system/publish.json',
|
8
9
|
MSG_HISTORY: '/message/history.json'
|
9
10
|
}
|
10
11
|
|
@@ -34,7 +35,7 @@ module Rongcloud
|
|
34
35
|
config[:headers].each { |key, value| req.headers[key.to_s] = value.to_s }
|
35
36
|
if post_format.to_s == 'urlencode'
|
36
37
|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
37
|
-
req.body = config[:params].collect { |key, value| "#{key}=#{value}" }.join('&')
|
38
|
+
req.body = config[:params].collect { |key, value| "#{key}=#{value.to_s.urlencode}" }.join('&')
|
38
39
|
elsif post_format.to_s == 'json'
|
39
40
|
req.headers['Content-Type'] = 'application/json'
|
40
41
|
req.body = config[:params].to_json
|
data/lib/rongcloud/version.rb
CHANGED
data/lib/rongcloud.rb
CHANGED
data/rongcloud.gemspec
CHANGED
@@ -27,8 +27,10 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
+
spec.add_runtime_dependency "faraday", "~> 0.9.1"
|
31
|
+
spec.add_runtime_dependency "core_extend", "~> 0.2.1"
|
32
|
+
|
30
33
|
spec.add_development_dependency "rspec", "~> 3.2"
|
31
34
|
spec.add_development_dependency "bundler", "~> 1.9"
|
32
35
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
-
spec.add_development_dependency "faraday", "~> 0.9.1"
|
34
36
|
end
|
metadata
CHANGED
@@ -1,72 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rongcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mumaoxi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
19
|
+
version: 0.9.1
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.9.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: core_extend
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.1
|
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.2'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '3.2'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '1.9'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '1.9'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
75
|
+
version: '10.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0
|
69
|
-
description: 融云及时通讯
|
82
|
+
version: '10.0'
|
83
|
+
description: "融云及时通讯"
|
70
84
|
email:
|
71
85
|
- 15201280641@qq.com
|
72
86
|
executables: []
|
@@ -110,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
124
|
version: '0'
|
111
125
|
requirements: []
|
112
126
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.4.
|
127
|
+
rubygems_version: 2.4.8
|
114
128
|
signing_key:
|
115
129
|
specification_version: 4
|
116
|
-
summary: 融云及时通讯
|
130
|
+
summary: "融云及时通讯"
|
117
131
|
test_files: []
|