qq_client 4.0.8

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: 6ae9c516b43243ecf7031c66830aa42579a2b2ea
4
+ data.tar.gz: 5eeac5d506c5597dc9297ce5020ea439ddd669c4
5
+ SHA512:
6
+ metadata.gz: b283cdb8e59f40141842951e90a98a2c9ef73867886019abb702ae0520c755c4bf32a9d38c3bfb1e39c506cd555f84150cbeb12c99a1c8a2dfabf28917fd01b5
7
+ data.tar.gz: 74028e4a721536f685754219e1734a3266d3e3dc5d9b1a4941198cdef8fa01d8ff42c4183d385dc2bf1659b00053bda9a7616fc04fa7622a5663e473ef2df85c
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qq_client.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Daniel Gonzàlez Lareo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # QQ Client for Ruby
2
+
3
+ This gem si based in the gem [qq_17up](https://github.com/17up/qq_17up) made by [veggie](mailto:kkxlkkxllb@gmail.com).
4
+
5
+ The difference is that the configurations for the qq client is inside the rails configration in a ruby file instead of being stored in `/config/service.ym`.
6
+
7
+ This is the first step to build a gem to communicate with the qq connect open platform API.
8
+
9
+ The gem includes an strategy for connect qq via omniauth.
10
+
11
+ ## Installation
12
+
13
+ Add to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'qq_client'
17
+ ```
18
+
19
+ Then `bundle install`
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ $ gem install qq_client
25
+ ```
26
+ ## Setup
27
+
28
+ To configure the gem create the file `config/initializers/qq_client_config.rb` and add the configuration of the client.
29
+
30
+ Example:
31
+
32
+ ```ruby
33
+ Rails.application.config.after_initialize do
34
+ QQ_CONNECT_API_KEY = {API Key} unless defined?(QQ_CONNECT_API_KEY)
35
+ QQ_CONNECT_API_SECRET = {API Secret} unless defined?(QQ_CONNECT_API_SECRET)
36
+ QQ_CONNECT_REDIRECT_URI = {Callback redirect url} unless defined?(QQ_CONNECT_REDIRECT_URI)
37
+
38
+ QqClient::Config.load_config(QQ_CONNECT_API_KEY, QQ_CONNECT_API_SECRET, QQ_CONNECT_REDIRECT_URI)
39
+ end
40
+ ```
41
+
42
+ ## OmniAuth configuration
43
+
44
+ To use qq_connect with devise omniauth please add to the `config/initializers/devise.rb`:
45
+
46
+ ```ruby
47
+ require 'omniauth/strategies/qq_connect'
48
+ ...
49
+ config.omniauth :qq_connect, ENV['TQQ_KEY'], ENV['TQQ_SECURT']
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ Frst of all create a QqClient::Client with a access_token provided by qq. The you can start getting the info.
55
+
56
+ You must have the uid before. This elemtn is provided during the oauth flow.
57
+
58
+ ```ruby
59
+ # Building the client for this spsecific user
60
+ client = QqClient::Client.new(access_token)
61
+
62
+ # Get the user uid
63
+ # More info (http://wiki.connect.qq.com/%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5_client-side)
64
+ me = client.oauth.get_uid
65
+ uid = me[:openid]
66
+
67
+ # Get Tencent Weibo user's login information.
68
+ # More info (http://wiki.connect.qq.com/get_info)
69
+ user_info = client.get_info(uid)
70
+
71
+ # Published a microblogging message (plain text) to the Tencent microblogging platforms.
72
+ # More info (http://wiki.connect.qq.com/add_t)
73
+ client.add_t(uid, 'Text message')
74
+
75
+ # Upload a picture and posted a message on the Tencent microblogging platforms.
76
+ # More info (http://wiki.connect.qq.com/add_pic_t)
77
+ client.add_pic_t(uid, 'Text message', pic)
78
+ ```
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it
83
+ 2. Create your feature branch => `git checkout -b my-new-feature`
84
+ 3. Commit your changes => `git commit -am 'Added some feature'`
85
+ 4. Push to the branch => `git push origin my-new-feature`
86
+ 5. Create new Pull Request
87
+
88
+ ## License
89
+
90
+ The MIT License (MIT)
91
+
92
+ Copyright (c) 2014 Daniel Gonzàlez Lareo
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
95
+ this software and associated documentation files (the "Software"), to deal in
96
+ the Software without restriction, including without limitation the rights to
97
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
98
+ the Software, and to permit persons to whom the Software is furnished to do so,
99
+ subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all
102
+ copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
106
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
107
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
108
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
109
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ #C:\Sites\tm_wed\lib\omniauth\strategies\tqq.rb
2
+ # Updated at: 2014-09-04
3
+ # Author: we@wedxt.com
4
+
5
+ require "omniauth-oauth2"
6
+
7
+ module OmniAuth
8
+ module Strategies
9
+ class QqConnect < OmniAuth::Strategies::OAuth2
10
+ DEFAULT_SCOPE = 'get_user_info, get_other_info'
11
+
12
+ option :name, 'qq_connect'
13
+
14
+ option :client_options, {
15
+ :site => "https://graph.qq.com",
16
+ :authorize_url => "/oauth2.0/authorize",
17
+ :token_method => :get,
18
+ :token_url => "/oauth2.0/token",
19
+ :token_formatter => lambda {|hash|
20
+ hash[:expires_in] = hash['expires_in'].to_i
21
+ hash.delete('expires_in')
22
+ }
23
+ }
24
+
25
+ option :authorize_params, {
26
+ :response_type => "code",
27
+ :scope => DEFAULT_SCOPE
28
+ }
29
+
30
+ option :authorize_options, [:scope]
31
+ option :token_params, {
32
+ :grant_type => "authorization_code",
33
+ :parse => :query,
34
+ :state => "state"
35
+ }
36
+ option :token_options, []
37
+
38
+ uid do
39
+ response = access_token.get(
40
+ '/oauth2.0/me'
41
+ )
42
+ data = MultiJson.decode(response.body.gsub(/callback\(/, "").gsub(/\);\n/, "").strip, :symbolize_keys => true)
43
+ @user_id = data[:openid]
44
+ end
45
+
46
+ info do
47
+ {
48
+ :nickname => raw_info['nickname'],
49
+ :avatar => raw_info['figureurl_2'],
50
+ :gender => raw_info['gender']
51
+ }
52
+ end
53
+
54
+ extra do
55
+ {
56
+ :raw_info => raw_info
57
+ }
58
+ end
59
+
60
+ def raw_info
61
+ response = access_token.get(
62
+ '/user/get_user_info', {:params => {:openid => @user_id, :oauth_consumer_key => access_token.client.id, :format => :json}, :parse => :json}
63
+ ).parsed
64
+ end
65
+
66
+ def build_access_token
67
+ verifier = request.params['code']
68
+ client.auth_code.get_token(
69
+ verifier,
70
+ {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)),
71
+ {:mode => :query, :param_name => 'access_token'}
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ OmniAuth.config.add_camelization 'qq_connect', 'QqConnect'
data/lib/qq_client.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'qq_client/version'
2
+ require 'qq_client/config'
3
+ require 'qq_client/oauth'
4
+ require 'qq_client/client'
5
+ require 'qq_client/railtie'
6
+ require 'qq_client/railtie'
7
+ require 'omniauth/strategies/qq_connect'
@@ -0,0 +1,44 @@
1
+ require "rest_client"
2
+
3
+ module QqClient
4
+ class Client
5
+ attr_reader :oauth
6
+
7
+ def initialize(access_token)
8
+ @oauth = Oauth.new(access_token)
9
+ end
10
+
11
+ ################# API
12
+
13
+ # Get Tencent Weibo user's login information.
14
+ # More info (http://wiki.connect.qq.com/get_info)
15
+ def get_info(uid, options = {})
16
+ @oauth.post uid, "user/get_info", options
17
+ end
18
+
19
+ # Published a microblogging message (plain text) to the Tencent microblogging platforms.
20
+ # More info (http://wiki.connect.qq.com/add_t)
21
+ def add_t(uid, content, options = {})
22
+ default_params = { :content => content }
23
+ @oauth.post uid, "t/add_t", default_params.merge(options)
24
+ end
25
+
26
+ # Upload a picture and posted a message on the Tencent microblogging platforms.
27
+ # More info (http://wiki.connect.qq.com/add_pic_t)
28
+ def add_pic_t(uid, content, pic, options = {})
29
+ default_params = { :content => content,:pic => pic }
30
+ @oauth.post uid, "t/add_pic_t", default_params.merge(options)
31
+ end
32
+
33
+ def add_blog(uid, title, content)
34
+ params = { :content => content,:title => title,:format => 'json' }
35
+ @oauth.post uid, "blog/add_one_blog", params
36
+ end
37
+
38
+ def get_uid
39
+ default_params = { :format => 'json' }
40
+ @oauth.get_uid "oauth2.0/me", default_params
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,55 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module QqClient
3
+ module Config
4
+
5
+ class << self
6
+ attr_reader :app_key, :app_secret, :redirect_uri
7
+
8
+ def load_config(app_key, app_secret, redirect_uri)
9
+ begin
10
+ filename = "#{Rails.root}/config/initializers/qq_client_config.rb"
11
+ if self.check_config_file(filename)
12
+ require filename
13
+ @app_key = (app_key.nil?) ? QQ_CONNECT_API_KEY : app_key
14
+ @app_secret = (app_secret.nil?) ? QQ_CONNECT_API_SECRET : app_secret
15
+ @redirect_uri = (redirect_uri.nil?) ? QQ_CONNECT_REDIRECT_URI : redirect_uri
16
+ else
17
+ @app_key = app_key
18
+ @app_secret = app_secret
19
+ @redirect_uri = redirect_uri
20
+ end
21
+ {
22
+ app_key: @app_key,
23
+ app_secret: @app_secret,
24
+ redirect_uri: @redirect_uri
25
+ }
26
+ rescue => e
27
+ puts e => e.message
28
+ end
29
+ end
30
+
31
+ def check_config_file(filename)
32
+ result = true
33
+ unless File.exist?(filename)
34
+ puts "|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
35
+ puts "|"
36
+ puts "Please configure qq app_id app_key redirect_uri in #{filename}."
37
+ puts "|"
38
+ puts "|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
39
+ result = false
40
+ end
41
+ result
42
+ end
43
+
44
+ def temp_change_config(config)
45
+ o_app_key, o_app_secret, o_redirect_url = @app_key, @app_secret, @redirect_uri
46
+ @app_key, @app_secret, @redirect_uri = config.app_key, config.app_secret, config.redirect_uri
47
+ result = yield
48
+ @app_key, @app_secret, @redirect_uri = o_app_key, o_app_secret, o_redirect_url
49
+ result
50
+ end
51
+ end
52
+
53
+
54
+ end
55
+ end
@@ -0,0 +1,65 @@
1
+ require "digest/md5"
2
+ require "base64"
3
+
4
+ module QqClient
5
+ class Oauth
6
+ API_URL = "https://graph.qq.com/"
7
+
8
+ def initialize(access_token)
9
+ config = QqClient::Config::load_config(nil, nil, nil)
10
+ @app_key = config[:app_key]
11
+ @access_token = access_token
12
+ end
13
+
14
+ def get(uid, path, parameters = {})
15
+ parameters.merge!(openid: uid,access_token: @access_token,oauth_consumer_key: @app_key)
16
+ JSON.parse RestClient.get(api_url(path), :params => parameters)
17
+ end
18
+
19
+ def post(uid, path, parameters = {})
20
+ parameters.merge!(openid: uid,access_token: @access_token,oauth_consumer_key: @app_key)
21
+ JSON.parse RestClient.post(api_url(path), parameters)
22
+ end
23
+
24
+ def get_uid(path, parameters = {})
25
+ parameters.merge!(access_token: @access_token,oauth_consumer_key: @app_key)
26
+ callback_function = RestClient.get(get_uid_url(path, parameters))
27
+ callback_function.match(/"openid":([^\/.]*)$/).to_a.second.split('"').second
28
+ end
29
+
30
+ ######################################################
31
+ #
32
+ # @param string $signed_request 应用框架在加载iframe时会通过向Canvas URL post的参数signed_request
33
+ #
34
+ #####################################################
35
+ def self.parse_signed_request(signed_request)
36
+ encoded_sig, payload = signed_request.split(".")
37
+ sig = Base64.decode64_url(encoded_sig)
38
+ begin
39
+ data = JSON.parse(Base64.decode64_url(payload))
40
+ rescue Exception => e
41
+ return nil
42
+ end
43
+ return nil if data["algorithm"].upcase != "HMAC-SHA256"
44
+
45
+ expected_sig = OpenSSL::HMAC.digest("sha256", Config.app_secret, payload)
46
+ (sig != expected_sig) ? nil : data
47
+ end
48
+
49
+ private
50
+ def api_url(path)
51
+ path = path.gsub /^\//, ""
52
+ "#{API_URL}#{path}"
53
+ end
54
+
55
+ def get_uid_url(path, parameters)
56
+ str = ""
57
+ parameters.each do |p|
58
+ sub_str = (str.empty?) ? "#{p[0]}=#{p[1]}" : "&#{p[0]}=#{p[1]}"
59
+ str = str + sub_str
60
+ end
61
+ "#{api_url(path)}?#{str}"
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module QqClient
3
+ class Railtie < ::Rails::Railtie
4
+ # initializer "Charge rails qq_client configuration" do
5
+ # QqClient::Config.load_config(nil, nil, nil)
6
+ # end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module QqClient
2
+ VERSION = "4.0.8"
3
+ end
data/qq_client.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ require_relative 'lib/qq_client/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.authors = ["Daniel Gonzalez"]
5
+ s.email = ["danigonza86@gmail.com"]
6
+ s.name = 'qq_client'
7
+ s.version = QqClient::VERSION
8
+ s.summary = "QqClient"
9
+ s.description = "A qq client for oath2 and API with a omniauth strategie"
10
+ s.files = `git ls-files`.split($\)
11
+ s.require_paths = ["lib"]
12
+ s.add_dependency 'rest-client', '~> 0'
13
+ s.homepage = 'http://rubygems.org/gems/qq_client'
14
+ s.license = 'MIT'
15
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qq_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Gonzalez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-02 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A qq client for oath2 and API with a omniauth strategie
28
+ email:
29
+ - danigonza86@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - lib/omniauth/strategies/qq_connect.rb
39
+ - lib/qq_client.rb
40
+ - lib/qq_client/client.rb
41
+ - lib/qq_client/config.rb
42
+ - lib/qq_client/oauth.rb
43
+ - lib/qq_client/railtie.rb
44
+ - lib/qq_client/version.rb
45
+ - qq_client.gemspec
46
+ homepage: http://rubygems.org/gems/qq_client
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.2.1
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: QqClient
70
+ test_files: []