Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added properties for background image and tiling as well as an Unauth…
…enticated error for better handling. [#8 state:resolved]
  • Loading branch information
Michael Bleigh committed Mar 30, 2009
1 parent 437b00b commit 6e20090
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/models/twitter_auth/generic_user.rb
Expand Up @@ -14,6 +14,8 @@ class GenericUser < ActiveRecord::Base
:profile_link_color,
:profile_sidebar_border_color,
:profile_text_color,
:profile_background_image_url,
:profile_background_tiled,
:friends_count,
:statuses_count,
:followers_count,
Expand Down
2 changes: 2 additions & 0 deletions generators/twitter_auth/templates/migration.rb
Expand Up @@ -27,6 +27,8 @@ def self.up
t.string :profile_link_color
t.string :profile_sidebar_border_color
t.string :profile_text_color
t.string :profile_background_image_url
t.boolean :profile_background_tiled
t.integer :friends_count
t.integer :statuses_count
t.integer :followers_count
Expand Down
8 changes: 7 additions & 1 deletion lib/twitter_auth.rb
Expand Up @@ -78,4 +78,10 @@ def self.net
require 'twitter_auth/dispatcher/basic'
require 'twitter_auth/dispatcher/shared'

class TwitterAuth::Dispatcher::Error < StandardError; end
module TwitterAuth
module Dispatcher
class Error < StandardError; end
class Unauthorized < Error; end
end
end

2 changes: 1 addition & 1 deletion lib/twitter_auth/dispatcher/shared.rb
Expand Up @@ -16,7 +16,7 @@ def handle_response(response)
response.body
end
when Net::HTTPUnauthorized
raise TwitterAuth::Dispatcher::Error, 'The credentials provided did not authorize the user.'
raise TwitterAuth::Dispatcher::Unauthorized, 'The credentials provided did not authorize the user.'
else
message = begin
JSON.parse(response.body)['error']
Expand Down
9 changes: 7 additions & 2 deletions spec/twitter_auth/dispatcher/basic_spec.rb
Expand Up @@ -54,12 +54,17 @@
end

it 'should set the error message to the JSON message' do
FakeWeb.register_uri('https://twitter.com:443/bad_response.json', :string => {'error' => 'bad response'}.to_json, :status => ['401', 'Unauthorized'])
FakeWeb.register_uri('https://twitter.com:443/bad_response.json', :string => {'error' => 'bad response'}.to_json, :status => ['403', 'Forbidden'])
lambda{@dispatcher.request(:get, '/bad_response')}.should raise_error(TwitterAuth::Dispatcher::Error, 'bad response')
end

it 'should raise a TwitterAuth::Dispatcher::Unauthorized on 401' do
FakeWeb.register_uri('https://twitter.com:443/unauthenticated_response.xml', :string => "<hash>\n<request>/unauthenticated_response.xml</request>\n<error>bad response</error>\n</hash>", :status => ['401', 'Unauthorized'])
lambda{@dispatcher.request(:get, '/unauthenticated_response.xml')}.should raise_error(TwitterAuth::Dispatcher::Unauthorized)
end

it 'should set the error message to the XML message' do
FakeWeb.register_uri('https://twitter.com:443/bad_response.xml', :string => "<hash>\n<request>/bad_response.xml</request>\n<error>bad response</error>\n</hash>", :status => ['401', 'Unauthorized'])
FakeWeb.register_uri('https://twitter.com:443/bad_response.xml', :string => "<hash>\n<request>/bad_response.xml</request>\n<error>bad response</error>\n</hash>", :status => ['403', 'Forbidden'])
lambda{@dispatcher.request(:get, '/bad_response')}.should raise_error(TwitterAuth::Dispatcher::Error, 'bad response')
end
end
Expand Down
11 changes: 8 additions & 3 deletions spec/twitter_auth/dispatcher/oauth_spec.rb
Expand Up @@ -51,13 +51,18 @@
end

it 'should set the error message to the JSON message' do
FakeWeb.register_uri('https://twitter.com:443/bad_response.json', :string => {'error' => 'bad response'}.to_json, :status => ['401', 'Unauthorized'])
FakeWeb.register_uri('https://twitter.com:443/bad_response.json', :string => {'error' => 'bad response'}.to_json, :status => ['403', 'Forbidden'])
lambda{@dispatcher.request(:get, '/bad_response')}.should raise_error(TwitterAuth::Dispatcher::Error, 'bad response')
end

it 'should set the error message to the XML message' do
FakeWeb.register_uri('https://twitter.com:443/bad_response.xml', :string => "<hash>\n<request>/bad_response.xml</request>\n<error>bad response</error>\n</hash>", :status => ['401', 'Unauthorized'])
lambda{@dispatcher.request(:get, '/bad_response')}.should raise_error(TwitterAuth::Dispatcher::Error, 'bad response')
FakeWeb.register_uri('https://twitter.com:443/bad_response.xml', :string => "<hash>\n<request>/bad_response.xml</request>\n<error>bad response</error>\n</hash>", :status => ['403', 'Forbidden'])
lambda{@dispatcher.request(:get, '/bad_response.xml')}.should raise_error(TwitterAuth::Dispatcher::Error, 'bad response')
end

it 'should raise a TwitterAuth::Dispatcher::Unauthorized on 401' do
FakeWeb.register_uri('https://twitter.com:443/unauthenticated_response.xml', :string => "<hash>\n<request>/unauthenticated_response.xml</request>\n<error>bad response</error>\n</hash>", :status => ['401', 'Unauthorized'])
lambda{@dispatcher.request(:get, '/unauthenticated_response.xml')}.should raise_error(TwitterAuth::Dispatcher::Unauthorized)
end

it 'should work with verb methods' do
Expand Down

0 comments on commit 6e20090

Please sign in to comment.