const request = require('superagent');
const Constants = require('../../util/Constants');

class APIRequest {
  constructor(rest, method, url, auth, data, file) {
    this.rest = rest;
    this.method = method;
    this.url = url;
    this.auth = auth;
    this.data = data;
    this.file = file;
  }

  getEndpoint() {
    return `${this.url}`;
  }

  getAuth() {
    if (this.rest.client.token && this.rest.client.user && this.rest.client.user.bot) {
      return `Bot ${this.rest.client.token}`;
    } else if (this.rest.client.token) {
      return this.rest.client.token;
    }
    throw new Error(Constants.Errors.NO_TOKEN);
  }

  gen() {
    const apiRequest = request[this.method](this.url);
    if (this.auth) apiRequest.set('authorization', this.getAuth());
    if (this.file && this.file.file) {
      apiRequest.attach('file', this.file.file, this.file.name);
      this.data = this.data || {};
      for (const key in this.data) {
        if (this.data[key]) {
          apiRequest.field(key, this.data[key]);
        }
      }
    } else if (this.data) {
      apiRequest.send(this.data);
    }
    apiRequest.set('User-Agent', this.rest.userAgentManager.userAgent);
    return apiRequest;
  }
}

module.exports = APIRequest;

@@ -328,19 +328,16 @@
 urn 
-%60$%7B
 this.url
 %7D%60;%0A
@@ -332,18 +332,16 @@
 this.url
-%7D%60
 ;%0A  %7D%0A%0A 

Simplify APIRequest endpoint