twitter-login 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/twitter/login.rb +22 -17
  2. metadata +45 -13
@@ -1,7 +1,11 @@
1
- require 'twitter'
1
+ require 'oauth'
2
+ require 'yajl'
2
3
  require 'rack/request'
3
4
  require 'hashie/mash'
4
5
 
6
+ module Twitter
7
+ end
8
+
5
9
  class Twitter::Login
6
10
  attr_reader :options
7
11
 
@@ -41,13 +45,12 @@ class Twitter::Login
41
45
 
42
46
  module Helpers
43
47
  def twitter_client
44
- oauth = twitter_oauth
45
- oauth.authorize_from_access(*session[:twitter_access_token])
46
- Twitter::Base.new oauth
48
+ OAuth::AccessToken.new(twitter_oauth, *session[:twitter_access_token])
47
49
  end
48
50
 
49
51
  def twitter_oauth
50
- Twitter::OAuth.new Twitter::Login.consumer_key, Twitter::Login.secret
52
+ OAuth::Consumer.new Twitter::Login.consumer_key, Twitter::Login.secret,
53
+ :site => 'http://api.twitter.com'
51
54
  end
52
55
 
53
56
  def twitter_user
@@ -87,17 +90,18 @@ class Twitter::Login
87
90
 
88
91
  def redirect_to_twitter(request)
89
92
  # create a request token and store its parameter in session
90
- oauth.set_callback_url(request.url)
91
- request.session[:twitter_request_token] = [oauth.request_token.token, oauth.request_token.secret]
93
+ request_token = oauth.get_request_token(:oauth_callback => request.url)
94
+ request.session[:twitter_request_token] = [request_token.token, request_token.secret]
92
95
  # redirect to Twitter authorization page
93
- redirect oauth.request_token.authorize_url
96
+ redirect request_token.authorize_url
94
97
  end
95
98
 
96
99
  def handle_twitter_authorization(request)
97
- authorize_from_request(request)
100
+ access_token = authorize_from_request(request)
101
+ response = access_token.get('/1/account/verify_credentials.json')
98
102
 
99
103
  # get and store authenticated user's info from Twitter
100
- request.session[:twitter_user] = twitter.verify_credentials.to_hash
104
+ request.session[:twitter_user] = Yajl::Parser.parse response.body
101
105
 
102
106
  # pass the request down to the main app
103
107
  response = begin
@@ -129,10 +133,12 @@ class Twitter::Login
129
133
  # replace the request token in session with access token
130
134
  def authorize_from_request(request)
131
135
  rtoken, rsecret = request.session[:twitter_request_token]
132
- oauth.authorize_from_request(rtoken, rsecret, request[:oauth_verifier])
136
+ request_token = OAuth::RequestToken.new(oauth, rtoken, rsecret)
137
+ access_token = request_token.get_access_token(:oauth_verifier => request[:oauth_verifier])
133
138
 
134
139
  request.session.delete(:twitter_request_token)
135
- request.session[:twitter_access_token] = [oauth.access_token.token, oauth.access_token.secret]
140
+ request.session[:twitter_access_token] = [access_token.token, access_token.secret]
141
+ return access_token
136
142
  end
137
143
 
138
144
  def redirect_to_return_path(request)
@@ -144,10 +150,9 @@ class Twitter::Login
144
150
  end
145
151
 
146
152
  def oauth
147
- @oauth ||= Twitter::OAuth.new options[:consumer_key], options[:secret], :sign_in => true
148
- end
149
-
150
- def twitter
151
- Twitter::Base.new oauth
153
+ @oauth ||= OAuth::Consumer.new(options[:consumer_key], options[:secret],
154
+ :site => 'http://api.twitter.com',
155
+ :authorize_path => '/oauth/authenticate'
156
+ )
152
157
  end
153
158
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter-login
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Mislav Marohni\xC4\x87"
@@ -15,29 +15,61 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-15 00:00:00 +02:00
18
+ date: 2010-09-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: twitter
22
+ name: oauth
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 49
29
+ hash: 11
30
30
  segments:
31
31
  - 0
32
- - 9
33
- - 5
34
- version: 0.9.5
32
+ - 4
33
+ - 2
34
+ version: 0.4.2
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: rspec
38
+ name: yajl-ruby
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 13
46
+ segments:
47
+ - 0
48
+ - 7
49
+ - 7
50
+ version: 0.7.7
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: hashie
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 19
62
+ segments:
63
+ - 0
64
+ - 2
65
+ - 2
66
+ version: 0.2.2
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
41
73
  none: false
42
74
  requirements:
43
75
  - - ~>
@@ -49,11 +81,11 @@ dependencies:
49
81
  - 9
50
82
  version: 1.2.9
51
83
  type: :development
52
- version_requirements: *id002
84
+ version_requirements: *id004
53
85
  - !ruby/object:Gem::Dependency
54
86
  name: fakeweb
55
87
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
88
+ requirement: &id005 !ruby/object:Gem::Requirement
57
89
  none: false
58
90
  requirements:
59
91
  - - ~>
@@ -65,7 +97,7 @@ dependencies:
65
97
  - 8
66
98
  version: 1.2.8
67
99
  type: :development
68
- version_requirements: *id003
100
+ version_requirements: *id005
69
101
  description: Rack middleware for Sinatra, Rails, and other web frameworks that provides user login functionality through Twitter.
70
102
  email: mislav.marohnic@gmail.com
71
103
  executables: []