xiaomi-push 0.2.1 → 0.2.3

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: f4e4e4b7206faa062c6cdff0317ce6674ea592b4
4
- data.tar.gz: a2897ab8748cf253814c4d6af1f6d57648ff32f1
3
+ metadata.gz: 596215b9db023ba5ed57ecdb279b08227b7c181d
4
+ data.tar.gz: d404409f70e5b628360cb926ba0229cff4a2a10e
5
5
  SHA512:
6
- metadata.gz: cd77e0742cc5f77551e6944075a5ad28378f37788b309db01a24dda27be99e08fac2bec8c60b9f566cdf6359b8c2b197a2891d4a256f819b5090ca0fc0690502
7
- data.tar.gz: de4b39e37ab848e9af9799cb6820937a1fd9438d52151f4c6ea1ce9858d9bf694344dcfdeccbe24d03c5ff6ee63b6ef0ba5d6cfbc7f2366343aa949c7e67df42
6
+ metadata.gz: 2c5ca54678cff7b74bbc93d8c9d8a90c9de3d7c1c61999caca6425f0dc299023766456a39e5de5af2da691e6e2c8cd5178c73f2e748a2dc0787fcff86dafea72
7
+ data.tar.gz: 99cf5f458eb925cea7b54e09fe411d648dfcee67ce5f041579383bc6c65be04b789ea0b7622251962b0be9fbdb2003efb5aac780b9662c4f39f64d7949cc8c11
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
+ # source 'https://gems.ruby-china.org'
2
3
 
3
4
  # Specify your gem's dependencies in xiaomi-push.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  非官方小米推送服务端 Ruby SDK
2
2
  =============================
3
3
 
4
+ > 小米官方好像也就不怎么维护此服务,本 gem 除了修复问题以为不做新特性的更新。
5
+
4
6
  官方文档: http://dev.xiaomi.com/doc/?p=533#d5e725
5
7
 
6
8
  TL;DR
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
  require 'dotenv/tasks'
4
- require 'awesome_print'
5
4
 
6
5
  # $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
7
6
 
@@ -9,49 +8,49 @@ require 'xiaomi/push'
9
8
 
10
9
  RSpec::Core::RakeTask.new(:spec)
11
10
 
12
- task :default => :spec
13
-
14
- task :send => :dotenv do
11
+ task default: :spec
15
12
 
13
+ task send: :dotenv do
16
14
  message = {
17
15
  title: '这是标题',
18
16
  description: '这个是推送的描述',
19
- notify_type: -1,
17
+ notify_type: -1
20
18
  }
19
+
21
20
  client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
22
21
 
23
- p "Send message to android device"
24
- client.message.send(reg_id:'', message:message)
25
- r = client.message.send(alias:'866383029998732', message:message)
26
- r = client.message.send(topic:'test', message:message)
27
- ap r
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
28
27
 
29
- p "Send message to ios device"
28
+ p 'Send message to ios device'
30
29
  client = Xiaomi::Push::IOS.new(ENV['XIAOMI_PUSH_IOS_SECRET'])
