UNPKG

dfp-lib

Version:

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

69 lines (68 loc) 2.71 kB
"use strict"; const settings_1 = require("../../settings"); const settings_2 = require("../settings"); const adsUser_1 = require("../../common/lib/adsUser"); const validationException_1 = require("../../common/lib/validationException"); class DfpUser extends adsUser_1.AdsUser { constructor(authenticationObject, settingsObject = null) { super(); this.libName = settings_1.Settings.LIB_NAME; this.libVersion = settings_1.Settings.LIB_VERSION; const defaultVersion = settings_2.DfpSettings.SERVER.VERSION; const defaultServer = settings_2.DfpSettings.SERVER.HOST; const applicationName = authenticationObject.applicationName; const networkCode = authenticationObject.networkCode; const oauth2 = authenticationObject.oauth2; let scopes = oauth2['scopes'] || []; scopes.push(DfpUser.OAUTH2_SCOPE); this.setOAuth2Info(oauth2); this.setApplicationName(applicationName); this.setClientLibraryUserAgent(applicationName); this.setNetworkCode(networkCode); this.setScopes(scopes); settingsObject = Object.assign({}, settingsObject, settings_2.DfpSettings); this.loadSettings(settingsObject, defaultVersion, defaultServer, process.cwd()); } getNetworkCode() { return this.getHeaderValue('networkCode'); } setNetworkCode(networkCode) { this.setHeaderValue('networkCode', networkCode); } getApplicationName() { return this.applicationName; } setApplicationName(applicationName) { this.applicationName = applicationName; } getUserAgentHeaderName() { return DfpUser.USER_AGENT_HEADER_NAME; } getClientLibraryNameAndVersion() { return [this.libName, this.libVersion]; } getScopes() { return this.scopes; } setScopes(scopes) { this.scopes = scopes; } getDefaultOAuth2Handler(cls) { cls = (cls) ? cls : settings_2.DfpSettings.AUTH.OAUTH2_HANDLER_CLASS; return new cls(this.getAuthServer(), this.getScopes()); } getDefaultRequestHandler(cls) { cls = (cls) ? cls : settings_2.DfpSettings.SOAP.REQUEST_HANDLER_CLASS; return new cls(); } validateUser() { super.validateOAuth2Info(); let applicationName = this.getApplicationName(); if (!applicationName) { throw new validationException_1.ValidationException('applicationName', null, "The property applicationName is required and cannot be null or an empty string"); } } } DfpUser.OAUTH2_SCOPE = 'https://www.googleapis.com/auth/dfp'; DfpUser.USER_AGENT_HEADER_NAME = 'applicationName'; exports.DfpUser = DfpUser;