qq_17up 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37ab53826ad346ee7455beba52215868d3a15c28
4
- data.tar.gz: 7a34f2c93481d8b135aea2ba3b9f9075b3acbc1a
3
+ metadata.gz: 0e0df5b86252573c5f99dee1e2f5ad81995e51dc
4
+ data.tar.gz: 3850057bf6ff7cc65024f5f8489e2836ce3b0dde
5
5
  SHA512:
6
- metadata.gz: 47cb9e6254f952d4f49d65bb3b5eecb323f4ca91731e0800293a00a357907b5a8884ae48411fb5a649ce1f7fea3b5e2a97a9bf5e18a50467992185bcee9774b1
7
- data.tar.gz: 65613894432722d55449e8be34cf5352e7718c3ea0243108e6e085549235d900c2df460ca62de4286459d31dfd4cc1fcbb75427876a4e2b7717a1a795a9dd47b
6
+ metadata.gz: a148633bdf38203db6761aae748c2805c19519ddf69f01302d78ebf61e8c5a6279ac5ced773042ea6a6ba3563c10438fb81fba416303baf136656b7194881bfa
7
+ data.tar.gz: 62984c2e1f437f9217f8530267506553bf8eae68bd365dd1fac5959d8c4df12eaaa2105fcd20dbcd33621e891c1e21316326dcbbeddac684bd3e052bae6e8ef5
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weibo.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 liguang
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,6 @@
1
+ # QQ SDK
2
+
3
+
4
+ ## 使用
5
+
6
+ 配置文件: Rails.root + "/config/service.yml"
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/qq/client.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "rest-client"
2
+
3
+ module Qq
4
+ class Client
5
+ attr_reader :oauth
6
+
7
+ def initialize(access_token, uid)
8
+ @oauth = Oauth.new(access_token,uid)
9
+ end
10
+
11
+ ################# api
12
+
13
+ def get_info(options = {})
14
+ @oauth.get "user/get_info",options
15
+ end
16
+
17
+ #发表一条微博信息到腾讯微博
18
+ def add_t(content,options = {})
19
+ default_params = { :content => content }
20
+ @oauth.post "t/add_t",default_params.merge(options)
21
+ end
22
+
23
+ #上传图片并发表消息到腾讯微博
24
+ def add_pic_t(content,pic,options = {})
25
+ default_params = { :content => content,:pic => pic }
26
+ @oauth.post "t/add_pic_t",default_params.merge(options)
27
+ end
28
+
29
+ end
30
+ end
data/lib/qq/config.rb ADDED
@@ -0,0 +1,35 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "yaml"
3
+
4
+ module Qq
5
+ module Config
6
+
7
+ class << self
8
+ attr_reader :app_key, :app_secret, :redirect_uri
9
+
10
+ def load_config
11
+ filename = "#{Rails.root}/config/service.yml"
12
+ config = YAML.load(File.open(filename))[Rails.env]
13
+ @app_key, @app_secret, @redirect_uri = config['qq_connect']['app_id'], config['qq_connect']['app_key'], config['qq_connect']['redirect_uri']
14
+
15
+ unless @app_key && @app_secret && @redirect_uri
16
+ puts "|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
17
+ puts "|"
18
+ puts "Please configure qq app_id app_key redirect_uri in #{filename}."
19
+ puts "|"
20
+ puts "|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
21
+ end
22
+ end
23
+
24
+ def temp_change_config(config)
25
+ o_app_key, o_app_secret, o_redirect_url = @app_key, @app_secret, @redirect_uri
26
+ @app_key, @app_secret, @redirect_uri = config.app_key, config.app_secret, config.redirect_uri
27
+ result = yield
28
+ @app_key, @app_secret, @redirect_uri = o_app_key, o_app_secret, o_redirect_url
29
+ result
30
+ end
31
+ end
32
+
33
+
34
+ end
35
+ end
data/lib/qq/oauth.rb ADDED
@@ -0,0 +1,52 @@
1
+ require "digest/md5"
2
+ require "base64"
3
+
4
+ module Qq
5
+ class Oauth
6
+ API_URL = "https://graph.qq.com/"
7
+
8
+ def initialize(access_token,openid)
9
+ filename = "#{Rails.root}/config/service.yml"
10
+ config = YAML.load(File.open(filename))[Rails.env]
11
+ @app_key = config['qq_connect']['app_id']
12
+ @access_token = access_token
13
+ @openid = openid
14
+ end
15
+
16
+ def get(path, parameters = {})
17
+ parameters.merge!(openid: @openid,access_token: @access_token,oauth_consumer_key: @app_key)
18
+ JSON.parse RestClient.get(api_url(path), :params => parameters)
19
+ end
20
+
21
+ def post(path, parameters = {})
22
+ parameters.merge!(openid: @openid,access_token: @access_token,oauth_consumer_key: @app_key)
23
+ JSON.parse RestClient.post(api_url(path), parameters)
24
+ end
25
+
26
+ ######################################################
27
+ #
28
+ # @param string $signed_request 应用框架在加载iframe时会通过向Canvas URL post的参数signed_request
29
+ #
30
+ #####################################################
31
+ def self.parse_signed_request(signed_request)
32
+ encoded_sig, payload = signed_request.split(".")
33
+ sig = Base64.decode64_url(encoded_sig)
34
+ begin
35
+ data = JSON.parse(Base64.decode64_url(payload))
36
+ rescue Exception => e
37
+ return nil
38
+ end
39
+ return nil if data["algorithm"].upcase != "HMAC-SHA256"
40
+
41
+ expected_sig = OpenSSL::HMAC.digest("sha256", Config.app_secret, payload)
42
+ (sig != expected_sig) ? nil : data
43
+ end
44
+
45
+ private
46
+ def api_url(path)
47
+ path = path.gsub /^\//, ""
48
+ "#{API_URL}#{path}"
49
+ end
50
+
51
+ end
52
+ end
data/lib/qq/railtie.rb ADDED
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Qq
3
+ class Railtie < ::Rails::Railtie
4
+ initializer "加载rails环境下的config" do
5
+ Qq::Config.load_config
6
+ end
7
+ end
8
+ end
data/lib/qq/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Qq
2
+ VERSION = "4.0.2"
3
+ end
data/lib/qq.rb ADDED
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/qq/version')
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/qq/config')
4
+ require File.expand_path(File.dirname(__FILE__) + '/qq/oauth')
5
+ require File.expand_path(File.dirname(__FILE__) + '/qq/client')
6
+
7
+ if defined?(Rails)
8
+ require File.expand_path(File.dirname(__FILE__) + '/qq/railtie')
9
+ end
10
+
data/qq.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/qq/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["veggie"]
6
+ gem.email = ["kkxlkkxllb@gmail.com"]
7
+ gem.description = %q{QQ oauth2}
8
+ gem.summary = %q{QQ oauth2}
9
+ gem.homepage = "https://github.com/17up/qq_17up"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "qq_17up"
15
+ gem.require_paths = ["lib"]
16
+
17
+ gem.add_dependency 'rest-client'
18
+
19
+ gem.version = Qq::VERSION
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qq_17up
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - veggie
@@ -30,7 +30,20 @@ email:
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
- files: []
33
+ files:
34
+ - .DS_Store
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - lib/qq.rb
41
+ - lib/qq/client.rb
42
+ - lib/qq/config.rb
43
+ - lib/qq/oauth.rb
44
+ - lib/qq/railtie.rb
45
+ - lib/qq/version.rb
46
+ - qq.gemspec
34
47
  homepage: https://github.com/17up/qq_17up
35
48
  licenses: []
36
49
  metadata: {}