sinatra-twitter-oauth 0.0.1 → 0.0.2
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.rdoc +2 -0
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/sinatra-twitter-oauth.rb +2 -2
- data/lib/sinatra-twitter-oauth/helpers.rb +17 -5
- data/sinatra-twitter-oauth.gemspec +2 -2
- metadata +3 -1
data/README.rdoc
CHANGED
@@ -13,6 +13,7 @@ A simple sinatra extension for using twitter oauth for login
|
|
13
13
|
:callback => 'example.com/foo/auth'
|
14
14
|
get '/' do
|
15
15
|
login_required
|
16
|
+
"hello #{user}"
|
16
17
|
end
|
17
18
|
=== using Sinatra::Base
|
18
19
|
|
@@ -25,6 +26,7 @@ A simple sinatra extension for using twitter oauth for login
|
|
25
26
|
:callback => 'example.com/foo/auth'
|
26
27
|
get '/' do
|
27
28
|
login_required
|
29
|
+
"hello #{user}"
|
28
30
|
end
|
29
31
|
end
|
30
32
|
== Note on Patches/Pull Requests
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/baroquebobcat/sinatra-twitter-oauth"
|
12
12
|
gem.authors = ["Nick Howard"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.rdoc_options << "--main" << "README.rdoc"
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -24,14 +24,14 @@ module Sinatra
|
|
24
24
|
:login_template => {:text=>'<a href="/connect">Login using Twitter</a>'}
|
25
25
|
}
|
26
26
|
|
27
|
-
def self.registered app
|
27
|
+
def self.registered app # :nodoc:
|
28
28
|
|
29
29
|
app.helpers Helpers
|
30
30
|
app.enable :sessions
|
31
31
|
app.set :twitter_oauth_config, DEFAULT_CONFIG
|
32
32
|
|
33
33
|
app.get '/login' do
|
34
|
-
redirect '/' if
|
34
|
+
redirect '/' if user
|
35
35
|
|
36
36
|
login_template = options.twitter_oauth_config[:login_template]
|
37
37
|
|
@@ -1,6 +1,14 @@
|
|
1
1
|
module Sinatra::TwitterOAuth
|
2
|
+
#Helpers exposed by the extension.
|
3
|
+
#
|
2
4
|
module Helpers
|
3
5
|
|
6
|
+
# The current logged in user
|
7
|
+
def user
|
8
|
+
@user
|
9
|
+
end
|
10
|
+
|
11
|
+
# Redirects to login unless there is an authenticated user
|
4
12
|
def login_required
|
5
13
|
setup_client
|
6
14
|
|
@@ -8,19 +16,20 @@ module Sinatra::TwitterOAuth
|
|
8
16
|
|
9
17
|
@rate_limit_status = @client.rate_limit_status
|
10
18
|
|
11
|
-
redirect '/login' unless
|
19
|
+
redirect '/login' unless user
|
12
20
|
end
|
13
21
|
|
14
|
-
|
22
|
+
|
23
|
+
def setup_client # :nodoc:
|
15
24
|
@client ||= ::TwitterOAuth::Client.new(
|
16
25
|
:consumer_secret => options.twitter_oauth_config[:secret],
|
17
26
|
:consumer_key => options.twitter_oauth_config[:key],
|
18
27
|
:token => session[:access_token],
|
19
28
|
:secret => session[:secret_token]
|
20
29
|
)
|
21
|
-
end
|
30
|
+
end
|
22
31
|
|
23
|
-
def get_request_token
|
32
|
+
def get_request_token # :nodoc:
|
24
33
|
setup_client
|
25
34
|
|
26
35
|
begin
|
@@ -30,7 +39,7 @@ module Sinatra::TwitterOAuth
|
|
30
39
|
end
|
31
40
|
end
|
32
41
|
|
33
|
-
def get_access_token
|
42
|
+
def get_access_token # :nodoc:
|
34
43
|
setup_client
|
35
44
|
|
36
45
|
begin
|
@@ -44,6 +53,7 @@ module Sinatra::TwitterOAuth
|
|
44
53
|
end
|
45
54
|
end
|
46
55
|
|
56
|
+
# gets the request token and redirects to twitter's OAuth endpoint
|
47
57
|
def redirect_to_twitter_auth_url
|
48
58
|
request_token = get_request_token
|
49
59
|
|
@@ -53,6 +63,7 @@ module Sinatra::TwitterOAuth
|
|
53
63
|
redirect request_token.authorize_url.gsub('authorize','authenticate')
|
54
64
|
end
|
55
65
|
|
66
|
+
# attempts to get the access token(MUST be used after user has been redirected back from twitter)
|
56
67
|
def authenticate!
|
57
68
|
access_token = get_access_token
|
58
69
|
|
@@ -67,6 +78,7 @@ module Sinatra::TwitterOAuth
|
|
67
78
|
end
|
68
79
|
end
|
69
80
|
|
81
|
+
#removes all the session data defined by the extension
|
70
82
|
def clear_oauth_session
|
71
83
|
session[:user] = nil
|
72
84
|
session[:request_token] = nil
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-twitter-oauth}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nick Howard"]
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"spec/spec_helper.rb"
|
32
32
|
]
|
33
33
|
s.homepage = %q{http://github.com/baroquebobcat/sinatra-twitter-oauth}
|
34
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.rdoc_options = ["--charset=UTF-8", "--main", "README.rdoc"]
|
35
35
|
s.require_paths = ["lib"]
|
36
36
|
s.rubygems_version = %q{1.3.5}
|
37
37
|
s.summary = %q{A Sinatra Extension that simplifies using twitter for login and authentication.}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-twitter-oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Howard
|
@@ -51,6 +51,8 @@ licenses: []
|
|
51
51
|
post_install_message:
|
52
52
|
rdoc_options:
|
53
53
|
- --charset=UTF-8
|
54
|
+
- --main
|
55
|
+
- README.rdoc
|
54
56
|
require_paths:
|
55
57
|
- lib
|
56
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|