xiaomi-push 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +13 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +0 -1
- data/README.md +180 -44
- data/Rakefile +57 -26
- data/bin/xmp +1 -1
- data/lib/xiaomi/push.rb +6 -3
- data/lib/xiaomi/push/client.rb +70 -16
- data/lib/xiaomi/push/commands.rb +1 -0
- data/lib/xiaomi/push/commands/feedback.rb +4 -5
- data/lib/xiaomi/push/commands/message.rb +21 -12
- data/lib/xiaomi/push/commands/user.rb +69 -0
- data/lib/xiaomi/push/const.rb +20 -2
- data/lib/xiaomi/push/platforms/android.rb +17 -0
- data/lib/xiaomi/push/platforms/ios.rb +20 -0
- data/lib/xiaomi/push/services/feedback.rb +9 -2
- data/lib/xiaomi/push/services/job.rb +36 -0
- data/lib/xiaomi/push/services/message.rb +49 -56
- data/lib/xiaomi/push/services/messages.rb +91 -0
- data/lib/xiaomi/push/services/messages/android.rb +11 -1
- data/lib/xiaomi/push/services/messages/base.rb +108 -6
- data/lib/xiaomi/push/services/messages/ios.rb +21 -1
- data/lib/xiaomi/push/services/topic.rb +39 -2
- data/lib/xiaomi/push/services/user.rb +60 -0
- data/lib/xiaomi/push/version.rb +1 -1
- data/xiaomi-push.gemspec +8 -8
- metadata +27 -51
- data/.travis.yml +0 -3
- data/lib/xiaomi/push/devices/android.rb +0 -6
- data/lib/xiaomi/push/devices/ios.rb +0 -9
- data/lib/xiaomi/push/services/multi_messages.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6770ff7fa9a2ee7457a000b350443879dd95c212
|
4
|
+
data.tar.gz: 89a52e13d3a8ba6a173b200cd69252e670ad304c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 285e9e1407613442177dbbb7ee9de2a1e630f294b6e1fbb01bd7b306ba7a29273f9881b8ca05c646876ee4d345d63dbed5ecb4d6b2977195d1a1020970af8c15
|
7
|
+
data.tar.gz: ecdf47335c176429e7ed0289a9c47364c1af2e9df11468da71158cd1c456eca05ddeee0ea1f2d4b093c015a48826ab191234fa479f877bf31327f2e85ebf097e
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# 变更历史
|
2
|
+
|
3
|
+
### v0.3.0
|
4
|
+
|
5
|
+
主要围绕 [#4](https://github.com/icyleaf/xiaomi-push/issues/4) 的需求完成:
|
6
|
+
|
7
|
+
- [重大改变] 仅支持 ruby 2.1(包含)以上版本
|
8
|
+
|
9
|
+
- [新增] 支持 iOS 10 的消息结构
|
10
|
+
- [新增] 初始化支持使用 sandbox 推送环境
|
11
|
+
- [新增] `message.counters` 接口获取消息的统计数据
|
12
|
+
- [新增] `message.send` 接口使用 v3 版本并支持 user_account 查询(调用时用 user)
|
13
|
+
- [新增] `user.aliases` 接口获取根据 reg id 查找绑定的别名(aliases)
|
14
|
+
- [新增] `user.topics` 接口获取根据 reg id 查找绑定的标签(Topics)
|
15
|
+
- [新增] `job.exist?` 接口检测定时任务是否存在
|
16
|
+
- [新增] `job.destory` 接口删除定时任务
|
17
|
+
- [新增] `xmp user` 命令工具支持查询 reg id 的 alias 和 topic
|
18
|
+
- [新增] `xmp message` 命令工具支持 user_account 推送
|
19
|
+
|
20
|
+
- [文档] 完善 README 文档和补全 API 文档
|
21
|
+
|
22
|
+
- [重构] 使用高性能的 http 代替 rest-client
|
23
|
+
- [重构] 移除 multi_json 转而使用自带的 json 解析
|
24
|
+
|
25
|
+
- [修复] 组装消息体获取 key 错误的问题 [8efc5ee](https://github.com/icyleaf/xiaomi-push/commit/8efc5eeb3e02366d3a92da62fc1a6b81a58a143c)
|
26
|
+
- [修复] 推送角标和声音设置不对的问题 [ebc4c89](https://github.com/icyleaf/xiaomi-push/commit/ebc4c89cad6db6d0b6cabaa7f52e54d53a4d55d6)
|
27
|
+
- [修复] `xmp` 检查 device 错误的逻辑 [1d728f29](https://github.com/icyleaf/xiaomi-push/commit/1d728f29405fd31bcff1a6d4c6cd4940ab9690ce)
|
28
|
+
|
29
|
+
### v0.2.4
|
30
|
+
|
31
|
+
- 项目初发布
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
非官方小米推送服务端 Ruby SDK
|
2
|
-
=============================
|
1
|
+
# 非官方小米推送服务端 Ruby SDK
|
3
2
|
|
4
|
-
|
3
|
+
[![Build Status](https://img.shields.io/circleci/project/github/icyleaf/xiaomi-push.svg?style=flat)](https://circleci.com/gh/icyleaf/xiaomi-push)
|
4
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/icyleaf/xiaomi-push.svg?style=flat)](https://codeclimate.com/github/icyleaf/xiaomi-push)
|
5
|
+
[![Inline docs](http://inch-ci.org/github/icyleaf/xiaomi-push.svg?style=flat)](https://inch-ci.org/github/icyleaf/xiaomi-push)
|
6
|
+
[![Gem version](https://img.shields.io/gem/v/xiaomi-push.svg?style=flat)](https://rubygems.org/gems/xiaomi-push)
|
7
|
+
[![License](https://img.shields.io/badge/license-MIT-red.svg?style=flat)](LICENSE.txt)
|
5
8
|
|
6
|
-
|
9
|
+
## TL;DR
|
7
10
|
|
8
|
-
|
9
|
-
=====
|
11
|
+
> 特别注意:仅支持 Ruby 2.1.0 (包含)以上版本。
|
10
12
|
|
11
|
-
安装
|
12
|
-
----
|
13
|
+
### 安装
|
13
14
|
|
14
15
|
添加如下至 Gemfile:
|
15
16
|
|
@@ -29,66 +30,170 @@ $ bundle
|
|
29
30
|
$ gem install xiaomi-push
|
30
31
|
```
|
31
32
|
|
32
|
-
用法
|
33
|
-
----
|
33
|
+
### 用法
|
34
34
|
|
35
|
-
###
|
35
|
+
### 发单一消息
|
36
|
+
|
37
|
+
支持按照 `reg_id`/`alias`/`topic`/`topics`/`user`/`all` 的方式向单个或一组设备发送同一条推送消息。
|
36
38
|
|
37
39
|
```ruby
|
38
40
|
require 'xiaomi-push'
|
41
|
+
|
39
42
|
# 初始化
|
40
|
-
|
41
|
-
client = Xiaomi::Push::IOS('Fill your app secret')
|
42
|
-
|
43
|
+
# iOS (环境支持 :production/:sandbox)
|
44
|
+
client = Xiaomi::Push::IOS('Fill your app secret', :production)
|
45
|
+
# Android
|
43
46
|
client = Xiaomi::Push::Android('Fill your app secret')
|
44
47
|
|
45
48
|
# 消息结构
|
46
|
-
|
49
|
+
# Hash 模式
|
47
50
|
message = {
|
48
51
|
'title': 'Android 需要标题',
|
49
52
|
'descrption': 'iOS 主要显示描述',
|
50
53
|
'extra.uri': 'app://bbs?id=8624'
|
51
54
|
}
|
52
55
|
|
53
|
-
|
54
|
-
|
56
|
+
# Builder 模式
|
57
|
+
# iOS
|
58
|
+
message = Xiaomi::Push::Message::IOS.new(
|
59
|
+
description: 'iOS 主要显示描述',
|
60
|
+
badge: 10,
|
61
|
+
extras: {
|
62
|
+
uri: 'app://bbs?id=8624',
|
63
|
+
source: 'mpush'
|
64
|
+
}
|
65
|
+
)
|
66
|
+
|
67
|
+
# iOS 10
|
55
68
|
message = Xiaomi::Push::Message::IOS.new(
|
56
|
-
|
57
|
-
|
69
|
+
title: '这是标题',
|
70
|
+
subtitle: '这是副标题'
|
71
|
+
description:'iOS 主要显示描述', # 对于 iOS 这里即可以是 description 也可以是 iOS 10 结构的 body
|
72
|
+
badge: 1,
|
58
73
|
extras: {
|
59
74
|
uri: 'app://bbs?id=8624',
|
60
75
|
source: 'mpush'
|
61
76
|
}
|
62
77
|
)
|
63
78
|
|
64
|
-
|
79
|
+
# Android
|
65
80
|
message = Xiaomi::Push::Message::Android.new(
|
66
|
-
title:'标题要有吸引力',
|
67
|
-
description:'描述可以在手机显示两行',
|
68
|
-
notify_type:'DEFAULT_ALL',
|
81
|
+
title: '标题要有吸引力',
|
82
|
+
description: '描述可以在手机显示两行',
|
83
|
+
notify_type: 'DEFAULT_ALL',
|
69
84
|
extras: {
|
70
85
|
source: 'mpush'
|
71
86
|
}
|
72
87
|
)
|
73
|
-
|
88
|
+
|
89
|
+
# 支持单独追加 extra
|
74
90
|
message.extra('uri', 'app://bbs?id=8624')
|
75
91
|
|
76
92
|
# 发消息
|
77
|
-
|
93
|
+
# 根据 regid
|
78
94
|
client.message.send reg_id:'id', message:message
|
79
95
|
|
80
|
-
|
96
|
+
# 根据 alias
|
81
97
|
client.message.send alias:'alias', message:message
|
82
98
|
|
83
|
-
|
99
|
+
# 根据 topic
|
84
100
|
client.message.send topic:'topic', message:message
|
85
101
|
|
86
|
-
|
102
|
+
# 全部推送
|
87
103
|
client.message.send all:true, message:message
|
88
104
|
```
|
89
105
|
|
90
|
-
|
91
|
-
|
106
|
+
### 发送多条消息
|
107
|
+
|
108
|
+
支持同一设备类型的设备发送不同的消息。**注意**发送多个消息不能是不同类型的设备 key。
|
109
|
+
|
110
|
+
支持的消息类型:
|
111
|
+
|
112
|
+
- `:reg_id`
|
113
|
+
- `reg_id`
|
114
|
+
- `regid`
|
115
|
+
- `registration_id`
|
116
|
+
- `:alias`
|
117
|
+
- `:alias`
|
118
|
+
- `:user`
|
119
|
+
- `:user`
|
120
|
+
- `:account`
|
121
|
+
- `:useraccount`
|
122
|
+
- `:user_account`
|
123
|
+
|
124
|
+
> 以上子列表为消息体传递的设备的 key 的名字。
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
# 向多个 reg id 发送不同的消息
|
128
|
+
client.messages.send(:reg_id, [
|
129
|
+
{
|
130
|
+
reg_id: 'abc',
|
131
|
+
title: '这是标题1',
|
132
|
+
description: '这个是推送的描述1',
|
133
|
+
notify_type: -1
|
134
|
+
},
|
135
|
+
{
|
136
|
+
regid: 'dfc',
|
137
|
+
title: '这是标题2',
|
138
|
+
description: '这个是推送的描述2',
|
139
|
+
},
|
140
|
+
{
|
141
|
+
registration_id: 'dfc',
|
142
|
+
title: '这是标题2',
|
143
|
+
description: '这个是推送的描述2',
|
144
|
+
}
|
145
|
+
])
|
146
|
+
|
147
|
+
# 这个是错误的消息,无法发送
|
148
|
+
client.messages.send(:alias, [
|
149
|
+
{
|
150
|
+
reg_id: 'abc',
|
151
|
+
title: '这是标题1',
|
152
|
+
description: '这个是推送的描述1',
|
153
|
+
notify_type: -1
|
154
|
+
},
|
155
|
+
{
|
156
|
+
user: 'dfc',
|
157
|
+
title: '这是标题2',
|
158
|
+
description: '这个是推送的描述2',
|
159
|
+
},
|
160
|
+
])
|
161
|
+
```
|
162
|
+
|
163
|
+
### 订阅/取消订阅标签
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
# 订阅单个 reg id 到 beijing 标签
|
167
|
+
client.topic.subscribe(reg_id: 'abc', topic: 'beijing')
|
168
|
+
|
169
|
+
# 订阅多个 alias 到 beijing 标签
|
170
|
+
client.topic.subscribe(alias: 'abc,def,ghi,jkl', topic: 'beijing')
|
171
|
+
|
172
|
+
# 取消订阅 beijing 标签的单个 reg id
|
173
|
+
client.topic.unsubscribe(reg_id: 'abc', topic: 'beijing')
|
174
|
+
|
175
|
+
# 取消订阅 beijing 标签的多个 alias
|
176
|
+
client.topic.unsubscribe(alias: 'abc,def,ghi,jkl', topic: 'beijing')
|
177
|
+
```
|
178
|
+
|
179
|
+
### 获取无效 iOS 的推送设备
|
180
|
+
|
181
|
+
用于检查 iOS 用户关闭了应用的推送或者是卸载了 App 的设备列表
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
client.feedback.invalid
|
185
|
+
```
|
186
|
+
|
187
|
+
### 获取消息的统计数据
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
# 获取 2017-09-01 到 2017-09-30 应用 com.icyleaf.app.helloworld 统计数据
|
191
|
+
client.message.counters('20170901', '20170930', 'com.icyleaf.app.helloworld')
|
192
|
+
```
|
193
|
+
|
194
|
+
更多用例可查阅 [Rakefile](Rakefile)。
|
195
|
+
|
196
|
+
### 命令行工具
|
92
197
|
|
93
198
|
本 SDK 同时还附带一个命令行工具 `xmp`,可以使用它尽快快速的测试和验证参数信息.
|
94
199
|
|
@@ -96,28 +201,59 @@ client.message.send all:true, message:message
|
|
96
201
|
# 发消息
|
97
202
|
## iOS
|
98
203
|
### 发送附加内容并设置未读消息数为 2
|
99
|
-
$ xmp message --device ios --secret '<密钥>'
|
204
|
+
$ xmp message --device ios --secret '<密钥>' \
|
205
|
+
--alias '<Alias>' \
|
206
|
+
-d '推送的描述内容' \
|
207
|
+
-b 2 \
|
208
|
+
-e uri="http://icyleaf.com"
|
209
|
+
# => {"result"=>"ok", "trace_id"=>"abc", "code"=>0, "data"=>{"id"=>"abc68b8350529097551xyz"}, "description"=>"成功", "info"=>"Received push messages for 1 ALIAS"}
|
100
210
|
|
101
211
|
## Android
|
102
212
|
### 最基本的推送信息
|
103
|
-
$ xmp message --device android --secret '<密钥>'
|
213
|
+
$ xmp message --device android --secret '<密钥>' \
|
214
|
+
--regid '<RegId>' \
|
215
|
+
-i '推送的标题' \
|
216
|
+
-d '推送的描述内容'
|
217
|
+
# => {"result"=>"ok", "trace_id"=>"abc", "code"=>0, "data"=>{"id"=>"abc68b8350529097551xyz"}, "description"=>"成功", "info"=>"Received push messages for 1 REG_ID"}
|
218
|
+
|
219
|
+
# 查找绑定的 aliases 和 topics
|
220
|
+
$ xmp user --device ios --secret '<密钥>' --reg-id '<RegId>'
|
221
|
+
# => alias count: 1
|
222
|
+
# => * ABCDEFGH-1234-5678-90ABC-F4DC5731EEFD
|
223
|
+
# => topic count: 1
|
224
|
+
# => * all
|
225
|
+
|
226
|
+
# 查找 iOS 无效的设备(Reg id)
|
227
|
+
$ xmp feedback --device ios --secret '<密钥>'
|
228
|
+
# => {"result"=>"ok", "trace_id"=>"Xlm07b67505290966457ey", "code"=>0, "data"=>{"list"=>["+9AKnbpV22HafwE7vjYMr6Hc7i41ClyQr7iqX1fm7zc="]}}
|
104
229
|
|
105
230
|
# 查看帮助
|
106
231
|
$ xmp message --help
|
107
|
-
```
|
108
232
|
|
109
|
-
|
110
|
-
|
233
|
+
NAME:
|
234
|
+
|
235
|
+
xmp
|
236
|
+
|
237
|
+
DESCRIPTION:
|
238
|
+
|
239
|
+
小米推送命令行工具
|
240
|
+
|
241
|
+
COMMANDS:
|
242
|
+
|
243
|
+
feedback 获取小米无效的设备列表
|
244
|
+
message 发送小米推送消息
|
245
|
+
user 小米 aliases/topics 查询工具
|
246
|
+
```
|
111
247
|
|
112
|
-
|
248
|
+
## 相关资源
|
113
249
|
|
114
|
-
|
250
|
+
- 官方 API 文档: https://dev.mi.com/console/doc/detail?pId=1163
|
251
|
+
- 官方 SDK 下载:https://dev.mi.com/mipush/downpage/ (Python Java PHP)
|
115
252
|
|
116
|
-
贡献代码
|
117
|
-
--------
|
253
|
+
## 贡献代码
|
118
254
|
|
119
|
-
1.
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
255
|
+
1. Fork it ( https://github.com/[my-github-username]/xiaomi-push/fork )
|
256
|
+
1. Create your feature branch (`git checkout -b my-new-feature`\)
|
257
|
+
1. Commit your changes (`git commit -am 'Add some feature'`\)
|
258
|
+
1. Push to the branch (`git push origin my-new-feature`\)
|
259
|
+
1. Create a new Pull Request
|
data/Rakefile
CHANGED
@@ -1,48 +1,79 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
-
require 'dotenv/tasks'
|
4
|
-
|
5
|
-
# $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
6
3
|
|
4
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
7
5
|
require 'xiaomi/push'
|
6
|
+
require 'pp'
|
8
7
|
|
9
8
|
RSpec::Core::RakeTask.new(:spec)
|
10
9
|
|
11
10
|
task default: :spec
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
namespace :message do
|
13
|
+
task :send do
|
14
|
+
message = {
|
15
|
+
title: '这是标题',
|
16
|
+
description: '这个是推送的描述',
|
17
|
+
notify_type: -1
|
18
|
+
}
|
19
19
|
|
20
|
-
|
20
|
+
p 'Send message to android device'
|
21
|
+
client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_SECRET'])
|
22
|
+
client.message.send(reg_id: '', message: message)
|
23
|
+
r = client.message.send(alias: '866383029998732', message: message)
|
24
|
+
# r = client.message.send(topic: 'test', message: message)
|
25
|
+
puts r
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
p 'Send message to ios device'
|
28
|
+
client = Xiaomi::Push::IOS.new(ENV['XIAOMI_PUSH_SECRET'])
|
29
|
+
r = client.message.send(
|
30
|
+
reg_id: 'xksdf76s667687xd786sdxsdf689s6x6s8d76s8d',
|
31
|
+
message: Xiaomi::Push::Message::IOS.new(
|
32
|
+
description: '这不是描述'
|
33
|
+
))
|
34
|
+
puts r
|
35
|
+
end
|
27
36
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
task :multi_send do
|
38
|
+
client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_SECRET'])
|
39
|
+
client.messages.send(:reg_idss, [
|
40
|
+
{
|
41
|
+
reg_id: 'abc',
|
42
|
+
title: '这是标题1',
|
43
|
+
description: '这个是推送的描述1',
|
44
|
+
notify_type: -1
|
45
|
+
},
|
46
|
+
{
|
47
|
+
reg_id: 'dfc',
|
48
|
+
title: '这是标题2',
|
49
|
+
description: '这个是推送的描述2',
|
50
|
+
}
|
51
|
+
])
|
52
|
+
end
|
53
|
+
|
54
|
+
task :counters, [:package_name, :start_date, :end_date] do |t, opts|
|
55
|
+
require 'date'
|
56
|
+
start_date = opts.fetch(:start_date, Date.today.strftime('%Y%m%d'))
|
57
|
+
end_date = opts.fetch(:end_date, (Date.today + 1).strftime('%Y%m%d'))
|
58
|
+
package_name = opts.fetch(:package_name)
|
59
|
+
|
60
|
+
if package_name
|
61
|
+
client = Xiaomi::Push::IOS.new(ENV['XIAOMI_PUSH_SECRET'])
|
62
|
+
pp client.message.counters(start_date, end_date, package_name)
|
63
|
+
else
|
64
|
+
puts "missing package name"
|
65
|
+
end
|
66
|
+
end
|
36
67
|
end
|
37
68
|
|
38
69
|
namespace :topic do
|
39
|
-
task subscribe
|
40
|
-
client = Xiaomi::Push::
|
70
|
+
task :subscribe do
|
71
|
+
client = Xiaomi::Push::IOS.new(ENV['XIAOMI_PUSH_SECRET'])
|
41
72
|
r = client.topic.subscribe(alias: '866383029998732', name: 'test')
|
42
73
|
puts r
|
43
74
|
end
|
44
75
|
|
45
|
-
task unsubscribe
|
76
|
+
task :unsubscribe do
|
46
77
|
client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
|
47
78
|
r = client.topic.unsubscribe(alias: '866383029998732', name: 'test')
|
48
79
|
puts r
|