mbleigh-twitter-auth 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 13
4
+ :patch: 14
@@ -48,7 +48,7 @@ class SessionsController < ApplicationController
48
48
  cookies[:remember_token] = @user.remember_me
49
49
 
50
50
  authentication_succeeded
51
- rescue Net::HTTPServerException, Net::HTTPFatalError => e
51
+ rescue Net::HTTPServerException, Net::HTTPFatalError, TwitterAuth::Dispatcher::Error => e
52
52
  case e.message
53
53
  when '401 "Unauthorized"'
54
54
  authentication_failed('This authentication request is no longer valid. Please try again.') and return
@@ -6,14 +6,16 @@ module TwitterAuth
6
6
  end
7
7
 
8
8
  base.extend TwitterAuth::OauthUser::ClassMethods
9
+ base.extend TwitterAuth::Dispatcher::Shared
9
10
  end
10
11
 
11
12
  module ClassMethods
12
13
  def identify_or_create_from_access_token(token, secret=nil)
13
14
  raise ArgumentError, 'Must authenticate with an OAuth::AccessToken or the string access token and secret.' unless (token && secret) || token.is_a?(OAuth::AccessToken)
14
-
15
- user_info = JSON.parse(token.get('/account/verify_credentials.json').body)
16
-
15
+
16
+ response = token.get(TwitterAuth.path_prefix + '/account/verify_credentials.json')
17
+ user_info = handle_response(response)
18
+
17
19
  if user = User.find_by_login(user_info['screen_name'])
18
20
  user.assign_twitter_attributes(user_info)
19
21
  user.access_token = token.token
data/lib/twitter_auth.rb CHANGED
@@ -10,6 +10,10 @@ module TwitterAuth
10
10
  config['base_url'] || 'https://twitter.com'
11
11
  end
12
12
 
13
+ def self.path_prefix
14
+ URI.parse(base_url).path
15
+ end
16
+
13
17
  def self.api_timeout
14
18
  config['api_timeout'] || 10
15
19
  end
@@ -13,6 +13,7 @@ module TwitterAuth
13
13
  end
14
14
 
15
15
  def request(http_method, path, body=nil, *arguments)
16
+ path = TwitterAuth.path_prefix + path
16
17
  path = append_extension_to(path)
17
18
 
18
19
  response = TwitterAuth.net.start{ |http|
@@ -14,8 +14,9 @@ module TwitterAuth
14
14
  end
15
15
 
16
16
  def request(http_method, path, *arguments)
17
+ path = TwitterAuth.path_prefix + path
17
18
  path = append_extension_to(path)
18
-
19
+
19
20
  response = super
20
21
 
21
22
  handle_response(response)
@@ -15,6 +15,8 @@ module TwitterAuth
15
15
  rescue JSON::ParserError
16
16
  response.body
17
17
  end
18
+ when Net::HTTPUnauthorized
19
+ raise TwitterAuth::Dispatcher::Error, 'The credentials provided did not authorize the user.'
18
20
  else
19
21
  message = begin
20
22
  JSON.parse(response.body)['error']
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe TwitterAuth do
4
- describe '#base_url' do
4
+ describe '.base_url' do
5
5
  it 'should have default to https://twitter.com' do
6
6
  TwitterAuth.stub!(:config).and_return({})
7
7
  TwitterAuth.base_url.should == 'https://twitter.com'
@@ -13,6 +13,18 @@ describe TwitterAuth do
13
13
  end
14
14
  end
15
15
 
16
+ describe ".path_prefix" do
17
+ it 'should be blank if the base url does not have a path' do
18
+ TwitterAuth.stub!(:base_url).and_return("https://twitter.com:443")
19
+ TwitterAuth.path_prefix.should == ""
20
+ end
21
+
22
+ it 'should return the path prefix if one exists' do
23
+ TwitterAuth.stub!(:base_url).and_return("https://api.presentlyapp.com/api/twitter")
24
+ TwitterAuth.path_prefix.should == "/api/twitter"
25
+ end
26
+ end
27
+
16
28
  describe '.api_timeout' do
17
29
  it 'should default to 10' do
18
30
  TwitterAuth.stub!(:config).and_return({})
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.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh