Skip to content

Commit

Permalink
Adding path prefix support for dispatchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Mar 27, 2009
1 parent dcd5f50 commit c499875
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/twitter_auth.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/twitter_auth/dispatcher/basic.rb
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions lib/twitter_auth/dispatcher/oauth.rb
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion 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'
Expand All @@ -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({})
Expand Down

0 comments on commit c499875

Please sign in to comment.