Skip to content

Commit

Permalink
move the BASE_URL constant from the Request to the Client
Browse files Browse the repository at this point in the history
different clients have different base urls so this needs to be
determined in a more dynamic way
  • Loading branch information
stve committed Feb 2, 2015
1 parent 93532fd commit cb2c047
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/twitter/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Twitter
module REST
class Client < Twitter::Client
include Twitter::REST::API
BASE_URL = 'https://api.twitter.com'
attr_accessor :bearer_token

# @return [Boolean]
Expand Down
3 changes: 1 addition & 2 deletions lib/twitter/rest/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module Twitter
module REST
class Request
include Twitter::Utils
BASE_URL = 'https://api.twitter.com'
attr_accessor :client, :headers, :multipart, :options, :path,
:rate_limit, :request_method, :uri
alias_method :verb, :request_method
Expand All @@ -27,7 +26,7 @@ class Request
def initialize(client, request_method, path, options = {})
@client = client
set_multipart_options!(request_method, options)
@uri = Addressable::URI.parse(path.start_with?('http') ? path : BASE_URL + path)
@uri = Addressable::URI.parse(path.start_with?('http') ? path : @client.class.const_get(:BASE_URL) + path)
@path = uri.path
@options = options
end
Expand Down
16 changes: 8 additions & 8 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@
end

def a_delete(path)
a_request(:delete, Twitter::REST::Request::BASE_URL + path)
a_request(:delete, Twitter::REST::Client::BASE_URL + path)
end

def a_get(path, klass = Twitter::REST::Request)
def a_get(path, klass = Twitter::REST::Client)
a_request(:get, klass::BASE_URL + path)
end

def a_post(path, klass = Twitter::REST::Request)
def a_post(path, klass = Twitter::REST::Client)
a_request(:post, klass::BASE_URL + path)
end

def a_put(path)
a_request(:put, Twitter::REST::Request::BASE_URL + path)
a_request(:put, Twitter::REST::Client::BASE_URL + path)
end

def stub_delete(path)
stub_request(:delete, Twitter::REST::Request::BASE_URL + path)
stub_request(:delete, Twitter::REST::Client::BASE_URL + path)
end

def stub_get(path, klass = Twitter::REST::Request)
def stub_get(path, klass = Twitter::REST::Client)
stub_request(:get, klass::BASE_URL + path)
end

def stub_post(path, klass = Twitter::REST::Request)
def stub_post(path, klass = Twitter::REST::Client)
stub_request(:post, klass::BASE_URL + path)
end

def stub_put(path)
stub_request(:put, Twitter::REST::Request::BASE_URL + path)
stub_request(:put, Twitter::REST::Client::BASE_URL + path)
end

def fixture_path
Expand Down
4 changes: 2 additions & 2 deletions spec/twitter/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Twitter::Headers do
before do
@client = Twitter::REST::Client.new(consumer_key: 'CK', consumer_secret: 'CS', access_token: 'AT', access_token_secret: 'AS')
@headers = Twitter::Headers.new(@client, :get, Twitter::REST::Request::BASE_URL + '/path')
@headers = Twitter::Headers.new(@client, :get, Twitter::REST::Client::BASE_URL + '/path')
end

describe '#oauth_auth_header' do
Expand Down Expand Up @@ -40,7 +40,7 @@
describe '#bearer_auth_header' do
it 'creates the correct auth headers with supplied bearer token' do
client = Twitter::REST::Client.new(bearer_token: 'BT')
headers = Twitter::Headers.new(client, :get, Twitter::REST::Request::BASE_URL + '/path')
headers = Twitter::Headers.new(client, :get, Twitter::REST::Client::BASE_URL + '/path')
authorization = headers.send(:bearer_auth_header)
expect(authorization).to eq('Bearer BT')
end
Expand Down

0 comments on commit cb2c047

Please sign in to comment.