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 CHANGED
@@ -1,106 +1,107 @@
1
1
  #简介
2
2
 
3
- 通过OAuth方式同步用户消息到微博平台(支持豆瓣,新浪微薄,腾讯微博,搜狐微博,网易微博)
4
- 和omini-auth的区别:omini-auth是专门提供oauth授权和获取用户信息的gem(比如用新浪微博帐号登陆这种需求)
5
- oauth_china是一个方便的同步信息到其他微博平台的gem(用来做像follow5.com或http://fanfou.com/settings/sync这样需求)
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
- gem install oauth_china
9
+ ``````
10
+ gem install oauth_china
11
+ ``````
12
12
 
13
13
  #使用
14
14
 
15
15
  * 在Gemfile里添加:
16
16
 
17
- gem 'oauth'
18
- gem 'oauth_china'
17
+ ``````
18
+ gem 'oauth'
19
+ gem 'oauth_china'
20
+ ``````
19
21
 
20
22
  * 添加配置文件
21
23
 
22
- 配置文件路径:
23
- config/oauth/douban.yml
24
- config/oauth/sina.yml
25
- config/oauth/qq.yml
26
- config/oauth/sohu.yml
27
- config/oauth/netease.yml
28
-
29
- 配置文件格式:
30
- development:
31
- key: "you api key"
32
- secret: "your secret"
33
- url: "http://yoursite.com"
34
- callback: "http://localhost:3000/your_callback_url"
35
- production:
36
- key: "you api key"
37
- secret: "your secret"
38
- url: "http://yoursite.com"
39
- callback: "http://localhost:3000/your_callback_url"
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
- #config/oauth/sina.yml
44
- development:
45
- key: "you api key"
46
- secret: "your secret"
47
- url: "http://yoursite.com"
48
- callback: "http://localhost:3000/syncs/sina/callback"
49
- production:
50
- key: "you api key"
51
- secret: "your secret"
52
- url: "http://yoursite.com"
53
- callback: "http://localhost:3000/syncs/sina/callback"
54
-
55
-
56
- #config/routes.rb
57
- match "syncs/:type/new" => "syncs#new", :as => :sync_new
58
- match "syncs/:type/callback" => "syncs#callback", :as => :sync_callback
59
-
60
- #app/controllers/syncs_controller.rb
61
- # encoding: UTF-8
62
- class SyncsController < ApplicationController
63
-
64
- before_filter :login_required
65
-
66
- def new
67
- client = OauthChina::Sina.new
68
- authorize_url = client.authorize_url
69
- Rails.cache.write(build_oauth_token_key(client.name, client.oauth_token), client.dump)
70
- redirect_to authorize_url
71
- end
72
-
73
- def callback
74
- client = OauthChina::Sina.load(Rails.cache.read(build_oauth_token_key(params[:type], params[:oauth_token])))
75
- client.authorize(:oauth_verifier => params[:oauth_verifier])
76
-
77
- results = client.dump
78
-
79
- if results[:access_token] && results[:access_token_secret]
80
- #在这里把access token and access token secret存到db
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
- 系统时间要正确设置。否则会出现timstamps refused错误
91
+ 系统时间要正确设置。否则会出现timstamps refused错误
101
92
 
102
93
  #API文档
103
94
 
104
- 腾讯微博API文档:http://open.t.qq.com/resource.php?i=1,1
105
- 新浪微博API文档:http://open.t.sina.com.cn/wiki/index.php/API%E6%96%87%E6%A1%A3
106
- 豆瓣微博API文档:http://www.douban.com/service/apidoc/reference/
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
- return "Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n#{v}\r\n"
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 + "--rn"
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
- #TODO
40
+
41
41
  def upload_image(content, image_path, options = {})
42
- add_status(content, options)
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
@@ -1,3 +1,3 @@
1
1
  module OauthChina
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
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
- prerelease: false
4
+ hash: 11
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 4
8
+ - 5
8
9
  - 0
9
- version: 0.4.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: 2011-08-01 00:00:00 +08:00
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: "\xE6\x96\xB0\xE6\xB5\xAA\xEF\xBC\x8C\xE8\xB1\x86\xE7\x93\xA3\xEF\xBC\x8C\xE8\x85\xBE\xE8\xAE\xAF\xE7\xAD\x89\xE5\x9B\xBD\xE5\x86\x85\xE5\xBE\xAE\xE8\x96\x84OAuth\xE8\xAE\xA4\xE8\xAF\x81"
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.7
106
+ rubygems_version: 1.3.9.4
99
107
  signing_key:
100
108
  specification_version: 3
101
- summary: "\xE6\x96\xB0\xE6\xB5\xAA\xEF\xBC\x8C\xE8\xB1\x86\xE7\x93\xA3\xEF\xBC\x8C\xE8\x85\xBE\xE8\xAE\xAF\xE7\xAD\x89\xE5\x9B\xBD\xE5\x86\x85\xE5\xBE\xAE\xE8\x96\x84OAuth\xE8\xAE\xA4\xE8\xAF\x81"
109
+ summary: !binary |
110
+ 5paw5rWq77yM6LGG55Oj77yM6IW+6K6v562J5Zu95YaF5b6u6JaET0F1dGjo
111
+ rqTor4E=
112
+
102
113
  test_files: []
103
114