xiaomipush 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c0c9f3e0f9393d758a330e4e11ca8a337512847
4
+ data.tar.gz: 61d4be8a7a969470f9a4fcd82c4e27855caa5710
5
+ SHA512:
6
+ metadata.gz: ce2626451873c5f30666faca328ee0226762c4f517043ed3477257610b7637fb80c525dab67d23c3b57c32d010d08c50bdf56934afaf65095897179b667470fb
7
+ data.tar.gz: 226f4237258a0263207d5097e625f1a88bfc03c22d6bbc0a3ea66f5c8a1250b5c2940e9ceaeb2714abdb1ddf7938f7fd2ae4f4cc5a42da39bf95cdfd738c70c6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xiaomipush.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Xiaomipush
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/xiaomipush`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'xiaomipush'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install xiaomipush
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xiaomipush.
36
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "xiaomipush"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Xiaomipush
2
+ VERSION = "0.1.0"
3
+ end
data/lib/xiaomipush.rb ADDED
@@ -0,0 +1,99 @@
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'
11
+
12
+ module Xiaomipush
13
+ class Service
14
+
15
+ attr_accessor :ios_secret, :android_secret, :bundle_id, :package_name, :connection_adapter, :sandbox
16
+
17
+ def initialize(ios_secret: "", android_secret: "", bundle_id: "", package_name: "", connection_adapter: :net_http, sandbox: false)
18
+ @sandbox = sandbox
19
+ @ios_secret = ios_secret
20
+ @bundle_id = bundle_id
21
+ @android_secret = android_secret
22
+ @package_name = package_name
23
+ @connection_adapter = connection_adapter
24
+ end
25
+
26
+ def self.config
27
+ yield service = new; service
28
+ end
29
+
30
+ def build(build_type, message={})
31
+ case build_type
32
+ when :ios
33
+ build_message = { ios: ios_builder(message)}
34
+ when :android
35
+ build_message = { android: android_builder(message) }
36
+ when :both
37
+ build_message = { ios: ios_builder(message), android: android_builder(message)}
38
+ end
39
+ return build_message
40
+ end
41
+
42
+ def push(push_type, message, options={})
43
+ case push_type
44
+ when :alias
45
+ return "must input alias" unless options[:alias]
46
+ message.values.each{|v| v.merge!(alias: options[:alias])}
47
+ resource_post('alias', message)
48
+ when :regid
49
+ return "must input regid" unless options[:regid]
50
+ message.values.each{|v| v.merge!(regid: options[:regid])}
51
+ resource_post('regid', message)
52
+ when :topic
53
+ return "must input topic" unless options[:topic]
54
+ message.values.each{|v| v.merge!(topic: options[:topic])}
55
+ resource_post('topic', message)
56
+ when :topics
57
+ return "must input topics" unless options[:topics]
58
+ message.values.each{|v| v.merge!(topics: options[:topics].join(";$;"), topic_op: options[:topic_op] || "UNION")}
59
+ resource_post('mtopic', message)
60
+ # ws add
61
+ when :user_account
62
+ return "must input user_account" unless options[:user_account]
63
+ message.values.each{|v| v.merge!(user_account: options[:user_account].class.to_s == 'Array' ? options[:user_account].join(',') : options[:user_account])}
64
+ resource_post('user_account', message)
65
+ when :all
66
+ resource_post('all', message)
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def ios_builder(message={})
73
+ message[:restricted_package_name] = @bundle_id
74
+ IosBuilder.new(message).build
75
+ end
76
+
77
+ def android_builder(message={})
78
+ message[:restricted_package_name] = @package_name
79
+ AndroidBuilder.new(message).build
80
+ end
81
+
82
+ def ios_http
83
+ host = @sandbox ? Xiaomipush::XmResource::SANDBOX_DOMAIN : Xiaomipush::XmResource::OFFICIAL_DOMAIN
84
+ Xiaomipush::HttpBase.new(host, @ios_secret, @connection_adapter)
85
+ end
86
+
87
+ def android_http
88
+ # return "android don't support sandbox" if @sandbox
89
+ host = Xiaomipush::XmResource::OFFICIAL_DOMAIN
90
+ Xiaomipush::HttpBase.new(host, @android_secret, @connection_adapter)
91
+ end
92
+
93
+ def resource_post(name, message)
94
+ ios_http.post(Xiaomipush::XmResource.const_get("#{name.upcase}_URL"), message[:ios]) if message[:ios]
95
+ android_http.post(Xiaomipush::XmResource.const_get("#{name.upcase}_URL"), message[:android]) if message[:android]
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xiaomipush/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xiaomipush"
8
+ spec.version = Xiaomipush::VERSION
9
+ spec.authors = ["trycatch"]
10
+ spec.email = ["guoyoujin123@gmail.com"]
11
+ spec.summary = %q{XiaoMi push Ruby Server SDK.}
12
+ spec.description = %q{XiaoMi push Ruby Server SDK}
13
+ spec.homepage = "https://github.com/guoyoujin/xiaomipush"
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
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xiaomipush
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - trycatch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: XiaoMi push Ruby Server SDK
42
+ email:
43
+ - guoyoujin123@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - lib/xiaomipush.rb
55
+ - lib/xiaomipush/version.rb
56
+ - xiaomipush.gemspec
57
+ homepage: https://github.com/guoyoujin/xiaomipush
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.6.4
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: XiaoMi push Ruby Server SDK.
81
+ test_files: []