weibo_2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/example/Gemfile CHANGED
@@ -3,4 +3,4 @@ source :rubygems
3
3
  gem 'sinatra'
4
4
  gem "haml"
5
5
  gem "sass"
6
- gem 'weibo_2', :path => '../'
6
+ gem 'weibo_2'
data/example/config.ru CHANGED
@@ -1,2 +1,2 @@
1
- require 'example'
1
+ require './example.rb'
2
2
  run Sinatra::Application
data/example/example.rb CHANGED
@@ -5,7 +5,11 @@ Bundler.setup
5
5
  %w(sinatra haml sass).each { |dependency| require dependency }
6
6
  enable :sessions
7
7
 
8
- client = WeiboOAuth2::Client.new('1317413087', '79c39d8c66a93bd15f16ed0e999532f9')
8
+ WeiboOAuth2::Config.api_key = ENV['KEY']
9
+ WeiboOAuth2::Config.api_secret = ENV['SECRET']
10
+ WeiboOAuth2::Config.redirect_uri = ENV['REDIR_URI']
11
+
12
+ client = WeiboOAuth2::Client.new
9
13
 
10
14
  get '/' do
11
15
  if session[:access_token] && !client.authorized?
@@ -18,13 +22,11 @@ get '/' do
18
22
  end
19
23
 
20
24
  get '/connect' do
21
-
22
- url = client.authorize_url(:redirect_uri => 'http://127.0.0.1:4567/callback')
23
- redirect url
25
+ redirect client.authorize_url
24
26
  end
25
27
 
26
28
  get '/callback' do
27
- access_token = client.auth_code.get_token(params[:code].to_s, :redirect_uri => 'http://127.0.0.1:4567/callback')
29
+ access_token = client.auth_code.get_token(params[:code].to_s)
28
30
  session[:uid] = access_token.params["uid"]
29
31
  session[:access_token] = access_token.token
30
32
  session[:expires_at] = access_token.expires_at
@@ -3,7 +3,9 @@ require 'oauth2'
3
3
  module WeiboOAuth2
4
4
  class Client < OAuth2::Client
5
5
 
6
- def initialize(client_id, client_secret, opts={}, &block)
6
+ def initialize(client_id='', client_secret='', opts={}, &block)
7
+ client_id = WeiboOAuth2::Config.api_key if client_id.empty?
8
+ client_secret = WeiboOAuth2::Config.api_secret if client_secret.empty?
7
9
  super
8
10
  @site = "https://api.weibo.com/2/"
9
11
  @options[:authorize_url] = '/oauth2/authorize'
@@ -13,6 +15,7 @@ module WeiboOAuth2
13
15
  def authorize_url(params=nil)
14
16
  params[:client_id] = @id unless params[:client_id]
15
17
  params[:response_type] = 'code' unless params[:response_type]
18
+ params[:redirect_uri] = WeiboOAuth2::Config.redirect_uri unless params[:redirect_uri]
16
19
  super
17
20
  end
18
21
 
@@ -0,0 +1,29 @@
1
+ module WeiboOAuth2
2
+ module Config
3
+
4
+ def self.api_key=(val)
5
+ @@api_key = val
6
+ end
7
+
8
+ def self.api_key
9
+ @@api_key
10
+ end
11
+
12
+ def self.api_secret=(val)
13
+ @@api_secret = val
14
+ end
15
+
16
+ def self.api_secret
17
+ @@api_secret
18
+ end
19
+
20
+ def self.redirect_uri=(val)
21
+ @@redirect_uri = val
22
+ end
23
+
24
+ def self.redirect_uri
25
+ @@redirect_uri
26
+ end
27
+
28
+ end
29
+ end
@@ -2,7 +2,9 @@ module WeiboOAuth2
2
2
  module Strategy
3
3
  class AuthCode < OAuth2::Strategy::AuthCode
4
4
  def get_token(code, params={}, opts={})
5
- params = {'grant_type' => 'authorization_code', 'code' => code}.merge(client_params).merge(params)
5
+ params = {'grant_type' => 'authorization_code',
6
+ 'code' => code,
7
+ 'redirect_uri' => WeiboOAuth2::Config.redirect_uri.to_s}.merge(client_params).merge(params)
6
8
  @client.get_and_restore_token(params, opts)
7
9
  end
8
10
  end
@@ -1,3 +1,3 @@
1
1
  module WeiboOAuth2
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -88,6 +88,7 @@ files:
88
88
  - README.md
89
89
  - Rakefile
90
90
  - example/.sass-cache/80b2331c862c6e430e0af18caf62d12d982610f0/screen.sassc
91
+ - example/.sass-cache/faf9751221db0b5ce76d45351b9591c3bfc59441/screen.sassc
91
92
  - example/Gemfile
92
93
  - example/config.ru
93
94
  - example/example.rb
@@ -115,6 +116,7 @@ files:
115
116
  - lib/weibo_2/api/v2/users.rb
116
117
  - lib/weibo_2/base.rb
117
118
  - lib/weibo_2/client.rb
119
+ - lib/weibo_2/config.rb
118
120
  - lib/weibo_2/oauth.rb
119
121
  - lib/weibo_2/strategy/auth_code.rb
120
122
  - lib/weibo_2/version.rb