31
30
  r = client.message.send(
32
- reg_id:'xksdf76s667687xd786sdxsdf689s6x6s8d76s8d',
33
- message:Xiaomi::Push::Message::IOS.new(
34
- description:'这不是描述'
31
+ reg_id: 'xksdf76s667687xd786sdxsdf689s6x6s8d76s8d',
32
+ message: Xiaomi::Push::Message::IOS.new(
33
+ description: '这不是描述'
35
34
  ))
36
- ap r
35
+ puts r
37
36
  end
38
37
 
39
38
  namespace :topic do
40
- task :subscribe => :dotenv do
39
+ task subscribe: :dotenv do
41
40
  client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
42
- r = client.topic.subscribe(alias:'866383029998732', name:'test')
41
+ r = client.topic.subscribe(alias: '866383029998732', name: 'test')
43
42
  ap r
44
43
  end
45
44
 
46
- task :unsubscribe => :dotenv do
45
+ task unsubscribe: :dotenv do
47
46
  client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
48
- r = client.topic.unsubscribe(alias:'866383029998732', name:'test')
47
+ r = client.topic.unsubscribe(alias: '866383029998732', name: 'test')
49
48
  ap r
50
49
  end
51
50
  end
52
51
 
53
52
  task :message do
54
- ios_message = Xiaomi::Push::Message::IOS.new(title:'dddd')
53
+ ios_message = Xiaomi::Push::Message::IOS.new(title: 'dddd')
55
54
  ios_message.extra('url', 'http://www.xxx.com')
56
55
  p ios_message
57
56
 
@@ -61,5 +60,5 @@ end
61
60
  task :feedback do
62
61
  client = Xiaomi::Push::Android.new(ENV['XIAOMI_PUSH_ANDROID_SECRET'])
63
62
  r = client.feedback.invalid
64
- ap r
63
+ puts r
65
64
  end
data/bin/xmp CHANGED
@@ -2,10 +2,8 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'commander/import'
5
- require "bundler/setup"
6
- require "xiaomi/push"
7
- require "awesome_print"
8
-
5
+ require 'bundler/setup'
6
+ require 'xiaomi/push'
9
7
 
10
8
  program :version, Xiaomi::Push::VERSION
11
9
  program :description, 'xiaomi push command line tool'
@@ -1,22 +1,16 @@
1
- require "xiaomi/push/version"
2
- require "xiaomi/push/error"
3
- require "xiaomi/push/const"
4
- require "xiaomi/push/client"
1
+ require 'xiaomi/push/version'
2
+ require 'xiaomi/push/error'
3
+ require 'xiaomi/push/const'
4
+ require 'xiaomi/push/client'
5
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/feedback"
6
+ require 'xiaomi/push/devices/ios'
7
+ require 'xiaomi/push/devices/android'
12
8
 
9
+ require 'xiaomi/push/services/message'
10
+ require 'xiaomi/push/services/topic'
11
+ require 'xiaomi/push/services/feedback'
13
12
 
14
13
  unless defined?(Dotenv)
15
14
  require 'dotenv'
16
15
  Dotenv.load
17
16
  end
18
-
19
- module Xiaomi
20
- module Push
21
- end
22
- end
@@ -8,7 +8,7 @@ module Xiaomi
8
8
 
9
9
  attr_reader :device, :secret, :header
10
10
  def initialize(secret)
11
- @device = self.class.name.split("::")[-1].upcase
11
+ @device = self.class.name.split('::')[-1].upcase
12
12
  @secret = secret
13
13
 
14
14
  unless DEVICES.include?@device
@@ -34,12 +34,10 @@ module Xiaomi
34
34
  @feedback ||= Services::Feedback.new(self)
35
35
  end
36
36
 
37
-
38
37
  def request(url, params)
39
38
  r = RestClient.post url, params, @header
40
39
  data = MultiJson.load r
41
40
  end
42
-
43
41
  end
44
42
  end
45
43
  end
@@ -1,2 +1,7 @@
1
- # require 'xiaomi/push/commands/message'
1
+ require 'xiaomi/push/commands/message'
2
2
  require 'xiaomi/push/commands/feedback'
3
+
4
+ unless defined?(Dotenv)
5
+ require 'dotenv'
6
+ Dotenv.load
7
+ end
@@ -4,11 +4,11 @@ command :feedback do |c|
4
4
  c.description = ''
5
5
 
6
6
  # normal params
7
- c.option '--device DEVICE', ['android', 'ios'], '设备类型'
7
+ c.option '--device DEVICE', %w('android', 'ios'), '设备类型'
8
8
  c.option '--secret SECRET', '应用密钥'
9
9
 
10
10
  c.action do |args, options|
11
- ap options if $verbose
11
+ puts options if $verbose
12
12
 
13
13
  @device = options.device.capitalize if options.device
14
14
  @secret = options.secret
@@ -21,19 +21,19 @@ command :feedback do |c|
21
21
 
22
22
  private
23
23
 
24
- def feedback!
25
- client = Xiaomi::Push.const_get(@device).new(@secret)
26
- r = client.feedback.invalid
24
+ def feedback!
25
+ client = Xiaomi::Push.const_get(@device).new(@secret)
26
+ r = client.feedback.invalid
27
27
 
28
- ap r
29
- end
28
+ puts r
29
+ end
30
30
 
31
- def determine_device!
32
- devices = %w[Android iOS].freeze
33
- @device = choose "选择推送设备:", *devices
34
- end
31
+ def determine_device!
32
+ devices = %w(Android iOS).freeze
33
+ @device = choose "选择推送设备:", *devices
34
+ end
35
35
 
36
- def determine_secret!
37
- @secret ||= ask '小米应用密钥:'
38
- end
36
+ def determine_secret!
37
+ @secret ||= ask '小米应用密钥:'
38
+ end
39
39
  end
@@ -4,7 +4,7 @@ command :message do |c|
4
4
  c.description = '使用小米推送消息(目前仅支持 regid/alias/topic 推送方式)'
5
5
 
6
6
  # normal params
7
- c.option '--device DEVICE', ['android', 'ios'], '设备类型'
7
+ c.option '--device DEVICE', %w('android', 'ios'), '设备类型'
8
8
  c.option '--secret SECRET', '应用密钥'
9
9
 
10
10
  # type
@@ -18,16 +18,8 @@ command :message do |c|
18
18
  c.option '-b', '--badge BADGE', Integer, '消息数字'
19
19
  c.option '-e', '--extras KEY=VALUE', Array, '自定义数据(使用 KEY=VALUE 方式,多个以逗号不带空格分隔)'
20
20
 
21
- # ## ios only
22
- # c.option '-y', '--category CATEGORY', '推送类别名称 (仅 iOS 有效)'
23
- # c.option '-v', '--environment ENV', [:production, :sandbox], '推送环境(仅 iOS 有效)'
24
- #
25
- # ## android only
26
- # c.option '-g', '--through THROUGHT', [0, 1], '消息传递方式(仅 iOS 有效)'
27
- # c.option '-n', '--notify NOTIFY', [-1, 1, 2, 4], 'message notify type'
28
-
29
21
  c.action do |args, options|
30
- ap options if $verbose
22
+ puts options if $verbose
31
23
 
32
24
  @device = options.device.capitalize if options.device
33
25
  @secret = options.secret
@@ -43,78 +35,78 @@ command :message do |c|
43
35
 
44
36
  private
45
37
 
46
- def sent!
47
- message_data = {
48
- @channel.to_sym => @channel_id,
49
- :message => @message,
50
- }
38
+ def sent!
39
+ message_data = {
40
+ @channel.to_sym => @channel_id,
41
+ :message => @message
42
+ }
51
43
 
52
- if $verbose
53
- ap message_data
54
- end
44
+ if $verbose
45
+ puts message_data
46
+ end
55
47
 
56
- client = Xiaomi::Push.const_get(@device).new(@secret)
57
- r = client.message.send(message_data)
48
+ client = Xiaomi::Push.const_get(@device).new(@secret)
49
+ r = client.message.send(message_data)
58
50
 
59
- ap r
60
- end
51
+ puts r
52
+ end
61
53
 
62
- def determine_android_message!(options)
63
- @message = Xiaomi::Push::Message::Android.new(
64
- title: @title,
65
- description: @description,
66
- badge: @badge,
67
- extras: @extras
68
- )
69
- end
54
+ def determine_android_message!(options)
55
+ @message = Xiaomi::Push::Message::Android.new(
56
+ title: @title,
57
+ description: @description,
58
+ badge: @badge,
59
+ extras: @extras
60
+ )
61
+ end
70
62
 
71
- def determine_ios_message!(options)
72
- @message = Xiaomi::Push::Message::IOS.new(
73
- description: @description,
74
- badge: @badge,
75
- extras: @extras
76
- )
77
- end
63
+ def determine_ios_message!(options)
64
+ @message = Xiaomi::Push::Message::IOS.new(
65
+ description: @description,
66
+ badge: @badge,
67
+ extras: @extras
68
+ )
69
+ end
78
70
 
79
- def determine_message!(options)
80
- @title = options.title
81
- @description = options.description
82
- @badge = options.badge
71
+ def determine_message!(options)
72
+ @title = options.title
73
+ @description = options.description
74
+ @badge = options.badge
83
75
 
84
- @extras = if options.extras
85
- Hash[options.extras.collect{|data| data.split(/\=/)}]
76
+ @extras =
77
+ if options.extras
78
+ Hash[options.extras.collect { |data| data.split(/\=/) }]
86
79
  else
87
80
  nil
88
81
  end
89
82
 
90
- case @device.downcase
91
- when 'android'
92
- determine_android_message!(options)
93
- when 'ios'
94
- determine_ios_message!(options)
95
- end
96
- end
97
-
98
- def determine_device!
99
- devices = %w[Android iOS].freeze
100
- @device = choose "选择推送设备:", *devices
83
+ case @device.downcase
84
+ when 'android'
85
+ determine_android_message!(options)
86
+ when 'ios'
87
+ determine_ios_message!(options)
101
88
  end
89
+ end
102
90
 
103
- def determine_secret!
104
- @secret ||= ask '小米应用密钥:'
105
- end
91
+ def determine_device!
92
+ devices = %w(Android iOS).freeze
93
+ @device = choose "选择推送设备:", *devices
94
+ end
106
95
 
107
- def determine_channel!(options)
108
- channles = %w[regid alias topic].freeze
109
- @channel = channles.select { |k| options.__hash__.has_key?k.to_sym }
96
+ def determine_secret!
97
+ @secret ||= ask '小米应用密钥:'
98
+ end
110
99
 
111
- unless @channel.count > 0
112
- @channel = choose "选择推送方式:", *channles
100
+ def determine_channel!(options)
101
+ channles = %w(regid alias topic).freeze
102
+ @channel = channles.select { |k| options.__hash__.key?k.to_sym }
113
103
 
114
- @channel_id = ask "输入 #{@channel} 的值:"
115
- else
116
- @channel = @channel[0]
117
- @channel_id = options.__hash__[@channel.to_sym]
118
- end
104
+ if @channel.count > 0
105
+ @channel = @channel[0]
106
+ @channel_id = options.__hash__[@channel.to_sym]
107
+ else
108
+ @channel = choose "选择推送方式:", *channles
109
+ @channel_id = ask "输入 #{@channel} 的值:"
119
110
  end
111
+ end
120
112
  end
@@ -1,13 +1,12 @@
1
1
  require 'uri'
2
2
 
3
-
4
3
  module Xiaomi
5
4
  module Push
6
5
  module Const
7
- DEVICES = %w[ANDROID IOS].freeze
6
+ DEVICES = %w(ANDROID IOS).freeze
8
7
 
9
- PRODUCTION_URL = 'https://api.xmpush.xiaomi.com'
10
- SANDBOX_URL = 'https://sandbox.xmpush.xiaomi.com'
8
+ PRODUCTION_URL = 'https://api.xmpush.xiaomi.com'.freeze
9
+ SANDBOX_URL = 'https://sandbox.xmpush.xiaomi.com'.freeze
11
10
 
12
11
  attr_reader :base_url
13
12
 
@@ -28,7 +27,7 @@ module Xiaomi
28
27
  end
29
28
 
30
29
  def build_uri(uri)
31
- URI::join(@base_url, "v2/#{uri}").to_s
30
+ URI.join(@base_url, "v2/#{uri}").to_s
32
31
  end
33
32
  end
34
33
  end
@@ -1,11 +1,9 @@
1
1
  module Xiaomi
2
2
  module Push
3
3
  class IOS < Xiaomi::Push::Client
4
-
5
4
  end
6
5
 
7
6
  class Ios < Xiaomi::Push::Client
8
-
9
7
  end
10
8
  end
11
9
  end
@@ -5,7 +5,6 @@ module Xiaomi
5
5
  end
6
6
 
7
7
  class RequestError < Xiaomi::Push::Error
8
-
9
8
  end
10
9
 
11
10
  class FailuresError < Xiaomi::Push::Error
@@ -2,7 +2,6 @@ module Xiaomi
2
2
  module Push
3
3
  module Services
4
4
  class Feedback
5
-
6
5
  attr_reader :context
7
6
 
8
7
  def initialize(context)
@@ -12,7 +11,7 @@ module Xiaomi
12
11
  def invalid
13
12
  url = 'https://feedback.xmpush.xiaomi.com/v1/feedback/fetch_invalid_regids'
14
13
  r = RestClient.get url, @context.header
15
- data = MultiJson.load r
14
+ MultiJson.load r
16
15
  end
17
16
  end
18
17
  end
@@ -15,28 +15,28 @@ module Xiaomi
15
15
  def type(key, value = nil)
16
16
  key = "@#{key}"
17
17
 
18
- unless value
19
- instance_variable_get key
20
- else
18
+ if value
21
19
  instance_variable_set key, value
20
+ else
21
+ instance_variable_get key
22
22
  end
23
23
  end
24
24
 
25
25
  def build
26
26
  hash_data = {}
27
27
  instance_variables.each do |ivar|
28
- key = ivar.to_s.gsub('@', '')
28
+ key = ivar.to_s.delete('@', '')
29
29
  value = instance_variable_get ivar
30
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
31
+ next unless value
32
+
33
+ if key == 'extras'
34
+ value.each do |k, v|
35
+ key = "extra.#{k}"
36
+ hash_data[key] = v
39
37
  end
38
+ else
39
+ hash_data[key] = value
40
40
  end
41
41
  end
42
42
 
@@ -9,34 +9,35 @@ module Xiaomi
9
9
 
10
10
  def subscribe(**options)
11
11
  url, params = prepare_params(__method__.to_s, options)
12
- data = @context.request url, params
12
+ @context.request url, params
13
13
  end
14
14
 
15
15
  def unsubscribe(**options)
16
16
  url, params = prepare_params(__method__.to_s, options)
17
- data = @context.request url, params
17
+ @context.request url, params
18
18
  end
19
19
 
20
20
  private
21
- def prepare_params(uri, options)
22
- if options.has_key?(:reg_id)
23
- type = "registration_id"
24
- value = options[:reg_id]
25
- url = @context.build_uri("topic/#{uri}")
26
- elsif options.has_key?(:alias)
27
- type = "aliases"
28
- value = options[:alias]
29
- url = @context.build_uri("topic/#{uri}/alias")
30
- end
31
21
 
32
- params = {
33
- type.to_sym => value,
34
- :topic => options[:name],
35
- :category => options[:category],
36
- }
37
-
38
- [url, params]
22
+ def prepare_params(uri, options)
23
+ if options.key?(:reg_id)
24
+ type = 'registration_id'
25
+ value = options[:reg_id]
26
+ url = @context.build_uri("topic/#{uri}")
27
+ elsif options.key?(:alias)
28
+ type = 'aliases'
29
+ value = options[:alias]
30
+ url = @context.build_uri("topic/#{uri}/alias")
39
31
  end
32
+
33
+ params = {
34
+ type.to_sym => value,
35
+ :topic => options[:name],
36
+ :category => options[:category]
37
+ }
38
+
39
+ [url, params]
40
+ end
40
41
  end
41
42
  end
42
43
  end
@@ -1,5 +1,5 @@
1
1
  module Xiaomi
2
2
  module Push
3
- VERSION = "0.2.1"
3
+ VERSION = '0.2.3'
4
4
  end
5
5
  end
@@ -4,26 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'xiaomi/push/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "xiaomi-push"
7
+ spec.name = 'xiaomi-push'
8
8
  spec.version = Xiaomi::Push::VERSION
9
- spec.authors = ["icyleaf"]
10
- spec.email = ["icyleaf.cn@gmail.com"]
9
+ spec.authors = ['icyleaf']
10
+ spec.email = ['icyleaf.cn@gmail.com']
11
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"
12
+ spec.summary = 'MiPush Server SDK for Ruby'
13
+ spec.description = 'MiPush Server SDK for Ruby'
14
+ spec.homepage = 'http://github.com/icyleaf/xiaomi-push'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency "rest-client", ">= 1.7.3"
21
- spec.add_dependency "commander", "~> 4.3.2"
22
- spec.add_dependency "multi_json", "~> 1.11.0"
20
+ spec.add_dependency 'rest-client', '>= 1.7.3'
21
+ spec.add_dependency 'commander', '~> 4.3.2'
22
+ spec.add_dependency 'multi_json', '~> 1.11.0'
23
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"
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
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xiaomi-push
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - icyleaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.4.7
177
+ rubygems_version: 2.6.4
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: MiPush Server SDK for Ruby