qqpush 0.0.1
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 +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +22 -0
- data/README.md +6 -0
- data/Rakefile +43 -0
- data/lib/xgpush/android.rb +4 -0
- data/lib/xgpush/general.rb +71 -0
- data/lib/xgpush/ios.rb +4 -0
- data/lib/xgpush.rb +5 -0
- data/spec/general_spec.rb +18 -0
- data/xgpush.gemspec +16 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7c0707d40aab681882e054a212e74985d70ca07
|
4
|
+
data.tar.gz: c0484741802148b12ed53076d30b2869f8f7aabf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1af6eb94d64e449d2af88d0bffa034f6c1d785964ba052ed1c76440eaae39d4cc5164752391f5ffedfcbabdffd192a07010dbe001c3dda090d998423c852eddc
|
7
|
+
data.tar.gz: 958cc3b49337e4dff55611f664f05103ff911693d36343bc9fa67ae2f11d57ea09f0f64fecc19324f331e4ef155bbaf2644f25e210341879fc708b5bebe5fb6b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://ruby.taobao.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.5)
|
5
|
+
domain_name (0.5.24)
|
6
|
+
unf (>= 0.0.5, < 1.0.0)
|
7
|
+
http-cookie (1.0.2)
|
8
|
+
domain_name (~> 0.5)
|
9
|
+
mime-types (2.6.1)
|
10
|
+
netrc (0.10.3)
|
11
|
+
rest-client (1.8.0)
|
12
|
+
http-cookie (>= 1.0.2, < 2.0)
|
13
|
+
mime-types (>= 1.16, < 3.0)
|
14
|
+
netrc (~> 0.7)
|
15
|
+
rspec (3.3.0)
|
16
|
+
rspec-core (~> 3.3.0)
|
17
|
+
rspec-expectations (~> 3.3.0)
|
18
|
+
rspec-mocks (~> 3.3.0)
|
19
|
+
rspec-core (3.3.2)
|
20
|
+
rspec-support (~> 3.3.0)
|
21
|
+
rspec-expectations (3.3.1)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.3.0)
|
24
|
+
rspec-mocks (3.3.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.3.0)
|
27
|
+
rspec-support (3.3.0)
|
28
|
+
unf (0.1.4)
|
29
|
+
unf_ext
|
30
|
+
unf_ext (0.0.7.1)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
rest-client
|
37
|
+
rspec
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 chaoli46
|
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
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
task default: %w(test)
|
2
|
+
|
3
|
+
desc 'test'
|
4
|
+
task :spec, :spec_name, :examples do |_t, args|
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
execute_spec = lambda do |function_name|
|
7
|
+
RSpec::Core::RakeTask.new do |st|
|
8
|
+
st.rspec_opts = "--format d --color #{@example}"
|
9
|
+
st.pattern = "spec/#{function_name}_spec.rb" if function_name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
if args.spec_name
|
13
|
+
if args.examples
|
14
|
+
@example = ''
|
15
|
+
example_array = args.examples.split(' ')
|
16
|
+
example_array.each { |e| @example += "--example '#{e}' " }
|
17
|
+
end
|
18
|
+
execute_spec.call(args.spec_name)
|
19
|
+
else
|
20
|
+
execute_spec.call(nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'build gem'
|
25
|
+
task :build do
|
26
|
+
puts `bundle exec gem build xgpush.gemspec`
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'publish gem'
|
30
|
+
task :push do
|
31
|
+
files = Dir.glob('xgpush-*.gem')
|
32
|
+
if files.size == 1
|
33
|
+
gem_file = files[0]
|
34
|
+
puts `bundle exec gem push #{gem_file}`
|
35
|
+
else
|
36
|
+
if files.size == 0
|
37
|
+
puts "No gem file. Run 'bundle exec rake build' at first."
|
38
|
+
else
|
39
|
+
puts 'Too many gem files:'
|
40
|
+
puts files
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'openssl'
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module Xgpush
|
6
|
+
class General
|
7
|
+
attr_accessor :settings
|
8
|
+
|
9
|
+
ROOT_URL = 'openapi.xg.qq.com'
|
10
|
+
PROTOCAL = 'http'
|
11
|
+
VERSION = 'v2'
|
12
|
+
SERVICES =
|
13
|
+
{ push: %w(single_device single_account
|
14
|
+
account_list all_device tags_device) }
|
15
|
+
|
16
|
+
SERVICES.each do |param_class, param_methods|
|
17
|
+
param_methods.each do |param_method|
|
18
|
+
define_method("#{param_class}_#{param_method}") do |params = {}|
|
19
|
+
request(params)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def request(params = {})
|
25
|
+
RestClient.post(
|
26
|
+
request_url(params),
|
27
|
+
general_params(params).merge(business_params(params)).to_json,
|
28
|
+
content_type: 'application/x-www-form-urlencoded')
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_url(params)
|
32
|
+
params[:param_encode] = true
|
33
|
+
"#{PROTOCAL}://#{ROOT_URL}/#{VERSION}/#{params[:param_class]}/" \
|
34
|
+
"#{params[:param_method]}#{params_string(params).gsub(/\&$/, '')}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def general_params(params)
|
38
|
+
base_params = { access_id: settings[:access_id],
|
39
|
+
timestamp: params[:timestamp],
|
40
|
+
valid_time: params[:valid_time] }
|
41
|
+
base_params[:timestamp] ||= Time.now.to_i
|
42
|
+
all_params = params.merge base_params
|
43
|
+
base_params.merge(sign: param_sign(all_params))
|
44
|
+
end
|
45
|
+
|
46
|
+
def param_sign(params)
|
47
|
+
sign_string = "POST#{ROOT_URL}/#{VERSION}/#{params[:param_class]}/" \
|
48
|
+
"#{params[:param_method]}#{params_string(params).gsub(/\&/, '')}" \
|
49
|
+
"#{params[:secret_key]}"
|
50
|
+
OpenSSL::Digest::MD5.new(sign_string).to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def business_params(params)
|
56
|
+
params.reject { |k, _v| k.to_s =~ /param_.*/ || k == :secret_key }
|
57
|
+
end
|
58
|
+
|
59
|
+
def params_string(params)
|
60
|
+
new_string = ''
|
61
|
+
business_params(params).keys.map(&:to_s).sort.each do |key|
|
62
|
+
next unless params[key] || params[key.to_sym]
|
63
|
+
value = [params[key], params[key.to_sym]].compact.first
|
64
|
+
new_value =
|
65
|
+
params[:param_encode] ? URI.encode(value) : "#{value}&"
|
66
|
+
new_string += "#{key}=#{new_value}" if new_value
|
67
|
+
end
|
68
|
+
new_string
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/xgpush/ios.rb
ADDED
data/lib/xgpush.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
require 'xgpush/general'
|
3
|
+
|
4
|
+
describe 'General methods' do
|
5
|
+
before do
|
6
|
+
@request = Xgpush::General.new
|
7
|
+
@request.settings = { access_id: '123' }
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'can generate sign by params' do
|
11
|
+
# http://developer.xg.qq.com/index.php/Rest_API
|
12
|
+
new_params = { param_class: 'push', param_method: 'single_device',
|
13
|
+
timestamp: 1386691200, secret_key: 'abcde',
|
14
|
+
'Param1' => 'Value1', 'Param2' => 'Value2' }
|
15
|
+
params = @request.general_params(new_params)
|
16
|
+
expect(params[:sign]).to eq('ccafecaef6be07493cfe75ebc43b7d53')
|
17
|
+
end
|
18
|
+
end
|
data/xgpush.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'qqpush'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2015-08-31'
|
5
|
+
s.summary = 'Tencent XG Push'
|
6
|
+
s.description = 'App push service by Tencent XG'
|
7
|
+
s.authors = ['Chao Li']
|
8
|
+
s.email = 'chaoli46@yahoo.com'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.homepage = 'https://github.com/chaoli46/xgpush'
|
11
|
+
s.license = 'MIT'
|
12
|
+
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
s.add_runtime_dependency 'rest-client', '~> 1.8'
|
15
|
+
s.add_development_dependency 'rspec', '~> 3.3'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qqpush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chao Li
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-31 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: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
description: App push service by Tencent XG
|
42
|
+
email: chaoli46@yahoo.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/xgpush.rb
|
54
|
+
- lib/xgpush/android.rb
|
55
|
+
- lib/xgpush/general.rb
|
56
|
+
- lib/xgpush/ios.rb
|
57
|
+
- spec/general_spec.rb
|
58
|
+
- xgpush.gemspec
|
59
|
+
homepage: https://github.com/chaoli46/xgpush
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.8
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Tencent XG Push
|
83
|
+
test_files: []
|