@testmonitor/ts-reporter-client
Version:
A convenient TypeScript wrapper for the TestMonitor reporter API endpoints. It can be used in both TypeScript and JavaScript.
44 lines (43 loc) • 1.07 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiRequest = void 0;
class ApiRequest {
constructor(request) {
this.headers = {};
this.method = request.method;
this.url = request.url;
this.accessToken = request.accessToken;
this.headers = request.headers;
this.body = request.body;
}
/**
*
* @returns {}
*/
getData() {
return {
method: this.method,
url: this.url,
headers: this.getHeaders(this.headers),
data: this.body || {},
};
}
/**
*
* @param headers
* @returns {}
*/
getHeaders(headers) {
return Object.assign({ 'Content-Type': this.hasFormData()
? 'multipart/form-data'
: 'application/json', Authorization: 'Bearer ' + this.accessToken }, headers);
}
/**
*
* @returns boolean
*/
hasFormData() {
return this.body instanceof FormData;
}
}
exports.ApiRequest = ApiRequest;