@niur/google-admanager-api
Version:
Google Ad Manager API Client Library for NodeJs
52 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportUtilities = void 0;
const report_enum_1 = require("../../client/services/report/report.enum");
const httpUtilities_util_1 = require("./httpUtilities.util");
const reports_1 = require("./reports");
const handlers_1 = require("../handlers");
/**
* Utility class for DFP API report downloads.
*/
class ReportUtilities extends reports_1.AdsReportUtilities {
/**
* @param reportService ReportService to be used
* @param reportJobId The ID of the report job
*/
constructor(reportService, reportJobId) {
super();
this.reportService = reportService;
this.reportJobId = reportJobId;
}
/**
* Returns a flag indicating whether the caller should wait more time for
* the report download to complete.
* @returns True, if the caller should wait more, false otherwise.
*/
async shouldWaitMore() {
const status = await this.reportService.getReportJobStatus(this.reportJobId);
if (status === report_enum_1.ReportJobStatus.FAILED) {
throw new handlers_1.AdsReportsException(`Report job ${this.reportJobId} failed.`);
}
return status != report_enum_1.ReportJobStatus.COMPLETED;
}
/**
* Gets the report response.
* @returns The report response.
*/
async getReport() {
const response = await this.buildRequest(await this.reportService.getReportDownloadUrlWithOptions(this.reportJobId, this.reportDownloadOptions));
return new reports_1.ReportResponse(response);
}
/**
* Builds an HTTP request for downloading reports.
* @param downloadUrl The download url.
*/
buildRequest(downloadUrl) {
return httpUtilities_util_1.HttpUtilities.buildRequest(downloadUrl, 'GET', {
timeout: 0,
});
}
}
exports.ReportUtilities = ReportUtilities;
//# sourceMappingURL=reportUtilities.util.js.map