Skip to content

Commit

Permalink
Rename URL_PREFIX to BASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 6, 2014
1 parent e0d4c36 commit 73e2b9b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/twitter/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Twitter
module REST
class Client < Twitter::Client
include Twitter::REST::API
URL_PREFIX = 'https://api.twitter.com'
BASE_URL = 'https://api.twitter.com'
attr_accessor :bearer_token

# @param connection_options [Hash]
Expand Down Expand Up @@ -92,7 +92,7 @@ def credentials?
#
# @return [Faraday::Connection]
def connection
@connection ||= Faraday.new(URL_PREFIX, connection_options)
@connection ||= Faraday.new(BASE_URL, connection_options)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/rest/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ module Media
# @param options [Hash] A customizable set of options.
def upload(media, options = {})
fail(Twitter::Error::UnacceptableIO.new) unless media.respond_to?(:to_io)
url_prefix = 'https://upload.twitter.com'
base_url = 'https://upload.twitter.com'
path = '/1.1/media/upload.json'
conn = connection.dup
conn.url_prefix = url_prefix
headers = Twitter::Headers.new(self, :post, url_prefix + path, options).request_headers
conn.url_prefix = base_url
headers = Twitter::Headers.new(self, :post, base_url + path, options).request_headers
options.merge!(:media => media)
conn.post(path, options) { |request| request.headers.update(headers) }.env.body[:media_id]
end
Expand Down
8 changes: 5 additions & 3 deletions lib/twitter/rest/request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'addressable/uri'
require 'faraday'
require 'json'
require 'timeout'
Expand All @@ -8,9 +9,9 @@
module Twitter
module REST
class Request
attr_accessor :client, :headers, :rate_limit, :request_method, :path, :options
attr_accessor :client, :headers, :options, :rate_limit, :request_method,
:path, :uri
alias_method :verb, :request_method
URL_PREFIX = 'https://api.twitter.com'

# @param client [Twitter::Client]
# @param request_method [String, Symbol]
Expand All @@ -21,12 +22,13 @@ def initialize(client, request_method, path, options = {})
@client = client
@request_method = request_method.to_sym
@path = path
@uri = Addressable::URI.parse(client.connection.url_prefix + path)
@options = options
end

# @return [Array, Hash]
def perform
@headers = Twitter::Headers.new(@client, @request_method, URL_PREFIX + @path, @options).request_headers
@headers = Twitter::Headers.new(@client, @request_method, @uri.to_s, @options).request_headers
begin
response = @client.connection.send(@request_method, @path, @options) { |request| request.headers.update(@headers) }.env
rescue Faraday::Error::TimeoutError, Timeout::Error => error
Expand Down
16 changes: 8 additions & 8 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,35 @@
end

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

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

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

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

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

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

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

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

def fixture_path
Expand Down
6 changes: 3 additions & 3 deletions spec/twitter/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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::URL_PREFIX + '/path')
@headers = Twitter::Headers.new(@client, :get, Twitter::REST::Client::BASE_URL + '/path')
end

describe '#oauth_auth_header' do
Expand Down Expand Up @@ -40,14 +40,14 @@
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::URL_PREFIX + '/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
it 'creates the correct auth headers with supplied Twitter::Token' do
token = Twitter::Token.new(:token_type => 'bearer', :access_token => 'BT')
client = Twitter::REST::Client.new(:bearer_token => token)
headers = Twitter::Headers.new(client, :get, Twitter::REST::Request::URL_PREFIX + '/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 73e2b9b

Please sign in to comment.