From 09e94c53e44094198159366bf646c29c69a78aed Mon Sep 17 00:00:00 2001 From: Malik Mahmud Date: Wed, 24 Jun 2020 20:50:21 +0100 Subject: [PATCH 1/2] Fix media upload resource url --- index.d.ts | 5 +++++ twitter.js | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index d3151f4..9b1d1e8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -54,6 +54,11 @@ export default class Twitter { getAccessToken(options: AccessTokenOptions): Promise; + /** Returns the appropriate url for the provided resource + * @param {string} resource - The API endpoint + */ + private _getResourceUrl(resource: string): string; + /** * Construct the data and headers for an authenticated HTTP request to the Twitter API * @param {'GET | 'POST' | 'PUT'} diff --git a/twitter.js b/twitter.js index 273a647..b20d46b 100644 --- a/twitter.js +++ b/twitter.js @@ -191,6 +191,19 @@ class Twitter { return results; } + /** Returns the appropriate url for the provided resource + * @param {string} resource - The API endpoint + * @private + */ + _getResourceUrl(resource) { + switch(resource) { + case 'media/upload': + return getUrl('upload'); + default: + return this.url; + } + } + /** * Construct the data and headers for an authenticated HTTP request to the Twitter API * @param {string} method - 'GET' or 'POST' @@ -201,7 +214,7 @@ class Twitter { */ _makeRequest(method, resource, parameters) { const requestData = { - url: `${this.url}/${resource}.json`, + url: `${this._getResourceUrl(resource)}/${resource}.json`, method, }; if (parameters) From a67b37969dbbbf1c0fdd117ab2f38efb7a5125ec Mon Sep 17 00:00:00 2001 From: Malik Mahmud Date: Sun, 15 Aug 2021 01:54:48 +0100 Subject: [PATCH 2/2] fix private getResourceUrl method - maintain client config verison when setting resource url --- twitter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitter.js b/twitter.js index 233036c..eef6ef8 100644 --- a/twitter.js +++ b/twitter.js @@ -200,7 +200,7 @@ class Twitter { switch(resource) { case 'media/upload': case 'media/metadata/create': - return getUrl('upload'); + return getUrl('upload', this.config.version); default: return this.url; }