Skip to content

Commit

Permalink
Merge pull request #232 from gvnn/master
Browse files Browse the repository at this point in the history
Allow users to specify a full path
  • Loading branch information
desmondmorris committed Jun 13, 2017
2 parents 3be527f + 87cc24c commit 458dde9
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
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
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 458dde9

Please sign in to comment.