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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fb5c2e6c1ee0eafc8af99743a10c7eca42a55ea
4
- data.tar.gz: 6adb342258ca17d51b1cc394499092aedb2adc4d
3
+ metadata.gz: 6770ff7fa9a2ee7457a000b350443879dd95c212
4
+ data.tar.gz: 89a52e13d3a8ba6a173b200cd69252e670ad304c
5
5
  SHA512:
6
- metadata.gz: ce5818f4d419effc99c8632b1f42467d91d397149cec3af5d70b3e8a65f8a39bc64317ba6b5d520b1130b44c502e082692c3691e4d0483cfbe5567ef218ef474
7
- data.tar.gz: c225e1c92e96b3116b2a29c994646beb554929a63f862bf2121b2d7c3fa270a616853fc6d1d853ea478b7eaa3ed58ae43208bdbeae69b70a8cb016743bc6b751
6
+ metadata.gz: 285e9e1407613442177dbbb7ee9de2a1e630f294b6e1fbb01bd7b306ba7a29273f9881b8ca05c646876ee4d345d63dbed5ecb4d6b2977195d1a1020970af8c15
7
+ data.tar.gz: ecdf47335c176429e7ed0289a9c47364c1af2e9df11468da71158cd1c456eca05ddeee0ea1f2d4b093c015a48826ab191234fa479f877bf31327f2e85ebf097e
@@ -0,0 +1,13 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.4.1
6
+ branches:
7
+ ignore:
8
+ - gh-pages
9
+ working_directory: ~/xiaomi-push
10
+ steps:
11
+ - checkout
12
+ - run: bundle install
13
+ - run: rake spec
@@ -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
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- # source 'https://gems.ruby-china.org'
3
2
 
4
3
  # Specify your gem's dependencies in xiaomi-push.gemspec
5
4
  gemspec
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
- 非官方小米推送服务端 Ruby SDK
2
- =============================
1
+ # 非官方小米推送服务端 Ruby SDK
3
2
 
4
- > 小米官方好像也就不怎么维护此服务,本 gem 除了修复问题以为不做新特性的更新。
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
- 官方文档: http://dev.xiaomi.com/doc/?p=533#d5e725
9
+ ## TL;DR
7
10
 
8
- TL;DR
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
- ## iOS
41
- client = Xiaomi::Push::IOS('Fill your app secret')
42
- ## Android
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
- ## Hash 模式
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
- ## Builder 模式
54
- ### iOS
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
- description:'iOS 主要显示描述',
57
- badge:10,
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
- ### Android
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
- #### 支持单独追加 extra
88
+
89
+ # 支持单独追加 extra
74
90
  message.extra('uri', 'app://bbs?id=8624')
75
91
 
76
92
  # 发消息
77
- ## 根据 regid
93
+ # 根据 regid
78
94
  client.message.send reg_id:'id', message:message
79
95
 
80
- ## 根据 alias
96
+ # 根据 alias
81
97
  client.message.send alias:'alias', message:message
82
98
 
83
- ## 根据 topic
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 '<密钥>' -d '推送的内容' -b 2 -e uri="app://bbs?id",source="push"
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 '<密钥>' -i '推送的标题' -d '推送的内容'
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
248
+ ## 相关资源
113
249
 
114
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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. Fork it ( https://github.com/[my-github-username]/xiaomi-push/fork )
120
- 2. Create your feature branch (`git checkout -b my-new-feature`\)
121
- 3. Commit your changes (`git commit -am 'Add some feature'`\)
122
- 4. Push to the branch (`git push origin my-new-feature`\)
123
- 5. Create a new Pull Request
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
- task send: :dotenv do
14
- message = {
15
- title: '这是标题',
16
- description: '这个是推送的描述',
17
- notify_type: -1
18
- }
12
+ namespace :message do
13
+ task :send do
14
+ message = {
15
+ title: '这是标题',
16
+ description: '这个是推送的描述',
17
+ notify_type: -1
18
+ }
19
19
 
20
- client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
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
- p 'Send message to android device'
23
- client.message.send(reg_id: '', message: message)
24
- r = client.message.send(alias: '866383029998732', message: message)
25
- # r = client.message.send(topic: 'test', message: message)
26
- puts r
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
- p 'Send message to ios device'
29
- client = Xiaomi::Push::IOS.new(ENV['XIAOMI_PUSH_IOS_SECRET'])
30
- r = client.message.send(
31
- reg_id: 'xksdf76s667687xd786sdxsdf689s6x6s8d76s8d',
32
- message: Xiaomi::Push::Message::IOS.new(
33
- description: '这不是描述'
34
- ))
35
- puts r
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: :dotenv do
40
- client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
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: :dotenv do
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