xiaomipush 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfc510fb762f7a870fc2f342abbb91c79b241a10
4
- data.tar.gz: 83b228adaad2f3d99ab50aa1d49a61b5687f81b0
3
+ metadata.gz: 9e48479e9939e0d417747f7be63bb4bb3ccfcb8e
4
+ data.tar.gz: e716f4a66309356cb7781fd3db0853a7c5449609
5
5
  SHA512:
6
- metadata.gz: d219e015a3248ab9660307faa2c4cf41c15ddb8bfd19f6fe59af5c26ff5c5cda49f3e6863ac8d91f3113ddc4c35a2fb1a782e4baa371e89efdbfdbb6ca9b5205
7
- data.tar.gz: 6ce6af62bddc5a07316230acbd38653e33fb7415a6c30a757a9f4e46cb62bcc7061b4dd19f3ca8e88197e25f0964d5292f51afa297bc02c1402bf87ebdee73b2
6
+ metadata.gz: 2f154bfc9a36b4b25c9ef7f303bedc18cec07c32dd9aa792a48f5739d4ecfd115fd0d67bbb4f0bb66ea82f56839d2b92f17d0dfb403f05d3f0583345d9065d58
7
+ data.tar.gz: c9a916ec10e361f37fe01a8e83b04ee69a32b4c05ae3af82bbf9de8f659c5e56fa5412a2c93a95356bfdb9075ca5651fdb445acdbcb55a2de6f783ab7bce9c68
data/README.md CHANGED
@@ -21,7 +21,39 @@ Or install it yourself as:
21
21
  $ gem install xiaomipush
22
22
 
23
23
  ## Usage
24
+ ```ruby
25
+ Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }
26
+ @xiaomipush_service = Xiaomipush::Service.config do |s|
27
+ s.sandbox = false # default false
28
+ s.ios_secret = "ios secret key"
29
+ s.bundle_id = "com.xxx.ios"
30
+ s.android_secret = 'android secret key'
31
+ s.package_name = "io.mdrtwell.mipushdemo"
32
+ s.connection_adapter = :net_http # default
33
+ end
34
+ # just iOS
35
+ @message1 = @xiaomipush_service.build(:ios, description: 'hello')
36
+ @xiaomipush_service.push(:all, @message1)
37
+
38
+ @message2 = @xiaomipush_service.build(:ios, description: 'hello alias', extra: {pid: 111})
39
+ @xiaomipush_service.push(:alias, @message2, alias: '1043478')
40
+
41
+ @message3 = @xiaomipush_service.build(:ios, description: 'hello topic', extra: {pid: 111})
42
+ @xiaomipush_service.push(:topic, @message2, topic: 'all')
43
+
44
+ #multi_topic
45
+ @message3 = @xiaomipush_service.build(:ios, description: 'hello topic', extra: {pid: 111})
46
+ @xiaomipush_service.push(:topics, @message2, topics: ['all', "other"])
47
+
48
+ # iOS and Android
49
+ @message3 = @xiaomipush_service.build(:both, title: "I'm title", description: 'push to iOS and Android client')
50
+ @xiaomipush_service.push(:all, @message3)
51
+
52
+ #user_account (推送到指定用户id格式为单个"1234",多个"1234,12345,123456")
53
+ handle_message = @xiaomipush_service.build(:android, title: "【你好测试", description: "测试", notify_id: 0, :pass_through => "jsdnnsd", extra:{notify_effect: 1, intent_uri: 'com.test.SplashActivity'})
54
+ result = @xiaomipush_service.push(:user_account, handle_message, user_account: "123456")
24
55
 
56
+ ```
25
57
  TODO: Write usage instructions here
26
58
 
27
59
  ## Development
@@ -32,5 +64,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
64
 
33
65
  ## Contributing
34
66
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xiaomipush.
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/guoyoujin/xiaomipush.
36
68
 
@@ -1,13 +1,13 @@
1
- require './lib/xiaomipush/xm_resources'
2
- require './lib/xiaomipush/http_base'
3
- require './lib/xiaomipush/message'
4
- require './lib/xiaomipush/android_builder'
5
- require './lib/xiaomipush/ios_builder'
6
- require './lib/xiaomipush/targeted_message'
7
- require './lib/xiaomipush/stats'
8
- require './lib/xiaomipush/subscription'
9
- require './lib/xiaomipush/tracer'
10
- require './lib/xiaomipush/feedback'
1
+ require 'xiaomipush/xm_resources'
2
+ require 'xiaomipush/http_base'
3
+ require 'xiaomipush/message'
4
+ require 'xiaomipush/android_builder'
5
+ require 'xiaomipush/ios_builder'
6
+ require 'xiaomipush/targeted_message'
7
+ require 'xiaomipush/stats'
8
+ require 'xiaomipush/subscription'
9
+ require 'xiaomipush/tracer'
10
+ require 'xiaomipush/feedback'
11
11
 
12
12
  module Xiaomipush
13
13
  class Service
