UNPKG

dfp-lib

Version:

This project hosts the Node.JS client library for the SOAP-based DFP API at Google.

53 lines (52 loc) 2.7 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; const validationException_1 = require("../../common/lib/validationException"); class ReportDownloader { constructor(reportService, reportJobId) { this.reportService = reportService; this.reportJobId = reportJobId; } waitForReportReady() { return __awaiter(this, void 0, void 0, function* () { const self = this; return new Promise((resolve, reject) => { (function isReportReady() { return __awaiter(this, void 0, void 0, function* () { self.reportJobStatus = yield self.reportService.getReportJobStatus(self.reportJobId); if (self.reportJobStatus === 'IN_PROGRESS') { setTimeout(isReportReady, ReportDownloader.SLEEP_DURATION); } else { (self.reportJobStatus === 'COMPLETED') ? resolve(true) : reject(false); } }); })(); }); }); } getDownloadUrl(exportFormat) { return __awaiter(this, void 0, void 0, function* () { if (this.reportJobStatus !== 'COMPLETED') { throw new validationException_1.ValidationException('ReportJobStatus', this.reportJobStatus, `Report ${this.reportJobId} must be completed before downloading.`); } return yield this.reportService.getReportDownloadURL(this.reportJobId, exportFormat); }); } getDownloadUrlWithOptions(options) { return __awaiter(this, void 0, void 0, function* () { if (this.reportJobStatus !== 'COMPLETED') { throw new validationException_1.ValidationException('ReportJobStatus', this.reportJobStatus, `Report ${this.reportJobId} must be completed before downloading.`); } return yield this.reportService.getReportDownloadUrlWithOptions(this.reportJobId, options); }); } } ReportDownloader.SLEEP_DURATION = 30000; exports.ReportDownloader = ReportDownloader;