qq_conn 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/const.rb +23 -0
- data/lib/qq.rb +28 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b72e3392b5721f7d6285689c4671af2ec9be3236
|
4
|
+
data.tar.gz: 265fe569cd0879b2eaf34f85bd57cc4224e7f5e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79003bd9046c2c1b180beb361fc5800ca9d601daee2ea613c5e05d35a3e109f5088b1d1b84fb6a45b6b020cb8200be153b0ca9b5c370fa682386c4ca3e4ac455
|
7
|
+
data.tar.gz: 5f87e966a64b62f5e50d3e26f01768691c417084ca3d9f39eb1852d69dc68d5cc074d44491826b2567514d45b6fbfa363860fcb198ae364d3b70f0f0f14498e1
|
data/lib/const.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
# define const and load APP_ID form qq_secrets.yml
|
3
|
+
module QQ
|
4
|
+
f = 'qq_secrets.yml'
|
5
|
+
return raise 'qq_secrets.yml not found!' unless File.exist?(f)
|
6
|
+
s = YAML.load_file(f)
|
7
|
+
APP_ID = s['APP_ID'].freeze
|
8
|
+
APP_KEY = s['APP_KEY'].freeze
|
9
|
+
RED_URL = s['RED_URL'].freeze
|
10
|
+
AUTH_URL = 'https://graph.qq.com/oauth2.0/authorize?' \
|
11
|
+
'response_type=code&' \
|
12
|
+
"client_id=#{APP_ID}&" \
|
13
|
+
"redirect_uri=#{RED_URL}".freeze
|
14
|
+
TOKEN_URL = 'https://graph.qq.com/oauth2.0/token?' \
|
15
|
+
'grant_type=authorization_code&' \
|
16
|
+
"client_id=#{APP_ID}&" \
|
17
|
+
"client_secret=#{APP_KEY}&" \
|
18
|
+
"redirect_uri=#{RED_URL}".freeze
|
19
|
+
OPENID_URL = 'https://graph.qq.com/oauth2.0/me?' \
|
20
|
+
'access_token='.freeze
|
21
|
+
G_U_I_URL = 'https://graph.qq.com/user/get_user_info?'.freeze
|
22
|
+
VERSION = '0.3.1'.freeze
|
23
|
+
end
|
data/lib/qq.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
# QQ Connect
|
4
|
+
class Qq
|
5
|
+
require 'const.rb'
|
6
|
+
attr_reader :openid
|
7
|
+
# get APP_ID & APP_KEY from https://connect.qq.com/
|
8
|
+
def initialize(code)
|
9
|
+
# WARNING! return raise 'CSRF detected' if params[:state] != state
|
10
|
+
# get token
|
11
|
+
url = "#{QQ::TOKEN_URL}&code=#{code}"
|
12
|
+
@token = open(url).read[/(?<=access_token=)\w{32}/]
|
13
|
+
# get openid
|
14
|
+
url = QQ::OPENID_URL + @token
|
15
|
+
@openid = open(url).read[/\w{32}/]
|
16
|
+
# get auth
|
17
|
+
@auth = "access_token=#{@token}&" \
|
18
|
+
"oauth_consumer_key=#{QQ::APP_ID}&" \
|
19
|
+
"openid=#{@openid}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_user_info
|
23
|
+
back = open(QQ::G_U_I_URL + @auth).read.force_encoding('utf-8')
|
24
|
+
back = JSON.parse(back)
|
25
|
+
return raise back['ret'].to_s + ': ' + back['msg'] if back['ret'] != 0
|
26
|
+
back
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qq_conn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- '046569'
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: It is a simple way to connect to QQ Connect
|
14
|
+
email: '046569@046569.com'
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/const.rb
|
20
|
+
- lib/qq.rb
|
21
|
+
homepage: https://github.com/046569/qq
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: QQ Connect SDK 4 Ruby Framework
|
46
|
+
test_files: []
|