xiaomi-push 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +109 -0
- data/Rakefile +45 -0
- data/bin/xmp +141 -0
- data/lib/xiaomi/push.rb +23 -0
- data/lib/xiaomi/push/client.rb +36 -0
- data/lib/xiaomi/push/const.rb +35 -0
- data/lib/xiaomi/push/devices/android.rb +6 -0
- data/lib/xiaomi/push/devices/ios.rb +11 -0
- data/lib/xiaomi/push/error.rb +20 -0
- data/lib/xiaomi/push/services/alias.rb +11 -0
- data/lib/xiaomi/push/services/feedback.rb +11 -0
- data/lib/xiaomi/push/services/message.rb +126 -0
- data/lib/xiaomi/push/services/messages/android.rb +19 -0
- data/lib/xiaomi/push/services/messages/base.rb +48 -0
- data/lib/xiaomi/push/services/messages/ios.rb +16 -0
- data/lib/xiaomi/push/services/multi_messages.rb +0 -0
- data/lib/xiaomi/push/services/topic.rb +11 -0
- data/lib/xiaomi/push/version.rb +5 -0
- data/xiaomi-push.gemspec +29 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2c3c36c6c5e5b4ba0a9e2c2a4613dc8d7a10cd6
|
4
|
+
data.tar.gz: c81f1a3bf49e0d03207a2716e1df1674fad2d45c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 215b4af4c6c8e3bdaacbd5e9a6fa967e0fe25d8d8ef5cbb69607b8c90b51e8665236246483c0a8001f52052ef8f0e7c4dbd7c8a25a1fbe18ba4f829cd877c915
|
7
|
+
data.tar.gz: 772e82860bcea9b62cd43a458ad37f247d6e30254755803266a5aab5c319e260a6580fa1fa070c329b8d28cd74178865dda471f5e5ca90c402f39442efa79756
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
非官方小米推送服务端 Ruby SDK
|
2
|
+
=============================
|
3
|
+
|
4
|
+
官方文档: http://dev.xiaomi.com/doc/?p=533#d5e725
|
5
|
+
|
6
|
+
安装
|
7
|
+
----
|
8
|
+
|
9
|
+
添加如下至 Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'xiaomi-push'
|
13
|
+
```
|
14
|
+
|
15
|
+
执行:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
或直接安装:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install xiaomi-push
|
25
|
+
```
|
26
|
+
|
27
|
+
用法
|
28
|
+
----
|
29
|
+
|
30
|
+
### 发消息
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'xiaomi-push'
|
34
|
+
# 初始化
|
35
|
+
## iOS
|
36
|
+
client = Xiaomi::Push::IOS('Fill your app secret')
|
37
|
+
## Android
|
38
|
+
client = Xiaomi::Push::Android('Fill your app secret')
|
39
|
+
|
40
|
+
# 消息结构
|
41
|
+
## Hash 模式
|
42
|
+
message = {
|
43
|
+
'title': 'Android 需要标题',
|
44
|
+
'descrption': 'iOS 主要显示描述',
|
45
|
+
'extra.uri': 'app://bbs?id=8624'
|
46
|
+
}
|
47
|
+
|
48
|
+
## Builder 模式
|
49
|
+
### iOS
|
50
|
+
message = Xiaomi::Push::Message::IOS.new(
|
51
|
+
description:'iOS 主要显示描述',
|
52
|
+
badge:10
|
53
|
+
)
|
54
|
+
|
55
|
+
### Android
|
56
|
+
message = Xiaomi::Push::Message::Android.new(
|
57
|
+
title:'标题要有吸引力',
|
58
|
+
description:'描述可以在手机显示两行',
|
59
|
+
notify_type:'DEFAULT_ALL'
|
60
|
+
)
|
61
|
+
|
62
|
+
# 发消息
|
63
|
+
## 根据 regid
|
64
|
+
client.message.send reg_id:'id', message:message
|
65
|
+
|
66
|
+
## 根据 alias
|
67
|
+
client.message.send alias:'alias', message:message
|
68
|
+
|
69
|
+
## 根据 topic
|
70
|
+
client.message.send topic:'topic', message:message
|
71
|
+
|
72
|
+
## 全部推送
|
73
|
+
client.message.send all:true, message:message
|
74
|
+
```
|
75
|
+
|
76
|
+
命令行工具
|
77
|
+
----------
|
78
|
+
|
79
|
+
本 SDK 同时还附带一个命令行工具 `xmp`,可以使用它尽快快速的测试和验证参数信息.
|
80
|
+
|
81
|
+
```bash
|
82
|
+
# 发消息
|
83
|
+
## iOS
|
84
|
+
### 发送附加内容并设置未读消息数为 2
|
85
|
+
$ xmp message --device ios --secret '<密钥>' -d '推送的内容' -b 2 -e uri="app://bbs?id",source="push"
|
86
|
+
|
87
|
+
## Android
|
88
|
+
### 最基本的推送信息
|
89
|
+
$ xmp message --device android --secret '<密钥>' -i '推送的标题' -d '推送的内容'
|
90
|
+
|
91
|
+
# 查看帮助
|
92
|
+
$ xmp message --help
|
93
|
+
```
|
94
|
+
|
95
|
+
开发
|
96
|
+
----
|
97
|
+
|
98
|
+
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.
|
99
|
+
|
100
|
+
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).
|
101
|
+
|
102
|
+
如何共享
|
103
|
+
--------
|
104
|
+
|
105
|
+
1. Fork it ( https://github.com/[my-github-username]/xiaomi-push/fork )
|
106
|
+
2. Create your feature branch (`git checkout -b my-new-feature`\)
|
107
|
+
3. Commit your changes (`git commit -am 'Add some feature'`\)
|
108
|
+
4. Push to the branch (`git push origin my-new-feature`\)
|
109
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require 'dotenv/tasks'
|
4
|
+
require 'awesome_print'
|
5
|
+
|
6
|
+
# $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
7
|
+
|
8
|
+
require 'xiaomi/push'
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
12
|
+
task :default => :spec
|
13
|
+
|
14
|
+
task :send => :dotenv do
|
15
|
+
|
16
|
+
message = {
|
17
|
+
title: '这是标题',
|
18
|
+
description: '这个是推送的描述',
|
19
|
+
notify_type: -1,
|
20
|
+
}
|
21
|
+
client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
|
22
|
+
|
23
|
+
p "Send message to android device"
|
24
|
+
# client.message.send(reg_id:'', data:message_data)
|
25
|
+
r = client.message.send(alias:'866383029998732', message:message)
|
26
|
+
# client.message.send(topic:'test', data:message_data)
|
27
|
+
ap r
|
28
|
+
|
29
|
+
p "Send message to ios device"
|
30
|
+
client = Xiaomi::Push::IOS.new(ENV['XIAOMI_PUSH_IOS_SECRET'])
|
31
|
+
r = client.message.send(
|
32
|
+
reg_id:'xksdf76s667687xd786sdxsdf689s6x6s8d76s8d',
|
33
|
+
message:Xiaomi::Push::Message::IOS.new(
|
34
|
+
description:'这不是描述'
|
35
|
+
))
|
36
|
+
ap r
|
37
|
+
end
|
38
|
+
|
39
|
+
task :message do
|
40
|
+
ios_message = Xiaomi::Push::Message::IOS.new(title:'dddd')
|
41
|
+
ios_message.extra('url', 'http://www.xxx.com')
|
42
|
+
p ios_message
|
43
|
+
|
44
|
+
p ios_message.build
|
45
|
+
end
|
data/bin/xmp
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'commander/import'
|
5
|
+
require "bundler/setup"
|
6
|
+
require "xiaomi/push"
|
7
|
+
require "awesome_print"
|
8
|
+
|
9
|
+
|
10
|
+
program :version, '0.0.1'
|
11
|
+
program :description, 'xiaomi push command line tool'
|
12
|
+
|
13
|
+
program :help, 'Author', 'icyleaf'
|
14
|
+
program :help, 'Website', 'icyleaf.cn@gmail.com'
|
15
|
+
program :help_formatter, Commander::HelpFormatter::Terminal
|
16
|
+
|
17
|
+
global_option('--verbose') { $verbose = true }
|
18
|
+
|
19
|
+
default_command :help
|
20
|
+
never_trace!
|
21
|
+
|
22
|
+
command :message do |c|
|
23
|
+
c.syntax = 'xmp message [options]'
|
24
|
+
c.summary = '发送小米推送消息'
|
25
|
+
c.description = '使用小米推送消息(目前仅支持 regid/alias/topic 推送方式)'
|
26
|
+
|
27
|
+
# normal params
|
28
|
+
c.option '--device DEVICE', ['android', 'ios'], '设备类型'
|
29
|
+
c.option '--secret SECRET', '应用密钥'
|
30
|
+
|
31
|
+
# type
|
32
|
+
c.option '--regid REGID', 'reg id'
|
33
|
+
c.option '--alias ALIAS', '别名'
|
34
|
+
c.option '--topic TOPIC', '订阅名'
|
35
|
+
|
36
|
+
# message
|
37
|
+
c.option '-i', '--title TITLE', '消息标题(仅 Android 有效)'
|
38
|
+
c.option '-d', '--description DESCRIPTION', '消息主体描述'
|
39
|
+
c.option '-b', '--badge BADGE', Integer, '消息数字'
|
40
|
+
c.option '-e', '--extras KEY=VALUE', Array, '自定义数据(使用 KEY=VALUE 方式,多个以逗号不带空格分隔)'
|
41
|
+
|
42
|
+
# ## ios only
|
43
|
+
# c.option '-y', '--category CATEGORY', '推送类别名称 (仅 iOS 有效)'
|
44
|
+
# c.option '-v', '--environment ENV', [:production, :sandbox], '推送环境(仅 iOS 有效)'
|
45
|
+
#
|
46
|
+
# ## android only
|
47
|
+
# c.option '-g', '--through THROUGHT', [0, 1], '消息传递方式(仅 iOS 有效)'
|
48
|
+
# c.option '-n', '--notify NOTIFY', [-1, 1, 2, 4], 'message notify type'
|
49
|
+
|
50
|
+
c.action do |args, options|
|
51
|
+
ap options if $verbose
|
52
|
+
|
53
|
+
@device = options.device.capitalize if options.device
|
54
|
+
@secret = options.secret
|
55
|
+
|
56
|
+
determine_device! unless @device
|
57
|
+
determine_secret! unless @secret
|
58
|
+
|
59
|
+
determine_channel!(options)
|
60
|
+
determine_message!(options)
|
61
|
+
|
62
|
+
sent!
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def sent!
|
68
|
+
message_data = {
|
69
|
+
@channel.to_sym => @channel_id,
|
70
|
+
:message => @message,
|
71
|
+
}
|
72
|
+
|
73
|
+
if $verbose
|
74
|
+
ap message_data
|
75
|
+
end
|
76
|
+
|
77
|
+
client = Xiaomi::Push.const_get(@device).new(@secret)
|
78
|
+
r = client.message.send(message_data)
|
79
|
+
|
80
|
+
ap r
|
81
|
+
end
|
82
|
+
|
83
|
+
def determine_android_message!(options)
|
84
|
+
@message = Xiaomi::Push::Message::Android.new(
|
85
|
+
title: @title,
|
86
|
+
description: @description,
|
87
|
+
badge: @badge,
|
88
|
+
extras: @extras
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def determine_ios_message!(options)
|
93
|
+
@message = Xiaomi::Push::Message::IOS.new(
|
94
|
+
description: @description,
|
95
|
+
badge: @badge,
|
96
|
+
extras: @extras
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
def determine_message!(options)
|
101
|
+
@title = options.title
|
102
|
+
@description = options.description
|
103
|
+
@badge = options.badge
|
104
|
+
|
105
|
+
@extras = if options.extras
|
106
|
+
Hash[options.extras.collect{|data| data.split(/\=/)}]
|
107
|
+
else
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
|
111
|
+
case @device.downcase
|
112
|
+
when 'android'
|
113
|
+
determine_android_message!(options)
|
114
|
+
when 'ios'
|
115
|
+
determine_ios_message!(options)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def determine_device!
|
120
|
+
devices = %w[Android iOS].freeze
|
121
|
+
@device = choose "选择推送设备:", *devices
|
122
|
+
end
|
123
|
+
|
124
|
+
def determine_secret!
|
125
|
+
@secret ||= ask '小米应用密钥:'
|
126
|
+
end
|
127
|
+
|
128
|
+
def determine_channel!(options)
|
129
|
+
channles = %w[regid alias topic].freeze
|
130
|
+
@channel = channles.select { |k| options.__hash__.has_key?k.to_sym }
|
131
|
+
|
132
|
+
unless @channel.count > 0
|
133
|
+
@channel = choose "选择推送方式:", *channles
|
134
|
+
|
135
|
+
@channel_id = ask "输入 #{@channel} 的值:"
|
136
|
+
else
|
137
|
+
@channel = @channel[0]
|
138
|
+
@channel_id = options.__hash__[@channel.to_sym]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/lib/xiaomi/push.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "xiaomi/push/version"
|
2
|
+
require "xiaomi/push/error"
|
3
|
+
require "xiaomi/push/const"
|
4
|
+
require "xiaomi/push/client"
|
5
|
+
|
6
|
+
require "xiaomi/push/devices/ios"
|
7
|
+
require "xiaomi/push/devices/android"
|
8
|
+
|
9
|
+
require "xiaomi/push/services/message"
|
10
|
+
require "xiaomi/push/services/topic"
|
11
|
+
require "xiaomi/push/services/alias"
|
12
|
+
require "xiaomi/push/services/feedback"
|
13
|
+
|
14
|
+
|
15
|
+
unless defined?(Dotenv)
|
16
|
+
require 'dotenv'
|
17
|
+
Dotenv.load
|
18
|
+
end
|
19
|
+
|
20
|
+
module Xiaomi
|
21
|
+
module Push
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "rest-client"
|
2
|
+
require "multi_json"
|
3
|
+
|
4
|
+
module Xiaomi
|
5
|
+
module Push
|
6
|
+
class Client
|
7
|
+
include Const
|
8
|
+
|
9
|
+
attr_reader :device, :secret, :header
|
10
|
+
def initialize(secret)
|
11
|
+
@device = self.class.name.split("::")[-1].upcase
|
12
|
+
|
13
|
+
unless DEVICES.include?@device
|
14
|
+
raise NameError, 'Instance using Xiaomi::Push::Android or Xiaomi::Push::IOS'
|
15
|
+
end
|
16
|
+
|
17
|
+
@secret = secret
|
18
|
+
|
19
|
+
@header = {
|
20
|
+
'Authorization' => "key=#{@secret}"
|
21
|
+
}
|
22
|
+
|
23
|
+
use_production!
|
24
|
+
end
|
25
|
+
|
26
|
+
def message
|
27
|
+
@message ||= Services::Message.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def topic
|
31
|
+
@topic ||= Services::Topic.new(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
|
4
|
+
module Xiaomi
|
5
|
+
module Push
|
6
|
+
module Const
|
7
|
+
DEVICES = %w[ANDROID IOS].freeze
|
8
|
+
|
9
|
+
PRODUCTION_URL = 'https://api.xmpush.xiaomi.com'
|
10
|
+
SANDBOX_URL = 'https://sandbox.xmpush.xiaomi.com'
|
11
|
+
|
12
|
+
attr_reader :base_url
|
13
|
+
|
14
|
+
def use_production!
|
15
|
+
production
|
16
|
+
end
|
17
|
+
|
18
|
+
def use_sandbox!
|
19
|
+
sandbox
|
20
|
+
end
|
21
|
+
|
22
|
+
def production
|
23
|
+
@base_url ||= PRODUCTION_URL
|
24
|
+
end
|
25
|
+
|
26
|
+
def sandbox
|
27
|
+
@base_url ||= SANDBOX_URL
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_uri(uri)
|
31
|
+
URI::join(@base_url, "v2/#{uri}").to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Xiaomi
|
2
|
+
module Push
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :url, :error
|
5
|
+
end
|
6
|
+
|
7
|
+
class RequestError < Xiaomi::Push::Error
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class FailuresError < Xiaomi::Push::Error
|
12
|
+
def initialize(code, error)
|
13
|
+
@code = code
|
14
|
+
@error = error
|
15
|
+
|
16
|
+
super "[#{@code}] #{@error}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'xiaomi/push/services/messages/base'
|
2
|
+
require 'xiaomi/push/services/messages/ios'
|
3
|
+
require 'xiaomi/push/services/messages/android'
|
4
|
+
|
5
|
+
module Xiaomi
|
6
|
+
module Push
|
7
|
+
module Services
|
8
|
+
class Message
|
9
|
+
|
10
|
+
MESSAGE_TYPE = {
|
11
|
+
reg_id: {
|
12
|
+
uri: 'regid',
|
13
|
+
query: 'registration_id'
|
14
|
+
},
|
15
|
+
alias: {
|
16
|
+
uri: 'alias',
|
17
|
+
query: 'alias'
|
18
|
+
},
|
19
|
+
topic: {
|
20
|
+
uri: 'topic',
|
21
|
+
query: 'topic'
|
22
|
+
},
|
23
|
+
topics: {
|
24
|
+
uri: 'multi_topic',
|
25
|
+
query: 'topics'
|
26
|
+
},
|
27
|
+
topic_op: {
|
28
|
+
uri: 'multi_topic',
|
29
|
+
query: 'topic_op'
|
30
|
+
},
|
31
|
+
all: {
|
32
|
+
uri: 'all',
|
33
|
+
query: 'all'
|
34
|
+
},
|
35
|
+
}
|
36
|
+
|
37
|
+
attr_reader :context
|
38
|
+
def initialize(context)
|
39
|
+
@context = context
|
40
|
+
end
|
41
|
+
|
42
|
+
def send(**options)
|
43
|
+
type, value = fetch_message_type(options)
|
44
|
+
if type && value
|
45
|
+
url = @context.build_uri("message/#{type[:uri]}")
|
46
|
+
if options[:message].kind_of?Xiaomi::Push::Message::Base
|
47
|
+
options[:message].type(type[:query], value)
|
48
|
+
params = options[:message].build
|
49
|
+
else
|
50
|
+
params = options[:message]
|
51
|
+
params[type[:query].to_sym] = value
|
52
|
+
end
|
53
|
+
|
54
|
+
r = RestClient.post url, params, @context.header
|
55
|
+
data = MultiJson.load r
|
56
|
+
else
|
57
|
+
raise Xiaomi::Push::RequestError, 'Not match message type: reg_id/alias/topic/topics/all'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def fetch_message_type(data)
|
62
|
+
type, value = nil
|
63
|
+
MESSAGE_TYPE.select do |k,v|
|
64
|
+
if data.has_key?k
|
65
|
+
type = v
|
66
|
+
value = data[k]
|
67
|
+
break
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
[type, value]
|
72
|
+
end
|
73
|
+
|
74
|
+
def valid?(params)
|
75
|
+
validates = {
|
76
|
+
'payload' => {
|
77
|
+
require: true,
|
78
|
+
},
|
79
|
+
'restricted_package_name' => {
|
80
|
+
require: true,
|
81
|
+
},
|
82
|
+
'pass_through' => {
|
83
|
+
require: true,
|
84
|
+
},
|
85
|
+
'title' => {
|
86
|
+
require: true,
|
87
|
+
},
|
88
|
+
'description' => {
|
89
|
+
require: true,
|
90
|
+
},
|
91
|
+
'notify_type' => {
|
92
|
+
require: true,
|
93
|
+
values: {
|
94
|
+
'DEFAULT_ALL' => -1,
|
95
|
+
'DEFAULT_SOUND' => 1,
|
96
|
+
'DEFAULT_VIBRATE' => 2,
|
97
|
+
'DEFAULT_LIGHTS' => 3
|
98
|
+
}
|
99
|
+
},
|
100
|
+
'time_to_live' => {
|
101
|
+
require: false,
|
102
|
+
},
|
103
|
+
'time_to_send' => {
|
104
|
+
require: false,
|
105
|
+
},
|
106
|
+
'notify_id' => {
|
107
|
+
require: false,
|
108
|
+
},
|
109
|
+
'extra.sound_uri' => {
|
110
|
+
require: false,
|
111
|
+
},
|
112
|
+
'extra.ticker' => {
|
113
|
+
require: false,
|
114
|
+
},
|
115
|
+
'extra.notify_foreground' => {
|
116
|
+
require: false,
|
117
|
+
},
|
118
|
+
'extra.notify_effect' => {
|
119
|
+
require: false,
|
120
|
+
},
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Xiaomi
|
2
|
+
module Push
|
3
|
+
module Message
|
4
|
+
class Android < Base
|
5
|
+
attr_accessor :title, :description, :badge, :sound, :pass_through, :notify_type, :notify_id, :extras
|
6
|
+
def initialize(**params)
|
7
|
+
@title = params[:title]
|
8
|
+
@description = params[:description]
|
9
|
+
@badge = params[:badge] || 1
|
10
|
+
@sound = params[:sound] || 'default'
|
11
|
+
@pass_through = params[:pass_through] || 0
|
12
|
+
@notify_type = params[:notify_type] || 'DEFAULT_ALL'
|
13
|
+
@notify_id = params[:notify_id]
|
14
|
+
@extras = params[:extras] || {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Xiaomi
|
2
|
+
module Push
|
3
|
+
module Message
|
4
|
+
class Base
|
5
|
+
attr_accessor :registration_id, :alias, :topic, :topics, :topic_op, :extras
|
6
|
+
|
7
|
+
def extra(key, value = nil)
|
8
|
+
unless value
|
9
|
+
@extras[key]
|
10
|
+
else
|
11
|
+
@extras[key] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def type(key, value = nil)
|
16
|
+
key = "@#{key}"
|
17
|
+
|
18
|
+
unless value
|
19
|
+
instance_variable_get key
|
20
|
+
else
|
21
|
+
instance_variable_set key, value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def build
|
26
|
+
hash_data = {}
|
27
|
+
instance_variables.each do |ivar|
|
28
|
+
key = ivar.to_s.gsub('@', '')
|
29
|
+
value = instance_variable_get ivar
|
30
|
+
|
31
|
+
if value
|
32
|
+
unless key == 'extras'
|
33
|
+
hash_data[key] = value
|
34
|
+
else
|
35
|
+
value.each do |k, v|
|
36
|
+
key = "extra.#{k}"
|
37
|
+
hash_data[key] = v
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
hash_data
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Xiaomi
|
2
|
+
module Push
|
3
|
+
module Message
|
4
|
+
class IOS < Base
|
5
|
+
attr_accessor :description, :badge, :sound, :category, :extras
|
6
|
+
def initialize(**params)
|
7
|
+
@description = params[:description]
|
8
|
+
@badge = params[:badge] || 1
|
9
|
+
@sound = params[:sound] || 'default'
|
10
|
+
@category = params[:category]
|
11
|
+
@extras = params[:extras] || {}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
File without changes
|
data/xiaomi-push.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'xiaomi/push/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "xiaomi-push"
|
8
|
+
spec.version = Xiaomi::Push::VERSION
|
9
|
+
spec.authors = ["icyleaf"]
|
10
|
+
spec.email = ["icyleaf.cn@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{MiPush Server SDK for Ruby}
|
13
|
+
spec.description = %q{MiPush Server SDK for Ruby}
|
14
|
+
spec.homepage = "http://github.com/icyleaf/xiaomi-push"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "rest-client", "~> 1.8.0"
|
21
|
+
spec.add_dependency "commander", "~> 4.3.2"
|
22
|
+
spec.add_dependency "multi_json", "~> 1.11.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "dotenv", "~> 2.0.1"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "awesome_print"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xiaomi-push
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- icyleaf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: commander
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.3.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.3.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.11.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.11.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.0.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: awesome_print
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: MiPush Server SDK for Ruby
|
126
|
+
email:
|
127
|
+
- icyleaf.cn@gmail.com
|
128
|
+
executables:
|
129
|
+
- xmp
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/xmp
|
140
|
+
- lib/xiaomi/push.rb
|
141
|
+
- lib/xiaomi/push/client.rb
|
142
|
+
- lib/xiaomi/push/const.rb
|
143
|
+
- lib/xiaomi/push/devices/android.rb
|
144
|
+
- lib/xiaomi/push/devices/ios.rb
|
145
|
+
- lib/xiaomi/push/error.rb
|
146
|
+
- lib/xiaomi/push/services/alias.rb
|
147
|
+
- lib/xiaomi/push/services/feedback.rb
|
148
|
+
- lib/xiaomi/push/services/message.rb
|
149
|
+
- lib/xiaomi/push/services/messages/android.rb
|
150
|
+
- lib/xiaomi/push/services/messages/base.rb
|
151
|
+
- lib/xiaomi/push/services/messages/ios.rb
|
152
|
+
- lib/xiaomi/push/services/multi_messages.rb
|
153
|
+
- lib/xiaomi/push/services/topic.rb
|
154
|
+
- lib/xiaomi/push/version.rb
|
155
|
+
- xiaomi-push.gemspec
|
156
|
+
homepage: http://github.com/icyleaf/xiaomi-push
|
157
|
+
licenses: []
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.4.3
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: MiPush Server SDK for Ruby
|
179
|
+
test_files: []
|