@@ -0,0 +1,44 @@
1
+ module Xiaomipush
2
+ class AndroidBuilder < Message
3
+
4
+ # 设置通知类型
5
+ NOTIFY_TYPE_DEFAULT_ALL = -1
6
+ NOTIFY_TYPE_DEFAULT_SOUND = 1 # 使用默认提示音提示
7
+ NOTIFY_TYPE_DEFAULT_VIBRATE = 2 # 使用默认震动提示
8
+ NOTIFY_TYPE_DEFAULT_LIGHTS = 4 # 使用默认led灯光提示
9
+
10
+ NTF_CENTER_NTF = 0 # 通知栏消息
11
+ PASS_THROUGH_NTF = 1 # 透传消息
12
+
13
+ attr_accessor :pass_through, :notify_id, :sound_url
14
+
15
+ def initialize(**message)
16
+ super(message)
17
+ puts "======> send push message====>: #{message.inspect}"
18
+ extra = message.delete(:extra) if message[:extra]
19
+ @pass_through = message[:pass_through] || NTF_CENTER_NTF
20
+ @notify_id = message[:notify_id] || 0
21
+ @notify_type = message[:notify_type] || NOTIFY_TYPE_DEFAULT_ALL
22
+ extra_message = {sound_url: ""}
23
+ extra_message.merge!(extra) if extra
24
+ @extra = extra_message
25
+ end
26
+
27
+ def build
28
+ extra_message = extra(@extra) if @extra
29
+ message = {
30
+ payload: @payload,
31
+ title: @title,
32
+ notify_id: @notify_id,
33
+ pass_through: @pass_through,
34
+ notify_type: @notify_type,
35
+ restricted_package_name: @restricted_package_name,
36
+ description: @description
37
+ }
38
+ message.merge!(extra_message)
39
+ puts "======> send push message_merge====>: #{message.inspect}"
40
+ return message
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module Xiaomipush
2
+ class Feedback < HttpBase
3
+
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'net/http'
2
+ require 'faraday'
3
+
4
+ module Xiaomipush
5
+ class HttpBase
6
+ attr_accessor :secret_key, :url, :host
7
+
8
+ def initialize(host="", secret_key="", connection_adapter = :net_http, headers={})
9
+ @host = host
10
+ @secret_key = secret_key
11
+ @connection_adapter = connection_adapter
12
+ @headers = headers
13
+ end
14
+
15
+ def post(url, body={}); conn.post url, body end
16
+ def get(url, params={}); conn.get url, params end
17
+
18
+ def conn
19
+ headers = {authorization: "key=#{@secret_key}"}.merge(@headers)
20
+ Faraday.new(:url => @host, :headers => headers) do |faraday|
21
+ faraday.request :url_encoded
22
+ # faraday.response :logger
23
+ faraday.options.timeout = 5 # open/read timeout in seconds
24
+ faraday.options.open_timeout = 2 # connection open timeout in seconds
25
+ faraday.adapter @connection_adapter
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ module Xiaomipush
2
+ class IosBuilder < Message
3
+ attr_accessor :sound_url, :badge
4
+
5
+ def initialize(**message)
6
+ super(message)
7
+ extra = message.delete(:extra) if message[:extra]
8
+ extra_message = {sound_url: "", badge: 1}
9
+ extra_message.merge!(extra) if extra
10
+ @extra = extra_message
11
+ end
12
+
13
+ def build
14
+ extra_message = extra(@extra) if @extra
15
+ message = {
16
+ restricted_package_name: @restricted_package_name,
17
+ description: @description
18
+ }
19
+ message.merge!(extra_message)
20
+ return message
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module Xiaomipush
2
+ class Message
3
+ EXTRA_PREFIX = 'extra.'
4
+ attr_accessor :payload, :title, :description, :time_to_live, :time_to_send, :extra, :notify_type, :restricted_package_name
5
+
6
+ # ws add
7
+ # pass_through: '' notify_id: 0
8
+ def initialize(payload: "", restricted_package_name: "", title: "", description: "", time_to_live: "", time_to_send: "", extra: "", notify_type: "", pass_through: '', notify_id: 0)
9
+ @payload = payload
10
+ @restricted_package_name = restricted_package_name
11
+ @title = title
12
+ @description = description
13
+ @time_to_live = time_to_live
14
+ @time_to_send = time_to_send
15
+ @extra = extra
16
+ @notify_type = notify_type
17
+ end
18
+
19
+ def extra(options={})
20
+ options.keys.inject({}) do |h, key|
21
+ h["#{EXTRA_PREFIX}#{key}"] = options.delete(key); h
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Xiaomipush
2
+ class Stats < HttpBase
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Xiaomipush
2
+ class Subscription < HttpBase
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Xiaomipush
2
+ class TargetedMessage < Message
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Xiaomipush
2
+ class Tracer < HttpBase
3
+
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Xiaomipush
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -0,0 +1,38 @@
1
+ module Xiaomipush
2
+ class XmResource
3
+
4
+ # Xiaomipush::XmResource::OFFICIAL_DOMAIN
5
+
6
+ OFFICIAL_DOMAIN = "https://api.xmpush.xiaomi.com"
7
+ SANDBOX_DOMAIN = "https://sandbox.xmpush.xiaomi.com"
8
+ REG_URL = "/v2/message/regid"
9
+ ALIAS_URL = "/v2/message/alias"
10
+ TOPIC_URL = "/v2/message/topic"
11
+ MTOPIC_URL = "/v2/message/multi_topic"
12
+
13
+ # ws add
14
+ USER_ACCOUNT_URL = "/v2/message/user_account"
15
+
16
+ ALL_URL = "/v2/message/all"
17
+
18
+ SUBSCRIBE_URL= "/v2/topic/subscribe"
19
+ UNSUBSCRIBE_URL = "/v2/topic/unsubscribe"
20
+
21
+ MMREG_URL = "/v2/multi_messages/regids"
22
+ MMALIAS_URL = "/v2/multi_messages/aliases"
23
+
24
+ STATS_URL = '/v1/stats/message/counters'
25
+ TRACE_URL = '/v1/trace/message/status'
26
+ TRACES_URL = '/v1/trace/messages/status'
27
+ VALIDATE_REGIDS = '/v1/validation/regids'
28
+
29
+
30
+ FETCH_INVALID_REGIDS_URL = "https://feedback.xmpush.xiaomi.com/v1/feedback/fetch_invalid_regids"
31
+
32
+ UNION = 'UNION'
33
+ INTERSECTION = 'INTERSECTION'
34
+ EXCEPT = 'EXCEPT'
35
+
36
+
37
+ end
38
+ end
data/test.rb ADDED
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }
4
+ @xiaomipush_service = Xiaomipush::Service.config do |s|
5
+ s.sandbox = false # default false
6
+ s.ios_secret = "ios secret key"
7
+ s.bundle_id = "com.xxx.ios"
8
+ s.android_secret = 'android secret key'
9
+ s.package_name = "io.mdrtwell.mipushdemo"
10
+ s.connection_adapter = :net_http # default
11
+ end
12
+ # just iOS
13
+ @message1 = @xiaomipush_service.build(:ios, description: 'hello')
14
+ @xiaomipush_service.push(:all, @message1)
15
+
16
+ @message2 = @xiaomipush_service.build(:ios, description: 'hello alias', extra: {pid: 111})
17
+ @xiaomipush_service.push(:alias, @message2, alias: '1043478')
18
+
19
+ @message3 = @xiaomipush_service.build(:ios, description: 'hello topic', extra: {pid: 111})
20
+ @xiaomipush_service.push(:topic, @message2, topic: 'all')
21
+
22
+ #multi_topic
23
+ @message3 = @xiaomipush_service.build(:ios, description: 'hello topic', extra: {pid: 111})
24
+ @xiaomipush_service.push(:topics, @message2, topics: ['all', "other"])
25
+
26
+ # iOS and Android
27
+ @message3 = @xiaomipush_service.build(:both, title: "I'm title", description: 'push to iOS and Android client')
28
+ @xiaomipush_service.push(:all, @message3)
29
+
30
+ #user_account (推送到指定用户id格式为单个"1234",多个"1234,12345,123456")
31
+ handle_message = @xiaomipush_service.build(:android, title: "【你好测试", description: "测试", notify_id: 0, :pass_through => "jsdnnsd", extra:{notify_effect: 1, intent_uri: 'com.test.SplashActivity'})
32
+ result = @xiaomipush_service.push(:user_account, handle_message, user_account: "123456")
@@ -12,21 +12,11 @@ Gem::Specification.new do |spec|
12
12
  spec.description = %q{XiaoMi push Ruby Server SDK}
