From dc1bb07d96a83fdf6d88e806626c52f29f455d01 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Fri, 27 Mar 2009 15:20:01 -0400 Subject: [PATCH] Adding path prefix support for dispatchers. --- lib/twitter_auth.rb | 4 ++++ lib/twitter_auth/dispatcher/basic.rb | 1 + lib/twitter_auth/dispatcher/oauth.rb | 1 + spec/twitter_auth_spec.rb | 14 +++++++++++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/twitter_auth.rb b/lib/twitter_auth.rb index d0a59dd..7f14936 100644 --- a/lib/twitter_auth.rb +++ b/lib/twitter_auth.rb @@ -10,6 +10,10 @@ def self.base_url config['base_url'] || 'https://twitter.com' end + def self.path_prefix + URI.parse(base_url).path + end + def self.api_timeout config['api_timeout'] || 10 end diff --git a/lib/twitter_auth/dispatcher/basic.rb b/lib/twitter_auth/dispatcher/basic.rb index 749321d..675de00 100644 --- a/lib/twitter_auth/dispatcher/basic.rb +++ b/lib/twitter_auth/dispatcher/basic.rb @@ -13,6 +13,7 @@ def initialize(user) end def request(http_method, path, body=nil, *arguments) + path = TwitterAuth.path_prefix + path path = append_extension_to(path) response = TwitterAuth.net.start{ |http| diff --git a/lib/twitter_auth/dispatcher/oauth.rb b/lib/twitter_auth/dispatcher/oauth.rb index 859d2ae..0c43f20 100644 --- a/lib/twitter_auth/dispatcher/oauth.rb +++ b/lib/twitter_auth/dispatcher/oauth.rb @@ -14,6 +14,7 @@ def initialize(user) end def request(http_method, path, *arguments) + path = TwitterAuth.path_prefix + path path = append_extension_to(path) response = super diff --git a/spec/twitter_auth_spec.rb b/spec/twitter_auth_spec.rb index b0dfd13..8776cf8 100644 --- a/spec/twitter_auth_spec.rb +++ b/spec/twitter_auth_spec.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/spec_helper' describe TwitterAuth do - describe '#base_url' do + describe '.base_url' do it 'should have default to https://twitter.com' do TwitterAuth.stub!(:config).and_return({}) TwitterAuth.base_url.should == 'https://twitter.com' @@ -13,6 +13,18 @@ end end + describe ".path_prefix" do + it 'should be blank if the base url does not have a path' do + TwitterAuth.stub!(:base_url).and_return("https://twitter.com:443") + TwitterAuth.path_prefix.should == "" + end + + it 'should return the path prefix if one exists' do + TwitterAuth.stub!(:base_url).and_return("https://api.presentlyapp.com/api/twitter") + TwitterAuth.path_prefix.should == "/api/twitter" + end + end + describe '.api_timeout' do it 'should default to 10' do TwitterAuth.stub!(:config).and_return({})