qq_connect 0.1.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/lib/qq_connect.rb +39 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ba084deefdc70f872fb1267854c19abab25d43f8
|
|
4
|
+
data.tar.gz: 984a5aa4ea0e7576953f34d117daabe406e90bde
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2e17481df03851fa0d9eccce4b58525780d63b0a05f11e14e24b01f715be03b468a69814b40e4e1540239d4e9b570546dd3d467ec28735bfcae584dd7f4623dc
|
|
7
|
+
data.tar.gz: 08dccba2de717e371ce71545e7f6ab700587b262abf32e8e8bacd2fe78ba8bebcbe315d4f802aa8e29354d0d2dc6bac76f43c39229d0ad400a8503da13760e6c
|
data/lib/qq_connect.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#encoding: utf-8
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'net/http'
|
|
4
|
+
class Qq
|
|
5
|
+
attr_reader :openid,:auth
|
|
6
|
+
#获取令牌:认证码code=params[:code],httpstat=request.env['HTTP_CONNECTION']
|
|
7
|
+
def initialize(appid,access_token)
|
|
8
|
+
#获取令牌
|
|
9
|
+
@appid = appid
|
|
10
|
+
@token = access_token
|
|
11
|
+
#@token ||= open('https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=' + APPID + '&client_secret=' + APPKEY + '&code=' + code + '&state='+ httpstat + REDURL).read[/(?<=access_token=)\w{32}/]
|
|
12
|
+
#获取Openid
|
|
13
|
+
@openid ||= open('https://graph.qq.com/oauth2.0/me?access_token=' + @token).read[/\w{32}/]
|
|
14
|
+
#获取通用验证参数
|
|
15
|
+
@auth ||= '?access_token=' + @token + '&oauth_consumer_key=' + @appid + '&openid=' + @openid
|
|
16
|
+
end
|
|
17
|
+
#调用API,格式为:腾讯API接口(网址,参数).
|
|
18
|
+
def method_missing(*params)
|
|
19
|
+
case params[0]
|
|
20
|
+
when /^get_.*|^list_.*|^check_.*/
|
|
21
|
+
back=open(params[1] + @auth + params[2].to_s).read.force_encoding('utf-8')
|
|
22
|
+
when /.*pic.*/
|
|
23
|
+
raise 'no block given' unless block_given?
|
|
24
|
+
url=URI(yield['url'])
|
|
25
|
+
request={'access_token' => @token,'oauth_consumer_key' => @appid,'openid' => @openid}.merge(yield)
|
|
26
|
+
back=Net::HTTP.post_form(url,request).body
|
|
27
|
+
when /^add_.*|^del_.*/
|
|
28
|
+
url=URI(params[1])
|
|
29
|
+
back=Net::HTTP.new(url.host,443)
|
|
30
|
+
back.use_ssl=true
|
|
31
|
+
back=back.post(url.path,@auth[1..-1] + params[2]).body
|
|
32
|
+
else
|
|
33
|
+
raise 'API not found'
|
|
34
|
+
end
|
|
35
|
+
back=MultiJson.decode(back)
|
|
36
|
+
raise back['ret'].to_s + ': ' + back['msg'] if back['ret'] != 0
|
|
37
|
+
return back
|
|
38
|
+
end
|
|
39
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: qq_connect
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- pobing
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: It's a simple way to connect to QQ Connect
|
|
14
|
+
email: cn.jdong@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/qq_connect.rb
|
|
20
|
+
homepage: https://github.com/pobing/qq_connect
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.2.2
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: QQ Connect SDK for Sinatra
|
|
45
|
+
test_files: []
|