weibo_2 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +27 -1
  2. data/lib/weibo_2/version.rb +2 -2
  3. data/lib/weibo_2.rb +16 -0
  4. metadata +2 -2
data/README.md CHANGED
@@ -101,5 +101,31 @@ It should work.
101
101
 
102
102
  For Fedora and CentOS, use the path and file `/etc/pki/tls/certs/ca-bundle.crt` instead, or find your system path with `openssl version -a`.
103
103
 
104
+ ## Integrate with Devise and omniauth
104
105
 
105
-
106
+ 1. Install gems in Gemfile
107
+
108
+ ```ruby
109
+ gem 'devise'
110
+ gem 'omniauth'
111
+ gem 'omniauth-weibo-oauth2'
112
+ gem 'weibo_2'
113
+ ```
114
+
115
+
116
+ 2. In devise initailize file config/initiallizers/devise.rb, add a line into setup block, please replace key and secret with yours.
117
+
118
+ ```ruby
119
+ config.omniauth :weibo, 'key', 'secret', :scope => 'user,public_repo'
120
+ ```
121
+
122
+ 3. Then you should handle omini callback controller by yourself, there is sample project show how to integrate devise and omniauth you can follow [devise-omniauth-example](https://github.com/holden/devise-omniauth-example)
123
+
124
+ 4. After get the callback data, you will see `env['omniauth.auth']['credentials']` has the value `token` and `expires_at`, store them into session or record,now you can use WeiboOAuth2 in anywhere:
125
+
126
+ ```ruby
127
+ client = WeiboOAuth2::Client.new
128
+ client.get_token_from_hash({:access_token=>session[:token],:expires_at=>session[:expires_at]})
129
+ statuses = client.statuses
130
+ statuses.update('just test from my app')
131
+ ```
@@ -2,8 +2,8 @@ module WeiboOAuth2
2
2
 
3
3
  class Version
4
4
  MAJOR = 0 unless defined? MAJOR
5
- MINOR = 0 unless defined? MINOR
6
- PATCH = 9 unless defined? PATCH
5
+ MINOR = 1 unless defined? MINOR
6
+ PATCH = 0 unless defined? PATCH
7
7
  PRE = nil unless defined? PRE
8
8
 
9
9
  class << self
data/lib/weibo_2.rb CHANGED
@@ -18,3 +18,19 @@ require "weibo_2/api/v2/short_url"
18
18
  require "weibo_2/api/v2/suggestions"
19
19
  require "weibo_2/api/v2/remind"
20
20
  require "weibo_2/strategy/auth_code"
21
+
22
+
23
+ if defined?(Rails)
24
+ module WeiboOAuth2
25
+ class Railtie < Rails::Railtie
26
+ initializer "weibo_oauth2" do
27
+ ActiveSupport.on_load :action_controller do
28
+ if Object.const_defined?("Devise") && Devise.omniauth_configs[:weibo]
29
+ WeiboOAuth2::Config.api_key = Devise.omniauth_configs[:weibo].strategy.client_id
30
+ WeiboOAuth2::Config.api_secret = Devise.omniauth_configs[:weibo].strategy.client_secret
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weibo_2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-23 00:00:00.000000000 Z
12
+ date: 2012-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec