@google-cloud/nodejs-common 2.2.0 → 2.2.2
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 +1 -1
- package/src/apis/dfa_reporting.js +3 -1
- package/src/apis/spreadsheets.js +63 -11
package/package.json
CHANGED
|
@@ -54,6 +54,7 @@ const API_VERSION = 'v4';
|
|
|
54
54
|
* floodlightConfigurationId:string,
|
|
55
55
|
* floodlightActivityId:string,
|
|
56
56
|
* quantity:(number|undefined),
|
|
57
|
+
* adUserDataConsent:ConsentStatus,
|
|
57
58
|
* },
|
|
58
59
|
* customVariables:(!Array<string>|undefined),
|
|
59
60
|
* encryptionInfo:({
|
|
@@ -76,6 +77,7 @@ const PICKED_PROPERTIES = [
|
|
|
76
77
|
'timestampMicros',
|
|
77
78
|
'value',
|
|
78
79
|
'quantity',
|
|
80
|
+
'adUserDataConsent',
|
|
79
81
|
];
|
|
80
82
|
|
|
81
83
|
/**
|
|
@@ -90,7 +92,7 @@ const IDENTIFIERS = [
|
|
|
90
92
|
|
|
91
93
|
const MAX_IDENTIFIERS_PER_USER = 5;
|
|
92
94
|
/**
|
|
93
|
-
* Google DfaReport API
|
|
95
|
+
* Google DfaReport API v4.0 stub.
|
|
94
96
|
* see https://developers.google.com/doubleclick-advertisers/service_accounts
|
|
95
97
|
*/
|
|
96
98
|
class DfaReporting extends GoogleApiClient {
|
package/src/apis/spreadsheets.js
CHANGED
|
@@ -109,21 +109,73 @@ class Spreadsheets extends GoogleApiClient {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
112
|
+
* Returns whether the sheet with speicified name exists.
|
|
113
|
+
* @param {string} sheetName
|
|
114
|
+
* @return {boolean}
|
|
115
|
+
*/
|
|
116
|
+
async hasSheet(sheetName) {
|
|
117
|
+
const sheets = await this.getApiClient();
|
|
118
|
+
const spreadsheet = await sheets.spreadsheets.get(
|
|
119
|
+
{ spreadsheetId: this.spreadsheetId });
|
|
120
|
+
return spreadsheet.data.sheets.some(
|
|
121
|
+
({ properties: { title } }) => title === sheetName);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Creates a sheet with the gvien name.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} sheetName
|
|
128
|
+
*/
|
|
129
|
+
async createSheet(sheetName) {
|
|
130
|
+
const sheets = await this.getApiClient();
|
|
131
|
+
await sheets.spreadsheets.batchUpdate({
|
|
132
|
+
spreadsheetId: this.spreadsheetId,
|
|
133
|
+
requestBody: {
|
|
134
|
+
requests: [{ addSheet: { properties: { title: sheetName } } }],
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Deletes a sheet with the gvien name.
|
|
141
|
+
*
|
|
142
|
+
* @param {string} sheetName
|
|
143
|
+
*/
|
|
144
|
+
async deleteSheet(sheetName) {
|
|
145
|
+
if (await this.hasSheet(sheetName)) {
|
|
146
|
+
const sheetId = await this.getSheetId(sheetName);
|
|
147
|
+
const sheets = await this.getApiClient();
|
|
148
|
+
await sheets.spreadsheets.batchUpdate({
|
|
149
|
+
spreadsheetId: this.spreadsheetId,
|
|
150
|
+
requestBody: {
|
|
151
|
+
requests: [{ deleteSheet: { sheetId } }],
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Clears the content of the Sheet. If the Sheet doesn't exist, then creates
|
|
159
|
+
* an empty sheet with the sheetName..
|
|
160
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear
|
|
115
161
|
* @param {string} sheetName Name of the Sheet.
|
|
116
162
|
*/
|
|
117
163
|
async clearSheet(sheetName) {
|
|
118
|
-
const request = {
|
|
119
|
-
spreadsheetId: this.spreadsheetId,
|
|
120
|
-
range: sheetName,
|
|
121
|
-
};
|
|
122
164
|
try {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
165
|
+
const hasSheet = await this.hasSheet(sheetName);
|
|
166
|
+
if (!hasSheet) {
|
|
167
|
+
await this.createSheet(sheetName);
|
|
168
|
+
this.logger.debug(`Create sheet[${sheetName}]`);
|
|
169
|
+
} else {
|
|
170
|
+
const sheets = await this.getApiClient();
|
|
171
|
+
const request = {
|
|
172
|
+
spreadsheetId: this.spreadsheetId,
|
|
173
|
+
range: sheetName,
|
|
174
|
+
};
|
|
175
|
+
const response = await sheets.spreadsheets.values.clear(request);
|
|
176
|
+
const data = response.data;
|
|
177
|
+
this.logger.debug(`Clear sheet[${sheetName}]: `, data);
|
|
178
|
+
}
|
|
127
179
|
} catch (error) {
|
|
128
180
|
this.logger.error(error.toString());
|
|
129
181
|
throw error;
|