mbleigh-twitter-auth 0.1.5 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown
CHANGED
@@ -59,6 +59,8 @@ The `User` class will have a `twitter` method that provides a generic dispatcher
|
|
59
59
|
user.twitter.post('/statuses/update.json', 'status' => 'This is my status.')
|
60
60
|
# => {"user"=>{"login" => "mbleigh" ... }, "text"=>"This is my status.", "id"=>1234567890 ... }
|
61
61
|
|
62
|
+
If Twitter returns something other than a 200 response code, TwitterAuth will catch it and try to raise a salient error message. The exception class is `TwitterAuth::Dispatcher::Error` if you're in the mood to catch it.
|
63
|
+
|
62
64
|
This area of the code is still a little raw, but hopefully will evolve to be a little more user-friendly as TwitterAuth matures. In the meantime, it's a perfectly workable foundation library, and the fact that it works the same with OAuth and HTTP Basic makes it all the better!
|
63
65
|
|
64
66
|
Customizing TwitterAuth
|
data/VERSION.yml
CHANGED
@@ -23,9 +23,9 @@ module TwitterAuth
|
|
23
23
|
]
|
24
24
|
|
25
25
|
validates_presence_of :login
|
26
|
-
validates_format_of :login, :with => /\A[a-z0-9_]+\z/
|
26
|
+
validates_format_of :login, :with => /\A[a-z0-9_]+\z/i
|
27
27
|
validates_length_of :login, :in => 1..15
|
28
|
-
validates_uniqueness_of :login
|
28
|
+
validates_uniqueness_of :login, :case_sensitive => false
|
29
29
|
|
30
30
|
def self.table_name; 'users' end
|
31
31
|
|
@@ -15,7 +15,10 @@ module TwitterAuth
|
|
15
15
|
user_info = JSON.parse(token.get('/account/verify_credentials.json').body)
|
16
16
|
|
17
17
|
if user = User.find_by_login(user_info['screen_name'])
|
18
|
-
user.
|
18
|
+
user.assign_twitter_attributes(user_info)
|
19
|
+
user.access_token = token.token
|
20
|
+
user.access_secret = token.secret
|
21
|
+
user.save
|
19
22
|
user
|
20
23
|
else
|
21
24
|
User.create_from_twitter_hash_and_token(user_info, token)
|
@@ -11,6 +11,15 @@ describe TwitterAuth::GenericUser do
|
|
11
11
|
Factory.build(:twitter_oauth_user).should have_at_least(1).errors_on(:login)
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'should allow capital letters in the username' do
|
15
|
+
Factory.build(:twitter_oauth_user, :login => 'TwitterMan').should have(:no).errors_on(:login)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not allow the same login with different capitalization' do
|
19
|
+
Factory.create(:twitter_oauth_user, :login => 'twitterman')
|
20
|
+
Factory.build(:twitter_oauth_user, :login => 'TwitterMan').should have_at_least(1).errors_on(:login)
|
21
|
+
end
|
22
|
+
|
14
23
|
describe '.new_from_twitter_hash' do
|
15
24
|
it 'should raise an argument error if the hash does not have a screen_name attribute' do
|
16
25
|
lambda{User.new_from_twitter_hash({})}.should raise_error(ArgumentError, 'Invalid hash: must include screen_name.')
|
@@ -34,9 +34,18 @@ describe TwitterAuth::OauthUser do
|
|
34
34
|
|
35
35
|
it 'should return the user if he/she exists' do
|
36
36
|
user = Factory.create(:twitter_oauth_user, :login => 'twitterman')
|
37
|
+
user.reload
|
37
38
|
User.identify_or_create_from_access_token(@token).should == user
|
38
39
|
end
|
39
40
|
|
41
|
+
it 'should update the access_token and access_secret for the user if he/she exists' do
|
42
|
+
user = Factory.create(:twitter_oauth_user, :login => 'twitterman', :access_token => 'someothertoken', :access_secret => 'someothersecret')
|
43
|
+
User.identify_or_create_from_access_token(@token)
|
44
|
+
user.reload
|
45
|
+
user.access_token.should == @token.token
|
46
|
+
user.access_secret.should == @token.secret
|
47
|
+
end
|
48
|
+
|
40
49
|
it 'should update the user\'s attributes based on the twitter info' do
|
41
50
|
user = Factory.create(:twitter_oauth_user, :login => 'twitterman', :name => 'Not Twitter Man')
|
42
51
|
User.identify_or_create_from_access_token(@token).name.should == 'Twitter Man'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mbleigh-twitter-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|