Skip to content

Commit

Permalink
Rename Twitter::REST::Client::ENDPOINT to URL_PREFIX
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 24, 2014
1 parent 28bf870 commit ecea9c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions lib/twitter/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module REST
class Client < Twitter::Client
include Twitter::REST::API
attr_accessor :bearer_token
ENDPOINT = 'https://api.twitter.com'
URL_PREFIX = 'https://api.twitter.com'

# @param connection_options [Hash]
# @return [Hash]
Expand Down Expand Up @@ -74,13 +74,13 @@ def middleware

# Perform an HTTP GET request
def get(path, params = {})
headers = request_headers(:get, path, params)
headers = request_headers(:get, URL_PREFIX + path, params)
request(:get, path, params, headers)
end

# Perform an HTTP POST request
def post(path, params = {})
headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:post, path, params)
headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, URL_PREFIX + path, params, {}) : request_headers(:post, URL_PREFIX + path, params)
request(:post, path, params, headers)
end

Expand All @@ -100,7 +100,7 @@ def credentials?
#
# @return [Faraday::Connection]
def connection
@connection ||= Faraday.new(ENDPOINT, connection_options)
@connection ||= Faraday.new(URL_PREFIX, connection_options)
end

def request(method, path, params = {}, headers = {})
Expand All @@ -111,25 +111,25 @@ def request(method, path, params = {}, headers = {})
raise(Twitter::Error.new(error))
end

def request_headers(method, path, params = {}, signature_params = params)
def request_headers(method, url, params = {}, signature_params = params)
bearer_token_request = params.delete(:bearer_token_request)
headers = {}
if bearer_token_request
headers[:accept] = '*/*'
headers[:authorization] = bearer_token_credentials_auth_header
headers[:content_type] = 'application/x-www-form-urlencoded; charset=UTF-8'
else
headers[:authorization] = auth_header(method, path, params, signature_params)
headers[:authorization] = auth_header(method, url, params, signature_params)
end
headers
end

def auth_header(method, path, params = {}, signature_params = params)
def auth_header(method, url, params = {}, signature_params = params)
if !user_token?
@bearer_token = token unless bearer_token?
bearer_auth_header
else
oauth_auth_header(method, ENDPOINT + path, signature_params).to_s
oauth_auth_header(method, url, signature_params).to_s
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@
end

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

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

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

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

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

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

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

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

def fixture_path
Expand Down
2 changes: 1 addition & 1 deletion spec/twitter/rest/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@

describe '#oauth_auth_header' do
it 'creates the correct auth headers' do
uri = Twitter::REST::Client::ENDPOINT + '/1.1/direct_messages.json'
uri = Twitter::REST::Client::URL_PREFIX + '/1.1/direct_messages.json'
authorization = @client.send(:oauth_auth_header, :get, uri)
expect(authorization.options[:signature_method]).to eq('HMAC-SHA1')
expect(authorization.options[:version]).to eq('1.0')
Expand Down

0 comments on commit ecea9c5

Please sign in to comment.