13
13
  spec.homepage = "https://github.com/guoyoujin/xiaomipush"
14
14
  spec.license = "MIT"
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- # if spec.respond_to?(:metadata)
19
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- # else
21
- # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- # end
23
-
24
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
16
  spec.bindir = "exe"
26
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
18
  spec.require_paths = ["lib"]
28
19
  spec.add_runtime_dependency 'faraday'
29
- spec.add_runtime_dependency 'http'
30
20
  spec.add_development_dependency "bundler", "~> 1.12"
31
21
  spec.add_development_dependency "rake", "~> 10.0"
32
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xiaomipush
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - trycatch
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: http
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +66,18 @@ files:
80
66
  - bin/console
81
67
  - bin/setup
82
68
  - lib/xiaomipush.rb
69
+ - lib/xiaomipush/android_builder.rb
70
+ - lib/xiaomipush/feedback.rb
71
+ - lib/xiaomipush/http_base.rb
72
+ - lib/xiaomipush/ios_builder.rb
73
+ - lib/xiaomipush/message.rb
74
+ - lib/xiaomipush/stats.rb
75
+ - lib/xiaomipush/subscription.rb
76
+ - lib/xiaomipush/targeted_message.rb
77
+ - lib/xiaomipush/tracer.rb
83
78
  - lib/xiaomipush/version.rb
79
+ - lib/xiaomipush/xm_resources.rb
80
+ - test.rb
84
81
  - xiaomipush.gemspec
85
82
  homepage: https://github.com/guoyoujin/xiaomipush
86
83
  licenses: