oauth_china 0.0.6 → 0.1.0
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.
- data/README.md +102 -0
- data/lib/oauth_china/strategies/douban.rb +1 -0
- data/lib/oauth_china/strategies/netease.rb +1 -1
- data/lib/oauth_china/strategies/qq.rb +1 -0
- data/lib/oauth_china/version.rb +1 -1
- metadata +7 -7
- data/README +0 -38
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#简介
|
2
|
+
|
3
|
+
OAuth gem for rails,支持豆瓣,新浪微薄,腾讯微博,搜狐微博,网易微博。
|
4
|
+
|
5
|
+
#安装
|
6
|
+
|
7
|
+
gem install oauth_china
|
8
|
+
|
9
|
+
#使用
|
10
|
+
|
11
|
+
* 在Gemfile里添加:
|
12
|
+
|
13
|
+
gem 'oauth'
|
14
|
+
gem 'oauth_china'
|
15
|
+
|
16
|
+
* 添加配置文件
|
17
|
+
|
18
|
+
配置文件路径:
|
19
|
+
config/oauth/douban.yml
|
20
|
+
config/oauth/sina.yml
|
21
|
+
config/oauth/qq.yml
|
22
|
+
config/oauth/sohu.yml
|
23
|
+
config/oauth/netease.yml
|
24
|
+
|
25
|
+
配置文件格式:
|
26
|
+
development:
|
27
|
+
key: "you api key"
|
28
|
+
secret: "your secret"
|
29
|
+
url: "http://yoursite.com"
|
30
|
+
callback: "http://localhost:3000/your_callback_url"
|
31
|
+
production:
|
32
|
+
key: "you api key"
|
33
|
+
secret: "your secret"
|
34
|
+
url: "http://yoursite.com"
|
35
|
+
callback: "http://localhost:3000/your_callback_url"
|
36
|
+
|
37
|
+
* 演示
|
38
|
+
|
39
|
+
#config/oauth/sina.yml
|
40
|
+
development:
|
41
|
+
key: "you api key"
|
42
|
+
secret: "your secret"
|
43
|
+
url: "http://yoursite.com"
|
44
|
+
callback: "http://localhost:3000/syncs/sina/callback"
|
45
|
+
production:
|
46
|
+
key: "you api key"
|
47
|
+
secret: "your secret"
|
48
|
+
url: "http://yoursite.com"
|
49
|
+
callback: "http://localhost:3000/syncs/sina/callback"
|
50
|
+
|
51
|
+
|
52
|
+
#config/routes.rb
|
53
|
+
match "syncs/:type/new" => "syncs#new", :as => :sync_new
|
54
|
+
match "syncs/:type/callback" => "syncs#callback", :as => :sync_callback
|
55
|
+
|
56
|
+
#app/controllers/syncs_controller.rb
|
57
|
+
# encoding: UTF-8
|
58
|
+
class SyncsController < ApplicationController
|
59
|
+
|
60
|
+
before_filter :login_required
|
61
|
+
|
62
|
+
def new
|
63
|
+
client = OauthChina::Sina.new
|
64
|
+
authorize_url = client.authorize_url
|
65
|
+
Rails.cache.write(build_oauth_token_key(client.name, client.oauth_token), client.dump)
|
66
|
+
redirect_to authorize_url
|
67
|
+
end
|
68
|
+
|
69
|
+
def callback
|
70
|
+
client = OauthChina::Sina.load(Rails.cache.read(build_oauth_token_key(params[:type], params[:oauth_token])))
|
71
|
+
client.authorize(:oauth_verifier => params[:oauth_verifier])
|
72
|
+
|
73
|
+
results = client.dump
|
74
|
+
|
75
|
+
if results[:access_token] && results[:access_token_secret]
|
76
|
+
#在这里把access token and access token secret存到db
|
77
|
+
#下次使用的时候:
|
78
|
+
#client = OauthChina::Sina.load(:access_token => "xx", :access_token_secret => "xxx")
|
79
|
+
#client.add_status("同步到新浪微薄..")
|
80
|
+
flash[:notice] = "授权成功!"
|
81
|
+
else
|
82
|
+
flash[:notice] = "授权失败!"
|
83
|
+
end
|
84
|
+
redirect_to account_syncs_path
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def build_oauth_token_key(name, oauth_token)
|
89
|
+
[name, oauth_token].join("_")
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
* 注意
|
95
|
+
|
96
|
+
系统时间要正确设置。否则会出现timstamps refused错误
|
97
|
+
|
98
|
+
#API文档
|
99
|
+
|
100
|
+
腾讯微博API文档:http://open.t.qq.com/resource.php?i=1,1
|
101
|
+
新浪微博API文档:http://open.t.sina.com.cn/wiki/index.php/API%E6%96%87%E6%A1%A3
|
102
|
+
豆瓣微博API文档:http://www.douban.com/service/apidoc/reference/
|
data/lib/oauth_china/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth_china
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.6
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Hooopo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-26 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -47,7 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
49
|
- Gemfile
|
50
|
-
- README
|
50
|
+
- README.md
|
51
51
|
- Rakefile
|
52
52
|
- lib/oauth_china.rb
|
53
53
|
- lib/oauth_china/strategies/douban.rb
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
requirements: []
|
88
88
|
|
89
89
|
rubyforge_project: oauth_china
|
90
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.6.2
|
91
91
|
signing_key:
|
92
92
|
specification_version: 3
|
93
93
|
summary: !binary |
|
data/README
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
一.简介:
|
2
|
-
|
3
|
-
OAuth gem for rails,支持豆瓣,新浪微薄,qq微薄
|
4
|
-
|
5
|
-
二.安装:
|
6
|
-
|
7
|
-
$ gem install oauth_china
|
8
|
-
|
9
|
-
三.使用:
|
10
|
-
|
11
|
-
1. 在Gemfile里添加:
|
12
|
-
|
13
|
-
gem 'oauth_china'
|
14
|
-
|
15
|
-
2. 添加配置文件
|
16
|
-
|
17
|
-
config/oauth/douban.yml
|
18
|
-
config/oauth/sina.yml
|
19
|
-
config/oauth/qq.yml
|
20
|
-
|
21
|
-
配置文件格式:
|
22
|
-
development:
|
23
|
-
key: "you api key"
|
24
|
-
secret: "your secret"
|
25
|
-
url: "http://yoursite.com"
|
26
|
-
callback: "http://localhost:3000/your_callback_url"
|
27
|
-
production:
|
28
|
-
key: "you api key"
|
29
|
-
secret: "your secret"
|
30
|
-
url: "http://yoursite.com"
|
31
|
-
callback: "http://localhost:3000/your_callback_url"
|
32
|
-
|
33
|
-
3.演示[TODO]
|
34
|
-
|
35
|
-
四.API文档
|
36
|
-
腾讯微博API文档:http://open.t.qq.com/resource.php?i=1,1
|
37
|
-
新浪微博API文档:http://open.t.sina.com.cn/wiki/index.php/API%E6%96%87%E6%A1%A3
|
38
|
-
豆瓣微博API文档:http://www.douban.com/service/apidoc/reference/
|