From 87cc24c2eba6f3bfd0dda8ff8c55f31aa2d87ef2 Mon Sep 17 00:00:00 2001 From: Giovanni Ferron Date: Tue, 6 Jun 2017 10:49:24 +0100 Subject: [PATCH] Allow users to specify a full path (avoid default `.json`) --- lib/twitter.js | 11 +++++++---- test/twitter.js | 7 +------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/twitter.js b/lib/twitter.js index 0754de20..1dbf3e27 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -78,8 +78,9 @@ Twitter.prototype.__buildEndpoint = function(path, base) { 'media': this.options.media_base }; var endpoint = (bases.hasOwnProperty(base)) ? bases[base] : bases.rest; - - if (url.parse(path).protocol) { + // if full url is specified we use that + var isFullUrl = (url.parse(path).protocol !== null); + if (isFullUrl) { endpoint = path; } else { @@ -93,8 +94,10 @@ Twitter.prototype.__buildEndpoint = function(path, base) { // Remove trailing slash endpoint = endpoint.replace(/\/$/, ''); - // Add json extension if not provided in call - endpoint += (path.split('.').pop() !== 'json') ? '.json' : ''; + if(!isFullUrl) { + // Add json extension if not provided in call... only if a full url is not specified + endpoint += (path.split('.').pop() !== 'json') ? '.json' : ''; + } return endpoint; }; diff --git a/test/twitter.js b/test/twitter.js index 7dbe9a3d..28ff6beb 100644 --- a/test/twitter.js +++ b/test/twitter.js @@ -168,12 +168,7 @@ describe('Twitter', function() { assert.equal( client.__buildEndpoint(endpoint), - endpoint + '.json' - ); - - assert.equal( - client.__buildEndpoint(endpoint), - endpoint + '.json' + endpoint ); }); });