Skip to content

Commit

Permalink
comply to the latest rate limit stuff (discord/discord-api-docs#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
amishshah committed Sep 24, 2016
1 parent bd1449b commit aef0b83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/docs.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions src/client/rest/APIRequest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const request = require('superagent');
const Constants = require('../../util/Constants');

function getRoute(url) {
let route = url.split('?')[0];
if (route.includes('/channels/') || route.includes('/guilds/')) {
const startInd = ~route.indexOf('/channels/') ? route.indexOf('/channels/') : route.indexOf('/guilds/');
const majorID = route.substring(startInd).split('/')[2];
route = route.replace(/(\d{8,})/g, ':id').replace(':id', majorID);
}
return route;
}

class APIRequest {
constructor(rest, method, url, auth, data, file) {
this.rest = rest;
Expand All @@ -9,10 +19,7 @@ class APIRequest {
this.auth = auth;
this.data = data;
this.file = file;
}

getEndpoint() {
return this.url;
this.route = getRoute(this.url);
}

getAuth() {
Expand Down
6 changes: 3 additions & 3 deletions src/client/rest/RESTManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class RESTManager {
makeRequest(method, url, auth, data, file) {
const apiRequest = new APIRequest(this, method, url, auth, data, file);

if (!this.handlers[apiRequest.getEndpoint()]) {
if (!this.handlers[apiRequest.route]) {
const RequestHandlerType = this.getRequestHandler();
this.handlers[apiRequest.getEndpoint()] = new RequestHandlerType(this, apiRequest.getEndpoint());
this.handlers[apiRequest.route] = new RequestHandlerType(this, apiRequest.route);
}

return this.push(this.handlers[apiRequest.getEndpoint()], apiRequest);
return this.push(this.handlers[apiRequest.route], apiRequest);
}
}

Expand Down

0 comments on commit aef0b83

Please sign in to comment.