twitter-login 0.3.0 → 0.3.1
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/lib/twitter/login.rb +11 -1
- data/spec/login_spec.rb +16 -19
- metadata +6 -6
data/lib/twitter/login.rb
CHANGED
@@ -101,7 +101,7 @@ class Twitter::Login
|
|
101
101
|
response = access_token.get('/1/account/verify_credentials.json')
|
102
102
|
|
103
103
|
# get and store authenticated user's info from Twitter
|
104
|
-
request.session[:twitter_user] =
|
104
|
+
request.session[:twitter_user] = user_hash_from_response(response)
|
105
105
|
|
106
106
|
# pass the request down to the main app
|
107
107
|
response = begin
|
@@ -155,4 +155,14 @@ class Twitter::Login
|
|
155
155
|
:authorize_path => '/oauth/authenticate'
|
156
156
|
)
|
157
157
|
end
|
158
|
+
|
159
|
+
def user_hash_from_response(api_response)
|
160
|
+
parse_response(api_response).reject { |key, _|
|
161
|
+
key == 'status' or key =~ /^profile_|_color$/
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
def parse_response(api_response)
|
166
|
+
Yajl::Parser.parse api_response.body
|
167
|
+
end
|
158
168
|
end
|
data/spec/login_spec.rb
CHANGED
@@ -44,38 +44,35 @@ describe Twitter::Login do
|
|
44
44
|
|
45
45
|
it "should login with Twitter" do
|
46
46
|
request_token = mock('Request Token', :authorize_url => 'http://disney.com/oauth', :token => 'abc', :secret => '123')
|
47
|
-
oauth = mock_oauth('Twitter OAuth'
|
48
|
-
oauth.should_receive(:
|
47
|
+
oauth = mock_oauth('Twitter OAuth')
|
48
|
+
oauth.should_receive(:get_request_token).with(:oauth_callback => 'http://example.org/login').and_return(request_token)
|
49
49
|
|
50
50
|
get('/login', :lint => true)
|
51
51
|
response.status.should == 302
|
52
52
|
response['Location'].should == 'http://disney.com/oauth'
|
53
53
|
response.body.should be_empty
|
54
|
-
session[:
|
54
|
+
session[:twitter_request_token].should == ['abc', '123']
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should authorize with Twitter" do
|
58
|
-
|
58
|
+
oauth = mock_oauth('Twitter OAuth')
|
59
|
+
request_token = mock('Request Token')
|
60
|
+
OAuth::RequestToken.should_receive(:new).with(oauth, 'abc', '123').and_return(request_token)
|
59
61
|
access_token = mock('Access Token', :token => 'access1', :secret => '42')
|
60
|
-
|
61
|
-
oauth.should_receive(:authorize_from_request).with('abc', '123', 'allrighty')
|
62
|
+
request_token.should_receive(:get_access_token).with(:oauth_verifier => 'allrighty').and_return(access_token)
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
payload = { :screen_name => 'faker', :name => 'Fake Jr.', :followers_count => '13',
|
65
|
+
:profile_image_url => 'http://disney.com/mickey.png', :friends_count => '6', :statuses_count => '52' }
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
:name => 'Fake Jr.', :profile_image_url => 'http://disney.com/mickey.png',
|
69
|
-
:followers_count => '13', :friends_count => '6', :statuses_count => '52'
|
70
|
-
}
|
67
|
+
http_response = mock('HTTP response', :body => Yajl::Encoder.encode(payload))
|
68
|
+
access_token.should_receive(:get).with('/1/account/verify_credentials.json').and_return(http_response)
|
71
69
|
|
72
|
-
session_data = {:
|
70
|
+
session_data = {:twitter_request_token => ['abc', '123']}
|
73
71
|
get('/login?oauth_verifier=allrighty', build_session(session_data).update(:lint => true))
|
74
72
|
response.status.should == 302
|
75
73
|
response['Location'].should == 'http://example.org/'
|
76
|
-
session[:
|
77
|
-
session[:
|
78
|
-
session[:oauth_consumer].should be_nil
|
74
|
+
session[:twitter_request_token].should be_nil
|
75
|
+
session[:twitter_access_token].should == ['access1', '42']
|
79
76
|
|
80
77
|
current_user = session[:twitter_user]
|
81
78
|
current_user['screen_name'].should == 'faker'
|
@@ -86,7 +83,7 @@ describe Twitter::Login do
|
|
86
83
|
get('/login?denied=OMG', build_session(session_data).update(:lint => true))
|
87
84
|
response.status.should == 302
|
88
85
|
response['Location'].should == 'http://example.org/'
|
89
|
-
session[:
|
86
|
+
session[:twitter_request_token].should be_nil
|
90
87
|
end
|
91
88
|
|
92
89
|
protected
|
@@ -124,7 +121,7 @@ describe Twitter::Login do
|
|
124
121
|
|
125
122
|
def mock_oauth(*args)
|
126
123
|
consumer = mock(*args)
|
127
|
-
|
124
|
+
OAuth::Consumer.should_receive(:new).and_return(consumer)
|
128
125
|
consumer
|
129
126
|
end
|
130
127
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Mislav Marohni\xC4\x87"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-17 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
requirements: []
|
141
141
|
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 1.
|
143
|
+
rubygems_version: 1.5.0
|
144
144
|
signing_key:
|
145
145
|
specification_version: 3
|
146
146
|
summary: Rack middleware to provide login functionality through Twitter
|