oauth_china 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +85 -84
- data/lib/oauth_china/multipart.rb +6 -2
- data/lib/oauth_china/strategies/qq.rb +5 -8
- data/lib/oauth_china/version.rb +1 -1
- metadata +18 -7
data/README.md
CHANGED
@@ -1,106 +1,107 @@
|
|
1
1
|
#简介
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
* 通过OAuth方式同步用户消息到微博平台(支持豆瓣,新浪微薄,腾讯微博,搜狐微博,网易微博)
|
4
|
+
* 和omini-auth的区别:omini-auth是专门提供oauth授权和获取用户信息的gem(比如用新浪微博帐号登陆这种需求)
|
5
|
+
* oauth_china是一个方便的同步信息到其他微博平台的gem(用来做像follow5.com或http://fanfou.com/settings/sync这样需求)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
7
|
#安装
|
10
8
|
|
11
|
-
|
9
|
+
``````
|
10
|
+
gem install oauth_china
|
11
|
+
``````
|
12
12
|
|
13
13
|
#使用
|
14
14
|
|
15
15
|
* 在Gemfile里添加:
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
``````
|
18
|
+
gem 'oauth'
|
19
|
+
gem 'oauth_china'
|
20
|
+
``````
|
19
21
|
|
20
22
|
* 添加配置文件
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
``````
|
25
|
+
config/oauth/douban.yml
|
26
|
+
config/oauth/sina.yml
|
27
|
+
config/oauth/qq.yml
|
28
|
+
config/oauth/sohu.yml
|
29
|
+
config/oauth/netease.yml
|
30
|
+
``````
|
31
|
+
|
32
|
+
* 配置文件格式:
|
33
|
+
|
34
|
+
``````yaml
|
35
|
+
development:
|
36
|
+
key: "you api key"
|
37
|
+
secret: "your secret"
|
38
|
+
url: "http://yoursite.com"
|
39
|
+
callback: "http://localhost:3000/your_callback_url"
|
40
|
+
production:
|
41
|
+
key: "you api key"
|
42
|
+
secret: "your secret"
|
43
|
+
url: "http://yoursite.com"
|
44
|
+
callback: "http://localhost:3000/your_callback_url"
|
45
|
+
``````
|
40
46
|
|
41
47
|
* 演示
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#client = OauthChina::Sina.load(:access_token => "xx", :access_token_secret => "xxx")
|
83
|
-
#client.add_status("同步到新浪微薄..")
|
84
|
-
flash[:notice] = "授权成功!"
|
85
|
-
else
|
86
|
-
flash[:notice] = "授权失败!"
|
87
|
-
end
|
88
|
-
redirect_to account_syncs_path
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
def build_oauth_token_key(name, oauth_token)
|
93
|
-
[name, oauth_token].join("_")
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
49
|
+
``````ruby
|
50
|
+
#config/routes.rb
|
51
|
+
match "syncs/:type/new" => "syncs#new", :as => :sync_new
|
52
|
+
match "syncs/:type/callback" => "syncs#callback", :as => :sync_callback
|
53
|
+
|
54
|
+
# encoding: UTF-8
|
55
|
+
class SyncsController < ApplicationController
|
56
|
+
|
57
|
+
def new
|
58
|
+
client = OauthChina::Sina.new
|
59
|
+
authorize_url = client.authorize_url
|
60
|
+
Rails.cache.write(build_oauth_token_key(client.name, client.oauth_token), client.dump)
|
61
|
+
redirect_to authorize_url
|
62
|
+
end
|
63
|
+
|
64
|
+
def callback
|
65
|
+
client = OauthChina::Sina.load(Rails.cache.read(build_oauth_token_key(params[:type], params[:oauth_token])))
|
66
|
+
client.authorize(:oauth_verifier => params[:oauth_verifier])
|
67
|
+
|
68
|
+
results = client.dump
|
69
|
+
|
70
|
+
if results[:access_token] && results[:access_token_secret]
|
71
|
+
#在这里把access token and access token secret存到db
|
72
|
+
#下次使用的时候:
|
73
|
+
#client = OauthChina::Sina.load(:access_token => "xx", :access_token_secret => "xxx")
|
74
|
+
#client.add_status("同步到新浪微薄..")
|
75
|
+
flash[:notice] = "授权成功!"
|
76
|
+
else
|
77
|
+
flash[:notice] = "授权失败!"
|
78
|
+
end
|
79
|
+
redirect_to root_path
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def build_oauth_token_key(name, oauth_token)
|
84
|
+
[name, oauth_token].join("_")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
``````
|
97
88
|
|
98
89
|
* 注意
|
99
90
|
|
100
|
-
|
91
|
+
系统时间要正确设置。否则会出现timstamps refused错误
|
101
92
|
|
102
93
|
#API文档
|
103
94
|
|
104
|
-
|
105
|
-
|
106
|
-
|
95
|
+
* 腾讯微博API文档:http://open.t.qq.com/resource.php?i=1,1
|
96
|
+
* 新浪微博API文档:http://open.t.sina.com.cn/wiki/index.php/API%E6%96%87%E6%A1%A3
|
97
|
+
* 豆瓣微博API文档:http://www.douban.com/service/apidoc/reference/
|
98
|
+
|
99
|
+
#License
|
100
|
+
This program is free softwareyou can redistribute it and /or modify
|
101
|
+
it under the terms of the GNU General Public License as published by
|
102
|
+
the Free Software Foundataioneither version 2 of the License,or (at
|
103
|
+
your option) any later version.
|
104
|
+
|
105
|
+
You should have read the GNU General Public License before start "RTFSC".
|
106
|
+
|
107
|
+
If not,see <http://www.gnu.org/licenses/>
|
@@ -12,7 +12,11 @@ module OauthChina
|
|
12
12
|
def to_multipart
|
13
13
|
#return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"\r\n\r\n#{v}\r\n"
|
14
14
|
# Don't escape mine...
|
15
|
-
|
15
|
+
if "".respond_to?(:force_encoding)
|
16
|
+
return "Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n#{v}\r\n".force_encoding("ASCII-8BIT")
|
17
|
+
else
|
18
|
+
return "Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n#{v}\r\n"
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
@@ -53,7 +57,7 @@ module OauthChina
|
|
53
57
|
fp.push(Param.new(k,v))
|
54
58
|
end
|
55
59
|
}
|
56
|
-
body = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "
|
60
|
+
body = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--\r\n"
|
57
61
|
return body, ContentType
|
58
62
|
end
|
59
63
|
|
@@ -37,17 +37,14 @@ module OauthChina
|
|
37
37
|
self.post("http://open.t.qq.com/api/t/add", options)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
|
41
41
|
def upload_image(content, image_path, options = {})
|
42
|
-
|
42
|
+
options = options.merge!(:content => content, :pic => File.open(image_path, "rb")).to_options
|
43
|
+
self.consumer.options[:site] = "http://open.t.qq.com/api/t/add_pic"
|
44
|
+
self.consumer.uri("http://open.t.qq.com/api/t/add_pic")
|
45
|
+
upload("http://open.t.qq.com/api/t/add_pic", options)
|
43
46
|
end
|
44
47
|
|
45
|
-
# def upload_image(content, image_path, options = {})
|
46
|
-
# options = options.merge!(:content => content, :pic => File.open(image_path, "rb")).to_options
|
47
|
-
#
|
48
|
-
# upload("http://open.t.qq.com/api/t/add_pic", options)
|
49
|
-
# end
|
50
|
-
|
51
48
|
|
52
49
|
end
|
53
50
|
end
|
data/lib/oauth_china/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth_china
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 11
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
+
- 5
|
8
9
|
- 0
|
9
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Hooopo
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2012-06-21 00:00:00 +08:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
28
30
|
segments:
|
29
31
|
- 0
|
30
32
|
version: "0"
|
@@ -38,12 +40,16 @@ dependencies:
|
|
38
40
|
requirements:
|
39
41
|
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
41
44
|
segments:
|
42
45
|
- 0
|
43
46
|
version: "0"
|
44
47
|
type: :development
|
45
48
|
version_requirements: *id002
|
46
|
-
description:
|
49
|
+
description: !binary |
|
50
|
+
5paw5rWq77yM6LGG55Oj77yM6IW+6K6v562J5Zu95YaF5b6u6JaET0F1dGjo
|
51
|
+
rqTor4E=
|
52
|
+
|
47
53
|
email:
|
48
54
|
- hoooopo@gmail.com
|
49
55
|
executables: []
|
@@ -81,6 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
87
|
requirements:
|
82
88
|
- - ">="
|
83
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
84
91
|
segments:
|
85
92
|
- 0
|
86
93
|
version: "0"
|
@@ -89,15 +96,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
96
|
requirements:
|
90
97
|
- - ">="
|
91
98
|
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
92
100
|
segments:
|
93
101
|
- 0
|
94
102
|
version: "0"
|
95
103
|
requirements: []
|
96
104
|
|
97
105
|
rubyforge_project: oauth_china
|
98
|
-
rubygems_version: 1.3.
|
106
|
+
rubygems_version: 1.3.9.4
|
99
107
|
signing_key:
|
100
108
|
specification_version: 3
|
101
|
-
summary:
|
109
|
+
summary: !binary |
|
110
|
+
5paw5rWq77yM6LGG55Oj77yM6IW+6K6v562J5Zu95YaF5b6u6JaET0F1dGjo
|
111
|
+
rqTor4E=
|
112
|
+
|
102
113
|
test_files: []
|
103
114
|
|