Duffer Derek

Current Path : /var/www/podio-api-client/src/modules/api/
Upload File :
Current File : /var/www/podio-api-client/src/modules/api/Api.ts

import { HttpResponse } from '../../types/http.type';
import { AuthToken } from '../../types/podio.type';
import HttpClient from '../../http/HttpClient';

class Api {
  /**
   *
   * @type {AuthToken} auth
   */
  auth: AuthToken;

  /**
   * Authorization header
   * This will be same for all requests
   * @type {object}
   */
  headers: object;

  /**
   *
   * @param {} auth
   */
  constructor(auth: AuthToken) {
    this.auth = auth;

    /**
     * Set the header
     */
    this.headers = { Authorization: `OAuth2 ${auth.access_token}` };
  }

  /**
   * Handling the request object and authorization header to be send with the API
   * @param requestParam
   * @param requestObj
   * @returns
   */
  protected async _httpRequest<ResponseType = any>(requestObj: any): Promise<HttpResponse<ResponseType>> {
    return await new HttpClient({ ...requestObj, headers: this.headers }).call();
  }
}

export default Api;

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists