@google-cloud/nodejs-common 2.0.4-alpha → 2.0.6-alpha
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/package.json +15 -14
- package/src/apis/analytics.js +1 -1
- package/src/apis/auth_client.js +33 -23
- package/src/apis/display_video.js +1 -1
- package/src/apis/doubleclick_search.js +3 -1
- package/src/apis/google_ads.js +1 -0
- package/src/apis/google_ads_api.js +1550 -0
- package/src/apis/index.js +20 -0
- package/src/apis/search_ads.js +171 -0
- package/src/components/storage.js +1 -1
- package/src/components/utils.js +23 -0
package/src/apis/index.js
CHANGED
|
@@ -77,6 +77,14 @@ exports.spreadsheets = require('./spreadsheets.js');
|
|
|
77
77
|
*/
|
|
78
78
|
exports.doubleclicksearch = require('./doubleclick_search.js');
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* APIs integration class for Search Ads 360 Reporting.
|
|
82
|
+
* @const {{
|
|
83
|
+
* SearchAds:!SearchAds,
|
|
84
|
+
* }}
|
|
85
|
+
*/
|
|
86
|
+
exports.searchads = require('./search_ads.js');
|
|
87
|
+
|
|
80
88
|
/**
|
|
81
89
|
* APIs integration class for DoubleClick BidManager (DV360).
|
|
82
90
|
* @const {{
|
|
@@ -104,6 +112,18 @@ exports.bigquery = require('./bigquery.js');
|
|
|
104
112
|
*/
|
|
105
113
|
exports.googleads = require('./google_ads.js');
|
|
106
114
|
|
|
115
|
+
/**
|
|
116
|
+
* APIs integration class for Google Ads with Google API library.
|
|
117
|
+
* @const {{
|
|
118
|
+
* GoogleAdsApi:!GoogleAdsApi,
|
|
119
|
+
* ConversionConfig:!ConversionConfig,
|
|
120
|
+
* CustomerMatchConfig: !CustomerMatchConfig,
|
|
121
|
+
* OfflineUserDataJobConfig: !OfflineUserDataJobConfig,
|
|
122
|
+
* CustomerMatchRecord: !CustomerMatchRecord,
|
|
123
|
+
* }}
|
|
124
|
+
*/
|
|
125
|
+
exports.googleadsapi = require('./google_ads_api.js');
|
|
126
|
+
|
|
107
127
|
/**
|
|
108
128
|
* APIs integration class for Ads Data Hub.
|
|
109
129
|
* @const {{
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Copyright 2019 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 Google Search Ads 360 Reporting on GoogleAPI Client Library.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
const { google } = require('googleapis');
|
|
22
|
+
const AuthClient = require('./auth_client.js');
|
|
23
|
+
const { getLogger } = require('../components/utils.js');
|
|
24
|
+
|
|
25
|
+
const API_SCOPES = Object.freeze([
|
|
26
|
+
'https://www.googleapis.com/auth/doubleclicksearch',
|
|
27
|
+
]);
|
|
28
|
+
const API_VERSION = 'v0';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Search Ads 360 Reporting API stub.
|
|
32
|
+
* See: https://developers.google.com/search-ads/reporting/api/reference/release-notes
|
|
33
|
+
*/
|
|
34
|
+
class SearchAds {
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @constructor
|
|
38
|
+
* @param {!Object<string,string>=} env The environment object to hold env
|
|
39
|
+
* variables.
|
|
40
|
+
*/
|
|
41
|
+
constructor(env = process.env) {
|
|
42
|
+
this.authClient = new AuthClient(API_SCOPES, env);
|
|
43
|
+
this.logger = getLogger('API.SA');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Prepares the Search Ads 360 Reporting API instance.
|
|
48
|
+
* OAuth 2.0 application credentials is required for calling this API.
|
|
49
|
+
* For Search Ads Reporting API calls made by a manager to a client account,
|
|
50
|
+
* a HTTP header named `login-customer-id` is required in the request. This
|
|
51
|
+
* value represents the Search Ads 360 customer ID of the manager making the
|
|
52
|
+
* API call. Be sure to remove any hyphens (—), for example: 1234567890, not
|
|
53
|
+
* 123-456-7890.
|
|
54
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/auth
|
|
55
|
+
* @return {!google.searchads360}
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
async getApiClient_(loginCustomerId) {
|
|
59
|
+
this.logger.debug(`Initialized Search Ads reporting instance for ${loginCustomerId}`);
|
|
60
|
+
this.searchads360 = google.searchads360({
|
|
61
|
+
version: API_VERSION,
|
|
62
|
+
auth: await this.getAuth_(),
|
|
63
|
+
headers: { 'login-customer-id': loginCustomerId },
|
|
64
|
+
});
|
|
65
|
+
return this.searchads360;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gets the auth object.
|
|
70
|
+
* @return {!Promise<{!OAuth2Client|!JWT|!Compute}>}
|
|
71
|
+
*/
|
|
72
|
+
async getAuth_() {
|
|
73
|
+
if (this.auth) return this.auth;
|
|
74
|
+
await this.authClient.prepareCredentials();
|
|
75
|
+
this.auth = this.authClient.getDefaultAuth();
|
|
76
|
+
return this.auth;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns all rows that match the search stream query.
|
|
81
|
+
* The streamed content is not NDJSON format, but one JSON object with the
|
|
82
|
+
* property `results`. The whole JSON string can be parsed to an object and
|
|
83
|
+
* the `results` be extracted and converted to NDJSON lines. If the report
|
|
84
|
+
* is too large to be handled in this way, a possible solution is to parse
|
|
85
|
+
* the string directly to get the content of `results`.
|
|
86
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/customers.searchAds360/searchStream
|
|
87
|
+
* @param {string} customerId
|
|
88
|
+
* @param {string} loginCustomerId Login customer account ID (Mcc Account id).
|
|
89
|
+
* @param {string} query
|
|
90
|
+
* @return {!ReadableStream}
|
|
91
|
+
*/
|
|
92
|
+
async streamReport(customerId, loginCustomerId, query) {
|
|
93
|
+
const searchads = await this.getApiClient_(loginCustomerId);
|
|
94
|
+
const response = await searchads.customers.searchAds360.search({
|
|
95
|
+
customerId,
|
|
96
|
+
requestBody: { query },
|
|
97
|
+
}, { responseType: 'stream' });
|
|
98
|
+
return response.data;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Gets a report synchronously from a given Customer account.
|
|
103
|
+
* This is for test as it does not handle page token. For product env, use
|
|
104
|
+
* function `streamReport`.
|
|
105
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/customers.searchAds360/search#request-body
|
|
106
|
+
* @param {string} customerId
|
|
107
|
+
* @param {string} loginCustomerId Login customer account ID (Mcc Account id).
|
|
108
|
+
* @param {string} query
|
|
109
|
+
* @return {!SearchAds360Field}
|
|
110
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/searchAds360Fields#SearchAds360Field
|
|
111
|
+
*/
|
|
112
|
+
async getReport(customerId, loginCustomerId, query) {
|
|
113
|
+
const searchads = await this.getApiClient_(loginCustomerId);
|
|
114
|
+
const response = await searchads.customers.searchAds360.search({
|
|
115
|
+
customerId,
|
|
116
|
+
requestBody: { query },
|
|
117
|
+
});
|
|
118
|
+
return response.data.results;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Returns the requested field or resource (artifact) used by SearchAds360Service.
|
|
123
|
+
* This service doesn't require `login-customer-id` HTTP header.
|
|
124
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/searchAds360Fields/get
|
|
125
|
+
* @param {string} resourceName
|
|
126
|
+
* @return {!SearchAds360Field}
|
|
127
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/searchAds360Fields#SearchAds360Field
|
|
128
|
+
*/
|
|
129
|
+
async getReportField(resourceName) {
|
|
130
|
+
const searchads = await this.getApiClient_();
|
|
131
|
+
const response = await searchads.searchAds360Fields.get({ resourceName });
|
|
132
|
+
return response.data;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Returns all the custom columns associated with the customer in full detail.
|
|
137
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/customers.customColumns/list
|
|
138
|
+
* @param {string} customerId - The ID of the customer.
|
|
139
|
+
* @param {string} loginCustomerId - The ID of the manager.
|
|
140
|
+
* @return {!Array<CustomColumn>}
|
|
141
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/customers.customColumns#CustomColumn
|
|
142
|
+
*/
|
|
143
|
+
async listCustomColumns(customerId, loginCustomerId) {
|
|
144
|
+
const searchads = await this.getApiClient_(loginCustomerId);
|
|
145
|
+
const response = await searchads.customers.customColumns.list({ customerId });
|
|
146
|
+
return response.data.customColumns;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns the requested custom column in full detail.
|
|
151
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/customers.customColumns/get
|
|
152
|
+
* @param {string} columnId - The ID of the customColumn.
|
|
153
|
+
* @param {string} customerId - The ID of the customer.
|
|
154
|
+
* @param {string} loginCustomerId - The ID of the manager.
|
|
155
|
+
* @return {!CustomColumn}
|
|
156
|
+
* @see https://developers.google.com/search-ads/reporting/api/reference/rest/v0/customers.customColumns#CustomColumn
|
|
157
|
+
*/
|
|
158
|
+
async getCustomColumn(columnId, customerId, loginCustomerId) {
|
|
159
|
+
const resourceName = `customers/${customerId}/customColumns/${columnId}`;
|
|
160
|
+
const searchads = await this.getApiClient_(loginCustomerId);
|
|
161
|
+
const response = await searchads.customers.customColumns.get({ resourceName });
|
|
162
|
+
return response.data;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
module.exports = {
|
|
168
|
+
SearchAds,
|
|
169
|
+
API_VERSION,
|
|
170
|
+
API_SCOPES,
|
|
171
|
+
};
|
package/src/components/utils.js
CHANGED
|
@@ -539,6 +539,28 @@ const changeNamingFromSnakeToLowerCamel = (name) => {
|
|
|
539
539
|
(initial) => initial.substring(1).toUpperCase());
|
|
540
540
|
};
|
|
541
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Converts a JSON object which has snake naming convention to lower camel
|
|
544
|
+
* naming.
|
|
545
|
+
*
|
|
546
|
+
* @param {object} obj
|
|
547
|
+
* @return {object}
|
|
548
|
+
*/
|
|
549
|
+
const changeObjectNamingFromSnakeToLowerCamel = (obj) => {
|
|
550
|
+
if (Array.isArray(obj)) {
|
|
551
|
+
return obj.map(changeObjectNamingFromSnakeToLowerCamel);
|
|
552
|
+
} else if (typeof obj === 'object') {
|
|
553
|
+
const newObj = {};
|
|
554
|
+
Object.keys(obj).forEach((key) => {
|
|
555
|
+
newObj[changeNamingFromSnakeToLowerCamel(key)] =
|
|
556
|
+
changeObjectNamingFromSnakeToLowerCamel(obj[key]);
|
|
557
|
+
});
|
|
558
|
+
return newObj;
|
|
559
|
+
} else {
|
|
560
|
+
return obj;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
542
564
|
/**
|
|
543
565
|
* Returns the response data for a HTTP request. It will retry the specific
|
|
544
566
|
* times if there was errors happened.
|
|
@@ -584,5 +606,6 @@ module.exports = {
|
|
|
584
606
|
getObjectByPath,
|
|
585
607
|
changeNamingFromSnakeToUpperCamel,
|
|
586
608
|
changeNamingFromSnakeToLowerCamel,
|
|
609
|
+
changeObjectNamingFromSnakeToLowerCamel,
|
|
587
610
|
requestWithRetry,
|
|
588
611
|
};
|