Skip to content

Commit

Permalink
Allow users to specify a full path (avoid default .json)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnn committed Jun 6, 2017
1 parent 3be527f commit 87cc24c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 7 additions & 4 deletions lib/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
};
Expand Down
7 changes: 1 addition & 6 deletions test/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,7 @@ describe('Twitter', function() {

assert.equal(
client.__buildEndpoint(endpoint),
endpoint + '.json'
);

assert.equal(
client.__buildEndpoint(endpoint),
endpoint + '.json'
endpoint
);
});
});
Expand Down

0 comments on commit 87cc24c

Please sign in to comment.