非官方小米推送服务端 Ruby SDK
小米官方好像也就不怎么维护此服务,本 gem 除了修复问题以为不做新特性的更新。
官方文档: http://dev.xiaomi.com/doc/?p=533#d5e725
TL;DR
安装
添加如下至 Gemfile:
gem 'xiaomi-push'
执行:
$ bundle
或直接安装:
$ gem install xiaomi-push
用法
发消息
require 'xiaomi-push'
# 初始化
## iOS
client = Xiaomi::Push::IOS('Fill your app secret')
## Android
client = Xiaomi::Push::Android('Fill your app secret')
# 消息结构
## Hash 模式
= {
'title': 'Android 需要标题',
'descrption': 'iOS 主要显示描述',
'extra.uri': 'app://bbs?id=8624'
}
## Builder 模式
### iOS
= Xiaomi::Push::Message::IOS.new(
description:'iOS 主要显示描述',
badge:10,
extras: {
uri: 'app://bbs?id=8624',
source: 'mpush'
}
)
### Android
= Xiaomi::Push::Message::Android.new(
title:'标题要有吸引力',
description:'描述可以在手机显示两行',
notify_type:'DEFAULT_ALL',
extras: {
source: 'mpush'
}
)
#### 支持单独追加 extra
.extra('uri', 'app://bbs?id=8624')
# 发消息
## 根据 regid
client..send reg_id:'id', message:
## 根据 alias
client..send alias:'alias', message:
## 根据 topic
client..send topic:'topic', message:
## 全部推送
client..send all:true, message:
命令行工具
本 SDK 同时还附带一个命令行工具 xmp,可以使用它尽快快速的测试和验证参数信息.
# 发消息
## iOS
### 发送附加内容并设置未读消息数为 2
$ xmp message --device ios --secret '<密钥>' -d '推送的内容' -b 2 -e uri="app://bbs?id",source="push"
## Android
### 最基本的推送信息
$ xmp message --device android --secret '<密钥>' -i '推送的标题' -d '推送的内容'
# 查看帮助
$ xmp message --help
开发
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.
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.
贡献代码
- Fork it ( https://github.com/[my-github-username]/xiaomi-push/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request