UNPKG

dfp-lib

Version:

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

41 lines (40 loc) 2.27 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 sprintf_js_1 = require("sprintf-js"); const src_1 = require("../../../src"); const config_1 = require("../auth/config"); (function () { return __awaiter(this, void 0, void 0, function* () { const user = new src_1.dfp.DfpUser(config_1.default); user.logAll(); const lineItemService = new src_1.dfp.LineItemService(user); const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); const statementBuilder = new src_1.dfp.StatementBuilder() .where('lastModifiedDateTime >= :lastModifiedDateTime') .orderBy('id ASC') .limit(src_1.dfp.StatementBuilder.SUGGESTED_PAGE_LIMIT) .withBindVariableValue('lastModifiedDateTime', src_1.dfp.DateTimeUtils.toDfpDateTime(yesterday)); let totalResultSetSize = 0; do { const page = yield lineItemService.getLineItemsByStatement(statementBuilder.toStatement()); if (page.results) { totalResultSetSize = page.totalResultSetSize; let i = page.startIndex; for (const lineItem of page.results) { console.log(sprintf_js_1.sprintf("%d) Line item with ID %d, belonging to order %d, and name '%s' was found.", ++i, lineItem.id, lineItem.orderId, lineItem.name)); } } statementBuilder.increaseOffsetBy(src_1.dfp.StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.getOffset() < totalResultSetSize); console.log("Number of results found:", totalResultSetSize); console.log("DONE"); }); })().catch((err) => console.error(err));