@google-cloud/nodejs-common 2.0.16-beta → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/bin/google_ads.sh +1 -1
- package/bin/install_functions.sh +1 -0
- package/package.json +1 -1
- package/src/apis/analytics.js +17 -21
- package/src/apis/base/ads_api_common.js +99 -0
- package/src/apis/base/google_api_client.js +55 -0
- package/src/apis/dfa_reporting.js +17 -33
- package/src/apis/display_video.js +13 -44
- package/src/apis/doubleclick_bidmanager.js +34 -42
- package/src/apis/doubleclick_search.js +17 -33
- package/src/apis/google_ads_api.js +94 -45
- package/src/apis/index.js +0 -1
- package/src/apis/search_ads.js +114 -52
- package/src/apis/spreadsheets.js +16 -23
- package/src/apis/youtube.js +18 -26
- package/src/components/firestore/datastore_mode_access.js +4 -3
- package/src/components/utils.js +23 -5
package/README.md
CHANGED
|
@@ -18,10 +18,11 @@ and [Data Tasks Coordinator]. This library includes:
|
|
|
18
18
|
- Google Ads click conversions upload
|
|
19
19
|
- Google Ads customer match upload
|
|
20
20
|
- Google Ads enhanced conversions upload
|
|
21
|
+
- Google Ads offline userdata job data upload
|
|
21
22
|
- Google Ads conversions scheduled uploads based on Google Sheets
|
|
22
23
|
- Measurement Protocol Google Analytics 4
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
2. Wrapper for some Google APIs for reporting, mainly
|
|
25
26
|
for [Data Tasks Coordinator]:
|
|
26
27
|
|
|
27
28
|
- Google Ads reporting
|
|
@@ -31,7 +32,7 @@ and [Data Tasks Coordinator]. This library includes:
|
|
|
31
32
|
- YouTube Data API
|
|
32
33
|
- Ads Data Hub querying
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
3. Utilities wrapper class for Google Cloud Products:
|
|
35
36
|
|
|
36
37
|
- **Firestore Access Object**: Firestore has two modes[[comparison]] which
|
|
37
38
|
have different API. This class, with its two successors, offer a unified
|
|
@@ -66,7 +67,7 @@ and [Data Tasks Coordinator]. This library includes:
|
|
|
66
67
|
an adapter to wrap a Node8 Cloud Functions into Node6 and Node8 compatible
|
|
67
68
|
functions.~~ (This has been removed since v1.9.0)
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
4. A share library for [Bash] to facilitate installation tasks.
|
|
70
71
|
|
|
71
72
|
[gmp and google ads connector]: https://github.com/GoogleCloudPlatform/cloud-for-marketing/tree/master/marketing-analytics/activation/gmp-googleads-connector
|
|
72
73
|
[data tasks coordinator]: https://github.com/GoogleCloudPlatform/cloud-for-marketing/tree/master/marketing-analytics/activation/data-tasks-coordinator
|
package/bin/google_ads.sh
CHANGED
package/bin/install_functions.sh
CHANGED
|
@@ -1560,6 +1560,7 @@ set_cloud_functions_default_settings() {
|
|
|
1560
1560
|
default_cf_flag+=(--set-env-vars=DEBUG="${DEBUG}")
|
|
1561
1561
|
default_cf_flag+=(--set-env-vars=IN_GCP="${IN_GCP}")
|
|
1562
1562
|
default_cf_flag+=(--set-env-vars=DATABASE_ID="${DATABASE_ID}")
|
|
1563
|
+
default_cf_flag+=(--set-env-vars=DATABASE_MODE="${DATABASE_MODE}")
|
|
1563
1564
|
}
|
|
1564
1565
|
|
|
1565
1566
|
#######################################
|
package/package.json
CHANGED
package/src/apis/analytics.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
const stream = require('stream');
|
|
23
23
|
const {google} = require('googleapis');
|
|
24
|
+
const { GoogleApiClient } = require('./base/google_api_client.js');
|
|
24
25
|
const {Schema$Upload} = google.analytics;
|
|
25
26
|
const AuthClient = require('./auth_client.js');
|
|
26
27
|
const {wait, getLogger, BatchResult} = require('../components/utils.js');
|
|
@@ -55,31 +56,26 @@ let DataImportClearConfig;
|
|
|
55
56
|
/**
|
|
56
57
|
* Google Analytics API v3 stub.
|
|
57
58
|
*/
|
|
58
|
-
class Analytics {
|
|
59
|
+
class Analytics extends GoogleApiClient {
|
|
59
60
|
/**
|
|
60
61
|
* @constructor
|
|
61
62
|
* @param {!Object<string,string>=} env The environment object to hold env
|
|
62
63
|
* variables.
|
|
63
64
|
*/
|
|
64
65
|
constructor(env = process.env) {
|
|
65
|
-
|
|
66
|
+
super(env);
|
|
67
|
+
this.googleApi = 'analytics';
|
|
66
68
|
this.logger = getLogger('API.GA');
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.logger.debug(`Initialized ${this.constructor.name} instance.`);
|
|
78
|
-
this.analytics = google.analytics({
|
|
79
|
-
version: API_VERSION,
|
|
80
|
-
auth: this.authClient.getDefaultAuth(),
|
|
81
|
-
});
|
|
82
|
-
return this.analytics;
|
|
71
|
+
/** @override */
|
|
72
|
+
getScope() {
|
|
73
|
+
return API_SCOPES;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @override */
|
|
77
|
+
getVersion() {
|
|
78
|
+
return API_VERSION;
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
/**
|
|
@@ -102,7 +98,7 @@ class Analytics {
|
|
|
102
98
|
},
|
|
103
99
|
config);
|
|
104
100
|
|
|
105
|
-
const analytics = await this.
|
|
101
|
+
const analytics = await this.getApiClient();
|
|
106
102
|
const response = await analytics.management.uploads.uploadData(
|
|
107
103
|
uploadConfig);
|
|
108
104
|
this.logger.debug('Configuration: ', config);
|
|
@@ -151,7 +147,7 @@ class Analytics {
|
|
|
151
147
|
* @return {!Promise<!Schema$Upload>} Updated data import Job status.
|
|
152
148
|
*/
|
|
153
149
|
async checkJobStatus(jobConfig) {
|
|
154
|
-
const analytics = await this.
|
|
150
|
+
const analytics = await this.getApiClient();
|
|
155
151
|
const { data: job } = await analytics.management.uploads.get(jobConfig);
|
|
156
152
|
if (job.status !== 'PENDING') return job;
|
|
157
153
|
this.logger.debug(
|
|
@@ -169,7 +165,7 @@ class Analytics {
|
|
|
169
165
|
* @return {!Promise<!Array<string>>}
|
|
170
166
|
*/
|
|
171
167
|
async listAccounts() {
|
|
172
|
-
const analytics = await this.
|
|
168
|
+
const analytics = await this.getApiClient();
|
|
173
169
|
const response = await analytics.management.accounts.list();
|
|
174
170
|
return response.data.items.map(
|
|
175
171
|
(account) => `Account id: ${account.name}[${account.id}]`
|
|
@@ -182,7 +178,7 @@ class Analytics {
|
|
|
182
178
|
* @return {!Promise<!Array<Object>>}
|
|
183
179
|
*/
|
|
184
180
|
async listUploads(config) {
|
|
185
|
-
const analytics = await this.
|
|
181
|
+
const analytics = await this.getApiClient();
|
|
186
182
|
const response = await analytics.management.uploads.list(config);
|
|
187
183
|
return response.data.items;
|
|
188
184
|
}
|
|
@@ -203,7 +199,7 @@ class Analytics {
|
|
|
203
199
|
const request = Object.assign({}, config, {
|
|
204
200
|
resource: {customDataImportUids},
|
|
205
201
|
});
|
|
206
|
-
const analytics = await this.
|
|
202
|
+
const analytics = await this.getApiClient();
|
|
207
203
|
await analytics.management.uploads.deleteUploadData(request);
|
|
208
204
|
this.logger.debug('Delete uploads: ', customDataImportUids);
|
|
209
205
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright 2024 Google Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this fileAccessObject except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
/**
|
|
15
|
+
* @fileoverview Common functions for Google Ads and Search Ads API classes.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const { Transform } = require('stream');
|
|
21
|
+
const {
|
|
22
|
+
getFilterAndStringifyFn,
|
|
23
|
+
getLogger,
|
|
24
|
+
} = require('../../components/utils.js');
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns a integer format CID by removing dashes and spaces.
|
|
28
|
+
* @param {string} cid
|
|
29
|
+
* @return {string}
|
|
30
|
+
*/
|
|
31
|
+
function getCleanCid(cid) {
|
|
32
|
+
return cid.toString().trim().replace(/-/g, '');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const START_TAG = '"results":';
|
|
36
|
+
const FIELD_MASK_TAG = '"fieldMask"';
|
|
37
|
+
const END_TAG = '"requestId"';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A stream.Transform that can extract properties and convert naming of the
|
|
41
|
+
* reponse of Google/Search Ads report from REST interface.
|
|
42
|
+
*/
|
|
43
|
+
class RestSearchStreamTransform extends Transform {
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @constructor
|
|
47
|
+
* @param {boolean=} snakeCase Whether or not output JSON in snake naming.
|
|
48
|
+
*/
|
|
49
|
+
constructor(snakeCase = false) {
|
|
50
|
+
super({ objectMode: true });
|
|
51
|
+
this.snakeCase = snakeCase;
|
|
52
|
+
this.chunks = [Buffer.from('')];
|
|
53
|
+
this.processFn; // The function to process a row of the report.
|
|
54
|
+
this.logger = getLogger('ADS.STREAM.T');
|
|
55
|
+
this.stopwatch = Date.now();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_transform(chunk, encoding, callback) {
|
|
59
|
+
const latest = Buffer.concat([this.chunks[this.chunks.length - 1], chunk]);
|
|
60
|
+
const endIndex = latest.indexOf(END_TAG);
|
|
61
|
+
if (endIndex > -1) {
|
|
62
|
+
this.chunks.push(chunk);
|
|
63
|
+
const rawString = Buffer.concat(this.chunks).toString();
|
|
64
|
+
const startIndex = rawString.indexOf(START_TAG) + START_TAG.length;
|
|
65
|
+
const maskIndex = rawString.lastIndexOf(FIELD_MASK_TAG);
|
|
66
|
+
if (!this.processFn) {
|
|
67
|
+
const fieldMask = rawString
|
|
68
|
+
.substring(maskIndex + FIELD_MASK_TAG.length, rawString.indexOf(END_TAG))
|
|
69
|
+
.split('"')[1];
|
|
70
|
+
this.logger.debug(`Got fieldMask: ${fieldMask}`);
|
|
71
|
+
this.processFn = getFilterAndStringifyFn(fieldMask, this.snakeCase);
|
|
72
|
+
}
|
|
73
|
+
const resultsWithTailing = rawString.substring(startIndex, maskIndex);
|
|
74
|
+
const results = resultsWithTailing.substring(
|
|
75
|
+
0, resultsWithTailing.lastIndexOf(','));
|
|
76
|
+
const rows = JSON.parse(results);
|
|
77
|
+
const data = rows.map(this.processFn).join('\n') + '\n';
|
|
78
|
+
// Clear cached chunks.
|
|
79
|
+
this.chunks = [latest.subarray(latest.indexOf(END_TAG) + END_TAG.length)];
|
|
80
|
+
|
|
81
|
+
this.logger.debug(`Got ${rows.length} rows. Process time:`,
|
|
82
|
+
Date.now() - this.stopwatch);
|
|
83
|
+
this.stopwatch = Date.now();
|
|
84
|
+
callback(null, data);
|
|
85
|
+
} else {
|
|
86
|
+
if (chunk.length < END_TAG.length) {// Update latest chunk for short chunk
|
|
87
|
+
this.chunks[this.chunks.length - 1] = latest;
|
|
88
|
+
} else {
|
|
89
|
+
this.chunks.push(chunk);
|
|
90
|
+
}
|
|
91
|
+
callback();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = {
|
|
97
|
+
getCleanCid,
|
|
98
|
+
RestSearchStreamTransform,
|
|
99
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright 2023 Google Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview A base class for Google Api client library class.
|
|
17
|
+
*/
|
|
18
|
+
const { google } = require('googleapis');
|
|
19
|
+
const { getLogger, getObjectByPath } = require('../../components/utils.js');
|
|
20
|
+
const { AuthRestfulApi } = require('./auth_restful_api.js');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A Google Api client library class.
|
|
24
|
+
*/
|
|
25
|
+
class GoogleApiClient extends AuthRestfulApi {
|
|
26
|
+
|
|
27
|
+
/** @constructor */
|
|
28
|
+
constructor(env = process.env, options = {}) {
|
|
29
|
+
super(env, options);
|
|
30
|
+
this.logger = getLogger('API.default');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns the Api version of the Api in the current library.
|
|
35
|
+
* @return {string}
|
|
36
|
+
* @abstract
|
|
37
|
+
*/
|
|
38
|
+
getVersion() { }
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the Api instance.
|
|
42
|
+
* @return {!Promise<object>} The Api instance.
|
|
43
|
+
*/
|
|
44
|
+
async getApiClient() {
|
|
45
|
+
if (this.apiClient) return this.apiClient;
|
|
46
|
+
this.logger.info(`Initialized ${this.constructor.name} instance.`);
|
|
47
|
+
this.apiClient = google[this.googleApi]({
|
|
48
|
+
version: this.getVersion(),
|
|
49
|
+
auth: await this.getAuth(),
|
|
50
|
+
});
|
|
51
|
+
return this.apiClient;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = { GoogleApiClient };
|
|
@@ -19,9 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
'use strict';
|
|
21
21
|
|
|
22
|
-
const {
|
|
23
|
-
const {
|
|
24
|
-
const AuthClient = require('./auth_client.js');
|
|
22
|
+
const { request } = require('gaxios');
|
|
23
|
+
const { GoogleApiClient } = require('./base/google_api_client.js');
|
|
25
24
|
const {
|
|
26
25
|
getLogger,
|
|
27
26
|
getFilterFunction,
|
|
@@ -94,7 +93,7 @@ const MAX_IDENTIFIERS_PER_USER = 5;
|
|
|
94
93
|
* Google DfaReport API v3.0 stub.
|
|
95
94
|
* see https://developers.google.com/doubleclick-advertisers/service_accounts
|
|
96
95
|
*/
|
|
97
|
-
class DfaReporting {
|
|
96
|
+
class DfaReporting extends GoogleApiClient {
|
|
98
97
|
|
|
99
98
|
/**
|
|
100
99
|
* @constructor
|
|
@@ -102,34 +101,19 @@ class DfaReporting {
|
|
|
102
101
|
* variables.
|
|
103
102
|
*/
|
|
104
103
|
constructor(env = process.env) {
|
|
105
|
-
|
|
104
|
+
super(env);
|
|
105
|
+
this.googleApi = 'dfareporting';
|
|
106
106
|
this.logger = getLogger('API.CM');
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* @private
|
|
113
|
-
*/
|
|
114
|
-
async getApiClient_() {
|
|
115
|
-
if (this.dfareporting) return this.dfareporting;
|
|
116
|
-
this.logger.debug(`Initialized ${this.constructor.name} instance.`);
|
|
117
|
-
this.dfareporting = google.dfareporting({
|
|
118
|
-
version: API_VERSION,
|
|
119
|
-
auth: await this.getAuth_(),
|
|
120
|
-
});
|
|
121
|
-
return this.dfareporting;
|
|
109
|
+
/** @override */
|
|
110
|
+
getScope() {
|
|
111
|
+
return API_SCOPES;
|
|
122
112
|
}
|
|
123
113
|
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*/
|
|
128
|
-
async getAuth_() {
|
|
129
|
-
if (this.auth) return this.auth;
|
|
130
|
-
await this.authClient.prepareCredentials();
|
|
131
|
-
this.auth = this.authClient.getDefaultAuth();
|
|
132
|
-
return this.auth;
|
|
114
|
+
/** @override */
|
|
115
|
+
getVersion() {
|
|
116
|
+
return API_VERSION;
|
|
133
117
|
}
|
|
134
118
|
|
|
135
119
|
/**
|
|
@@ -140,7 +124,7 @@ class DfaReporting {
|
|
|
140
124
|
* @return {!Promise<string>}
|
|
141
125
|
*/
|
|
142
126
|
async getProfileId(accountId) {
|
|
143
|
-
const dfareporting = await this.
|
|
127
|
+
const dfareporting = await this.getApiClient();
|
|
144
128
|
const { data: { items } } = await dfareporting.userProfiles.list();
|
|
145
129
|
const profiles = items.filter(
|
|
146
130
|
(profile) => profile.accountId === accountId
|
|
@@ -237,7 +221,7 @@ class DfaReporting {
|
|
|
237
221
|
numberOfLines: lines.length,
|
|
238
222
|
};
|
|
239
223
|
try {
|
|
240
|
-
const dfareporting = await this.
|
|
224
|
+
const dfareporting = await this.getApiClient();
|
|
241
225
|
const response = await dfareporting.conversions[operation]({
|
|
242
226
|
profileId: config.profileId,
|
|
243
227
|
requestBody: requestBody,
|
|
@@ -304,7 +288,7 @@ class DfaReporting {
|
|
|
304
288
|
* @return {!Promise<!Array<string>>}
|
|
305
289
|
*/
|
|
306
290
|
async listUserProfiles() {
|
|
307
|
-
const dfareporting = await this.
|
|
291
|
+
const dfareporting = await this.getApiClient();
|
|
308
292
|
const { data: { items } } = await dfareporting.userProfiles.list();
|
|
309
293
|
return items.map(({profileId, userName, accountId, accountName}) => {
|
|
310
294
|
return `Profile: ${profileId}[${userName}] `
|
|
@@ -349,7 +333,7 @@ class DfaReporting {
|
|
|
349
333
|
*/
|
|
350
334
|
async runReport(config) {
|
|
351
335
|
const profileId = await this.getProfileForOperation_(config);
|
|
352
|
-
const dfareporting = await this.
|
|
336
|
+
const dfareporting = await this.getApiClient();
|
|
353
337
|
const { startDate, endDate } = config;
|
|
354
338
|
if (startDate && endDate) {
|
|
355
339
|
const { data: report } = await dfareporting.reports.get({
|
|
@@ -392,7 +376,7 @@ class DfaReporting {
|
|
|
392
376
|
*/
|
|
393
377
|
async getReportFileUrl(config) {
|
|
394
378
|
const profileId = await this.getProfileForOperation_(config);
|
|
395
|
-
const dfareporting = await this.
|
|
379
|
+
const dfareporting = await this.getApiClient();
|
|
396
380
|
const response = await dfareporting.reports.files.get({
|
|
397
381
|
profileId,
|
|
398
382
|
reportId: config.reportId,
|
|
@@ -410,7 +394,7 @@ class DfaReporting {
|
|
|
410
394
|
* @return {!Promise<stream>}
|
|
411
395
|
*/
|
|
412
396
|
async getReportFileStream(url) {
|
|
413
|
-
const auth = await this.
|
|
397
|
+
const auth = await this.getAuth();
|
|
414
398
|
const headers = await auth.getRequestHeaders();
|
|
415
399
|
const response = await request({
|
|
416
400
|
method: 'GET',
|
|
@@ -19,14 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
'use strict';
|
|
21
21
|
|
|
22
|
-
const {
|
|
23
|
-
const
|
|
24
|
-
const {
|
|
25
|
-
getLogger,
|
|
26
|
-
getObjectByPath,
|
|
27
|
-
SendSingleBatch,
|
|
28
|
-
BatchResult,
|
|
29
|
-
} = require('../components/utils.js');
|
|
22
|
+
const { GoogleApiClient } = require('./base/google_api_client.js');
|
|
23
|
+
const { getLogger } = require('../components/utils.js');
|
|
30
24
|
|
|
31
25
|
const API_SCOPES = Object.freeze([
|
|
32
26
|
'https://www.googleapis.com/auth/display-video',
|
|
@@ -34,13 +28,13 @@ const API_SCOPES = Object.freeze([
|
|
|
34
28
|
const API_VERSION = 'v3';
|
|
35
29
|
|
|
36
30
|
/**
|
|
37
|
-
* Display and Video 360 API
|
|
38
|
-
* @see https://developers.google.com/display-video/api/reference/rest/
|
|
31
|
+
* Display and Video 360 API v3 stub.
|
|
32
|
+
* @see https://developers.google.com/display-video/api/reference/rest/v3
|
|
39
33
|
* This is not the same to Reports Display & Video 360 API which is from Google
|
|
40
34
|
* Bid Manager API.
|
|
41
35
|
* @see https://developers.google.com/bid-manager/reference/rest
|
|
42
36
|
*/
|
|
43
|
-
class DisplayVideo {
|
|
37
|
+
class DisplayVideo extends GoogleApiClient {
|
|
44
38
|
|
|
45
39
|
/**
|
|
46
40
|
* @constructor
|
|
@@ -48,44 +42,19 @@ class DisplayVideo {
|
|
|
48
42
|
* variables.
|
|
49
43
|
*/
|
|
50
44
|
constructor(env = process.env) {
|
|
51
|
-
|
|
45
|
+
super(env);
|
|
46
|
+
this.googleApi = 'displayvideo';
|
|
52
47
|
this.logger = getLogger('API.DV3API');
|
|
53
48
|
}
|
|
54
49
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* @private
|
|
59
|
-
*/
|
|
60
|
-
async getApiClient_() {
|
|
61
|
-
if (this.displayvideo) return this.displayvideo;
|
|
62
|
-
this.logger.debug(`Initialized ${this.constructor.name} instance.`);
|
|
63
|
-
this.displayvideo = google.displayvideo({
|
|
64
|
-
version: API_VERSION,
|
|
65
|
-
auth: await this.getAuth_(),
|
|
66
|
-
});
|
|
67
|
-
return this.displayvideo;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Gets the auth object.
|
|
72
|
-
* @return {!Promise<{!OAuth2Client|!JWT|!Compute}>}
|
|
73
|
-
*/
|
|
74
|
-
async getAuth_() {
|
|
75
|
-
if (this.auth) return this.auth;
|
|
76
|
-
await this.authClient.prepareCredentials();
|
|
77
|
-
this.auth = this.authClient.getDefaultAuth();
|
|
78
|
-
return this.auth;
|
|
50
|
+
/** @override */
|
|
51
|
+
getScope() {
|
|
52
|
+
return API_SCOPES;
|
|
79
53
|
}
|
|
80
54
|
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* @return {Object}
|
|
85
|
-
*/
|
|
86
|
-
async getFunctionObject(path) {
|
|
87
|
-
const instance = await this.getApiClient_();
|
|
88
|
-
return getObjectByPath(instance, path);
|
|
55
|
+
/** @override */
|
|
56
|
+
getVersion() {
|
|
57
|
+
return API_VERSION;
|
|
89
58
|
}
|
|
90
59
|
|
|
91
60
|
}
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
'use strict';
|
|
21
21
|
|
|
22
|
-
const {
|
|
23
|
-
const AuthClient = require('./auth_client.js');
|
|
22
|
+
const { GoogleApiClient } = require('./base/google_api_client.js');
|
|
24
23
|
const { getLogger } = require('../components/utils.js');
|
|
25
24
|
|
|
26
25
|
const API_SCOPES = Object.freeze([
|
|
@@ -28,25 +27,24 @@ const API_SCOPES = Object.freeze([
|
|
|
28
27
|
]);
|
|
29
28
|
const API_VERSION = 'v2';
|
|
30
29
|
|
|
31
|
-
/**
|
|
32
|
-
* The returned information of get a query.
|
|
33
|
-
* @typedef {{
|
|
34
|
-
* running:boolean,
|
|
35
|
-
* latestReportRunTimeMs:string,
|
|
36
|
-
* googleCloudStoragePathForLatestReport:string,
|
|
37
|
-
* }}
|
|
38
|
-
*/
|
|
39
|
-
let QueryResource;
|
|
40
|
-
|
|
41
30
|
/**
|
|
42
31
|
* RequestBody controls the data range of reports.
|
|
43
32
|
* see:
|
|
44
|
-
* https://developers.google.com/bid-manager/
|
|
33
|
+
* https://developers.google.com/bid-manager/reference/rest/v2/queries/run#RunQueryRequest
|
|
45
34
|
* @typedef {{
|
|
46
|
-
* dataRange:
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
35
|
+
* dataRange: {
|
|
36
|
+
* range: Range,
|
|
37
|
+
* customStartDate: {
|
|
38
|
+
* year: integer,
|
|
39
|
+
* month: integer,
|
|
40
|
+
* day: integer,
|
|
41
|
+
* },
|
|
42
|
+
* customEndDate: {
|
|
43
|
+
* year: integer,
|
|
44
|
+
* month: integer,
|
|
45
|
+
* day: integer,
|
|
46
|
+
* },
|
|
47
|
+
* }
|
|
50
48
|
* }}
|
|
51
49
|
*/
|
|
52
50
|
let RequestBody;
|
|
@@ -56,31 +54,26 @@ let RequestBody;
|
|
|
56
54
|
* Note: DV360 report API only support OAuth 2.0, see:
|
|
57
55
|
* https://developers.google.com/bid-manager/how-tos/authorizing
|
|
58
56
|
*/
|
|
59
|
-
class DoubleClickBidManager {
|
|
57
|
+
class DoubleClickBidManager extends GoogleApiClient {
|
|
60
58
|
/**
|
|
61
59
|
* @constructor
|
|
62
60
|
* @param {!Object<string,string>=} env The environment object to hold env
|
|
63
61
|
* variables.
|
|
64
62
|
*/
|
|
65
63
|
constructor(env = process.env) {
|
|
66
|
-
|
|
64
|
+
super(env);
|
|
65
|
+
this.googleApi = 'doubleclickbidmanager';
|
|
67
66
|
this.logger = getLogger('API.DV3');
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.logger.debug(`Initialized ${this.constructor.name} instance.`);
|
|
79
|
-
this.doubleclickbidmanager = google.doubleclickbidmanager({
|
|
80
|
-
version: API_VERSION,
|
|
81
|
-
auth: this.authClient.getDefaultAuth(),
|
|
82
|
-
});
|
|
83
|
-
return this.doubleclickbidmanager;
|
|
69
|
+
/** @override */
|
|
70
|
+
getScope() {
|
|
71
|
+
return API_SCOPES;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @override */
|
|
75
|
+
getVersion() {
|
|
76
|
+
return API_VERSION;
|
|
84
77
|
}
|
|
85
78
|
|
|
86
79
|
/**
|
|
@@ -91,21 +84,21 @@ class DoubleClickBidManager {
|
|
|
91
84
|
* @return {!Promise<number>} Report Id.
|
|
92
85
|
*/
|
|
93
86
|
async runQuery(queryId, requestBody = undefined) {
|
|
94
|
-
const doubleclickbidmanager = await this.
|
|
87
|
+
const doubleclickbidmanager = await this.getApiClient();
|
|
95
88
|
const response = await doubleclickbidmanager.queries.run(
|
|
96
89
|
{queryId, requestBody});
|
|
97
90
|
return response.data.key.reportId;
|
|
98
91
|
}
|
|
99
92
|
|
|
100
93
|
/**
|
|
101
|
-
* Gets a query
|
|
94
|
+
* Gets a query metadata.
|
|
102
95
|
* See https://developers.google.com/bid-manager/reference/rest/v2/queries/get
|
|
103
96
|
* @param {number} queryId Id of the query.
|
|
104
|
-
* @return {!Promise<!
|
|
105
|
-
* https://developers.google.com/bid-manager/reference/rest/v2/queries#
|
|
97
|
+
* @return {!Promise<!QueryMetadata>} Query metadata, see
|
|
98
|
+
* https://developers.google.com/bid-manager/reference/rest/v2/queries#QueryMetadata
|
|
106
99
|
*/
|
|
107
100
|
async getQuery(queryId) {
|
|
108
|
-
const doubleclickbidmanager = await this.
|
|
101
|
+
const doubleclickbidmanager = await this.getApiClient();
|
|
109
102
|
const response = await doubleclickbidmanager.queries.get({ queryId });
|
|
110
103
|
return response.data.metadata;
|
|
111
104
|
}
|
|
@@ -117,14 +110,14 @@ class DoubleClickBidManager {
|
|
|
117
110
|
* @return {!Promise<number>} Id of created query.
|
|
118
111
|
*/
|
|
119
112
|
async createQuery(query) {
|
|
120
|
-
const doubleclickbidmanager = await this.
|
|
113
|
+
const doubleclickbidmanager = await this.getApiClient();
|
|
121
114
|
const response = await doubleclickbidmanager.queries.create(
|
|
122
115
|
{requestBody: query});
|
|
123
116
|
return response.data.queryId;
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
async getQueryReport(queryId, reportId) {
|
|
127
|
-
const doubleclickbidmanager = await this.
|
|
120
|
+
const doubleclickbidmanager = await this.getApiClient();
|
|
128
121
|
const response = await doubleclickbidmanager.queries.reports.get(
|
|
129
122
|
{ queryId, reportId });
|
|
130
123
|
return response.data.metadata;
|
|
@@ -136,7 +129,7 @@ class DoubleClickBidManager {
|
|
|
136
129
|
* @return {!Promise<boolean>} Whether the query was deleted.
|
|
137
130
|
*/
|
|
138
131
|
async deleteQuery(queryId) {
|
|
139
|
-
const doubleclickbidmanager = await this.
|
|
132
|
+
const doubleclickbidmanager = await this.getApiClient();
|
|
140
133
|
try {
|
|
141
134
|
const { status } = await doubleclickbidmanager.queries.delete({ queryId });
|
|
142
135
|
return status === 200;
|
|
@@ -148,7 +141,6 @@ class DoubleClickBidManager {
|
|
|
148
141
|
}
|
|
149
142
|
|
|
150
143
|
module.exports = {
|
|
151
|
-
QueryResource,
|
|
152
144
|
RequestBody,
|
|
153
145
|
DoubleClickBidManager,
|
|
154
146
|
};
|