aliyun-cloudpush 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/aliyun-cloudpush.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/aliyun/cloudpush/client.rb +67 -0
- data/lib/aliyun/cloudpush/config.rb +31 -0
- data/lib/aliyun/cloudpush/version.rb +5 -0
- data/lib/aliyun/cloudpush.rb +9 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 445f13f3637f1f66845f3bfc0e7a22895f083546
|
4
|
+
data.tar.gz: fc864093550ab09d1433682226caa652a7077b99
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 660f8b7dc155244806e595e93b5fadc06be0fd2d397a03f1930228e0427bf70ead3b50ab16ce3f94a3349e68c885c4a4c3e27385162ffde62839385138c01a38
|
7
|
+
data.tar.gz: fa8437ab636230d35e859ca8269af7657ff5f63feb954be2f459e0d7251b32d1a980c0f4080a1ed3a64c1f4598975506aa2c3c39baf7d6595dfc0f6f97f962d9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aliyun-cloudpush (0.1.0)
|
5
|
+
rest-client (~> 2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
domain_name (0.5.20170404)
|
12
|
+
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
http-cookie (1.0.3)
|
14
|
+
domain_name (~> 0.5)
|
15
|
+
mime-types (3.1)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2016.0521)
|
18
|
+
netrc (0.11.0)
|
19
|
+
rake (10.5.0)
|
20
|
+
rest-client (2.0.2)
|
21
|
+
http-cookie (>= 1.0.2, < 2.0)
|
22
|
+
mime-types (>= 1.16, < 4.0)
|
23
|
+
netrc (~> 0.8)
|
24
|
+
rspec (3.7.0)
|
25
|
+
rspec-core (~> 3.7.0)
|
26
|
+
rspec-expectations (~> 3.7.0)
|
27
|
+
rspec-mocks (~> 3.7.0)
|
28
|
+
rspec-core (3.7.1)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-expectations (3.7.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-mocks (3.7.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.7.0)
|
36
|
+
rspec-support (3.7.1)
|
37
|
+
unf (0.1.4)
|
38
|
+
unf_ext
|
39
|
+
unf_ext (0.0.7.5)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
aliyun-cloudpush!
|
46
|
+
bundler (~> 1.16)
|
47
|
+
rake (~> 10.0)
|
48
|
+
rspec (~> 3.0)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jeff Lai
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Aliyun::Cloudpush
|
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/aliyun/cloudpush`. 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 'aliyun-cloudpush'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install aliyun-cloudpush
|
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. Then, run `rake spec` to run the tests. 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]/aliyun-cloudpush.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "aliyun/cloudpush/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aliyun-cloudpush"
|
8
|
+
spec.version = Aliyun::Cloudpush::VERSION
|
9
|
+
spec.authors = ["Jeff Lai"]
|
10
|
+
spec.email = ["winfield301@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{aliyun cloud push}
|
13
|
+
spec.description = %q{aliyun cloud push}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "rest-client", "~> 2.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "aliyun/cloudpush"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'base64'
|
3
|
+
require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
require 'rest-client'
|
6
|
+
|
7
|
+
module Aliyun
|
8
|
+
module Cloudpush
|
9
|
+
class Client
|
10
|
+
|
11
|
+
def push(employee_id, title, body)
|
12
|
+
params = {
|
13
|
+
"TargetValue": employee_id,
|
14
|
+
"Title": title,
|
15
|
+
"Body": body,
|
16
|
+
}
|
17
|
+
http_post(default_push_params.merge(params))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def default_push_params
|
23
|
+
{
|
24
|
+
"Action": "Push",
|
25
|
+
"AppKey": Aliyun::Cloudpush.app_key,
|
26
|
+
"Target": "ACCOUNT",
|
27
|
+
"DeviceType": "ALL",
|
28
|
+
"PushType": "NOTICE",
|
29
|
+
"iOSApnsEnv": "PRODUCT",
|
30
|
+
"AndroidOpenType": "APPLICATION",
|
31
|
+
"iOSBadge": "0"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_params
|
36
|
+
{
|
37
|
+
'Format': "json",
|
38
|
+
'RegionId': "cn-hangzhou",
|
39
|
+
'Version': "2016-08-01",
|
40
|
+
'AccessKeyId': Aliyun::Cloudpush.access_key_id,
|
41
|
+
'SignatureMethod': "HMAC-SHA1",
|
42
|
+
'SignatureVersion': "1.0",
|
43
|
+
'SignatureNonce': (rand * 1_000_000_000).to_s,
|
44
|
+
'Timestamp': Time.now.utc.iso8601
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def params_str(action, params)
|
49
|
+
str = params.sort.map { |k, v| [CGI.escape(k.to_s), CGI.escape(v.to_s)].join('=') }.join('&')
|
50
|
+
"#{action}&#{CGI.escape('/')}&#{CGI.escape(str)}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def signature(str)
|
54
|
+
Base64.strict_encode64(
|
55
|
+
OpenSSL::HMAC.digest('sha1', "#{Aliyun::Cloudpush.access_key_secret}&", str)
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def http_post(params = {})
|
60
|
+
p = default_params.merge(params)
|
61
|
+
s = signature(params_str('POST', p))
|
62
|
+
res = RestClient.post(ENDPOINT, p.merge('Signature': s))
|
63
|
+
JSON.parse(res)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Cloudpush
|
3
|
+
class << self
|
4
|
+
attr_accessor :config
|
5
|
+
|
6
|
+
def configure
|
7
|
+
yield self.config ||= Config.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def app_key
|
11
|
+
@app_key ||= config.app_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def app_secret
|
15
|
+
@app_secret ||= config.app_secret
|
16
|
+
end
|
17
|
+
|
18
|
+
def access_key_id
|
19
|
+
@access_key_id ||= config.access_key_id
|
20
|
+
end
|
21
|
+
|
22
|
+
def access_key_secret
|
23
|
+
@access_key_secret ||= config.access_key_secret
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Config
|
28
|
+
attr_accessor :app_key, :app_secret, :access_key_id, :access_key_secret
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aliyun-cloudpush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Lai
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-16 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: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: aliyun cloud push
|
70
|
+
email:
|
71
|
+
- winfield301@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- aliyun-cloudpush.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/aliyun/cloudpush.rb
|
88
|
+
- lib/aliyun/cloudpush/client.rb
|
89
|
+
- lib/aliyun/cloudpush/config.rb
|
90
|
+
- lib/aliyun/cloudpush/version.rb
|
91
|
+
homepage: ''
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.6.13
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: aliyun cloud push
|
115
|
+
test_files: []
|