aliyun-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 +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +56 -0
- data/Rakefile +8 -0
- data/aliyun-push.gemspec +21 -0
- data/lib/aliyun-push.rb +2 -0
- data/lib/aliyun-push/client.rb +39 -0
- data/lib/aliyun-push/parameter_set.rb +36 -0
- data/test/test_parameters.rb +25 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb9b4e910bb1cbba8681733abfac3ed114e03a2d
|
4
|
+
data.tar.gz: 290214566529d65ad671037901eb90096861ae20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 250140b99498221f3e2139c6a5fa8cf06af690c5e7881dc8615795e5707f2786d7f3d5b00739f50821fd0ccab5db3c45e1446e186c01f020e2035f0b21ffd813
|
7
|
+
data.tar.gz: d7027ba3a95ad47d8baace0a083ea6aa3ec2026de5d3af5bc1a15ebd11568d7123c6cbbd85ad665e36cb6c6983272261f5e826fbb7064ccc13fdfb3b9dbe0a25
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Eric Zhang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# aliyun-push-ruby-sdk
|
2
|
+
|
3
|
+
Ruby wrapper of Aliyun push service.
|
4
|
+
I'm using it in production, and it works well.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add `gem 'aliyun-push'` to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'aliyun-push'
|
11
|
+
|
12
|
+
And then run:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it with gem command:
|
17
|
+
|
18
|
+
$ gem install aliyun-push
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Example:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'aliyun-push'
|
26
|
+
|
27
|
+
client = AliyunPush::Client.new('your_access_key_id', 'your_access_key_secret')
|
28
|
+
puts client.send_request(Action: 'Push',
|
29
|
+
AppKey: 'your app key',
|
30
|
+
Body: 'test',
|
31
|
+
Summary: 'test2',
|
32
|
+
DeviceType: '3',
|
33
|
+
Target: 'account',
|
34
|
+
TargetValue: '16',
|
35
|
+
ApnsEnv: 'PRODUCT',
|
36
|
+
StoreOffline: false,
|
37
|
+
Type: '1',
|
38
|
+
Title: 'test1',
|
39
|
+
Remind: false)
|
40
|
+
|
41
|
+
# documentation for the parameterss: https://help.aliyun.com/document_detail/30074.html
|
42
|
+
```
|
43
|
+
|
44
|
+
You can create/fetch `access key` and `secret` at [https://i.aliyun.com/access_key](https://i.aliyun.com/access_key)
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it ( https://github.com/qinix/aliyun-push-ruby-sdk/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create a new Pull Request
|
53
|
+
|
54
|
+
## Author
|
55
|
+
|
56
|
+
* [Eric Zhang](https://github.com/qinix)
|
data/Rakefile
ADDED
data/aliyun-push.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "aliyun-push"
|
7
|
+
gem.version = "0.1.0"
|
8
|
+
gem.authors = ["Eric Zhang"]
|
9
|
+
gem.email = ["i@qinix.com"]
|
10
|
+
gem.description = %q{Ruby SDK for Aliyun push service}
|
11
|
+
gem.summary = %q{Ruby SDK for Aliyun push service}
|
12
|
+
gem.homepage = "https://github.com/qinix/aliyun-push-ruby-sdk"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency 'httparty', '~> 0.13.7'
|
20
|
+
|
21
|
+
end
|
data/lib/aliyun-push.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'aliyun-push/parameter_set'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module AliyunPush
|
6
|
+
class Client
|
7
|
+
def initialize(access_key_id, access_key_secret, region = 'cn-hangzhou')
|
8
|
+
@base_url = "https://cloudpush.aliyuncs.com/"
|
9
|
+
@region = region
|
10
|
+
@access_key_id = access_key_id
|
11
|
+
@access_key_secret = access_key_secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def send_request(params)
|
15
|
+
default_params = {
|
16
|
+
Format: 'JSON',
|
17
|
+
RegionId: @region,
|
18
|
+
Version: '2015-08-27',
|
19
|
+
AccessKeyId: @access_key_id,
|
20
|
+
SignatureMethod: 'HMAC-SHA1',
|
21
|
+
Timestamp: Time.now.utc.iso8601,
|
22
|
+
SignatureVersion: '1.0',
|
23
|
+
SignatureNonce: SecureRandom.uuid
|
24
|
+
}
|
25
|
+
|
26
|
+
params.each do |key, val|
|
27
|
+
default_params[key.to_sym] = val
|
28
|
+
end
|
29
|
+
|
30
|
+
ps = ParameterSet.new
|
31
|
+
default_params.each do |key, val|
|
32
|
+
ps.add key.to_s, val.to_s
|
33
|
+
end
|
34
|
+
ps.add 'Signature', ps.sign(@access_key_secret)
|
35
|
+
request_url = "#{@base_url}?#{ps.concatenate}"
|
36
|
+
HTTParty.get request_url
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'openssl'
|
3
|
+
require 'base64'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module AliyunPush
|
7
|
+
class AliyunPush::ParameterSet
|
8
|
+
def initialize
|
9
|
+
@params = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(key, value)
|
13
|
+
@params[key] = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def concatenate
|
17
|
+
@params.sort_by{ |key, value| key }.to_h.map do |key, value|
|
18
|
+
"#{custom_url_encode(key)}=#{custom_url_encode(value)}"
|
19
|
+
end.join '&'
|
20
|
+
end
|
21
|
+
|
22
|
+
def string_to_sign
|
23
|
+
"GET&%2F&#{CGI.escape(concatenate)}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def sign(access_key_secret)
|
27
|
+
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), access_key_secret + '&', string_to_sign)).strip
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def custom_url_encode(str)
|
33
|
+
CGI.escape(str).sub('+', '%20').sub('*', '%2A').sub('%7E', '~')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'aliyun-push'
|
3
|
+
|
4
|
+
class ParametersTest < Minitest::Test
|
5
|
+
def test_parameters
|
6
|
+
ps = AliyunPush::ParameterSet.new
|
7
|
+
ps.add 'Format', 'XML'
|
8
|
+
ps.add 'AccessKeyId', 'testid'
|
9
|
+
ps.add 'Action', 'GetDeviceInfos'
|
10
|
+
ps.add 'SignatureMethod', 'HMAC-SHA1'
|
11
|
+
ps.add 'RegionId', 'cn-hangzhou'
|
12
|
+
ps.add 'Devices', 'e2ba19de97604f55b165576736477b74,92a1da34bdfd4c9692714917ce22d53d'
|
13
|
+
ps.add 'SignatureNonce', 'c4f5f0de-b3ff-4528-8a89-fa478bda8d80'
|
14
|
+
ps.add 'SignatureVersion', '1.0'
|
15
|
+
ps.add 'Version', '2015-08-27'
|
16
|
+
ps.add 'AppKey', '23267207'
|
17
|
+
ps.add 'Timestamp', '2016-03-29T03:59:24Z'
|
18
|
+
|
19
|
+
assert_equal 'GET&%2F&AccessKeyId%3Dtestid%26Action%3DGetDeviceInfos%26AppKey%3D23267207%26Devices%3De2ba19de97604f55b165576736477b74%252C92a1da34bdfd4c9692714917ce22d53d%26Format%3DXML%26RegionId%3Dcn-hangzhou%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3Dc4f5f0de-b3ff-4528-8a89-fa478bda8d80%26SignatureVersion%3D1.0%26Timestamp%3D2016-03-29T03%253A59%253A24Z%26Version%3D2015-08-27',
|
20
|
+
ps.string_to_sign
|
21
|
+
|
22
|
+
assert_equal 'Q4jj5vC+NRtz294V+oIW7gfaJ6U=',
|
23
|
+
ps.sign('testsecret')
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aliyun-push
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Zhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.7
|
27
|
+
description: Ruby SDK for Aliyun push service
|
28
|
+
email:
|
29
|
+
- i@qinix.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- aliyun-push.gemspec
|
40
|
+
- lib/aliyun-push.rb
|
41
|
+
- lib/aliyun-push/client.rb
|
42
|
+
- lib/aliyun-push/parameter_set.rb
|
43
|
+
- test/test_parameters.rb
|
44
|
+
homepage: https://github.com/qinix/aliyun-push-ruby-sdk
|
45
|
+
licenses: []
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.5.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Ruby SDK for Aliyun push service
|
67
|
+
test_files:
|
68
|
+
- test/test_parameters.rb
|