@google-cloud/nodejs-common 1.7.3 → 1.8.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google-cloud/nodejs-common",
3
- "version": "1.7.3",
3
+ "version": "1.8.0",
4
4
  "description": "A NodeJs common library for solutions based on Cloud Functions",
5
5
  "author": "Google Inc.",
6
6
  "license": "Apache-2.0",
@@ -122,17 +122,44 @@ class AdsDataHub {
122
122
  /**
123
123
  * Lists the analysis queries owned by the specified customer.
124
124
  * @see https://developers.google.com/ads-data-hub/reference/rest/v1/customers.analysisQueries/list
125
+ * @param {Object=} parameters The query parameter object.
125
126
  * @param {string=} customerId
126
127
  * @return {!Promise<{
127
128
  * queries:Array<Object>,
128
129
  * nextPageToken:string,
129
130
  * }>}
130
131
  */
131
- async listQuery(customerId = this.customerId) {
132
- const path = `customers/${customerId}/analysisQueries`;
132
+ async listQuery(parameters = {}, customerId = this.customerId) {
133
+ const querystring = this.getQueryString_(parameters);
134
+ const path = `customers/${customerId}/analysisQueries`
135
+ + (querystring ? `?${querystring}` : '');
133
136
  return this.sendRequestAndReturnResponse_(path);
134
137
  }
135
138
 
139
+ /**
140
+ * Starts execution on a transient analysis query. The results will be written
141
+ * to the specified BigQuery destination table. The returned operation name
142
+ * can be used to poll for query completion status.
143
+ * @see https://developers.google.com/ads-data-hub/reference/rest/v1/customers.analysisQueries/startTransient
144
+ * @param {string} queryText The content of the query.
145
+ * @param {Object} spec Defines the query execution parameters.
146
+ * @see https://developers.google.com/ads-data-hub/reference/rest/v1/QueryExecutionSpec
147
+ * @param {string} destTable Destination BigQuery table for query results with
148
+ * the format 'project.dataset.table_name'. If specified, the project must
149
+ * be explicitly whitelisted for the customer's ADH account. If project is
150
+ * not specified, uses default project for the provided customer. If
151
+ * neither project nor dataset is specified, uses the default project and
152
+ * dataset.
153
+ * @param {string=} customerId
154
+ * @return {!Promise<Object>} Promised operation object.
155
+ * @see https://developers.google.com/ads-data-hub/reference/rest/v1/operations#Operation
156
+ */
157
+ async startTransientQuery(queryText, spec, destTable, customerId = this.customerId) {
158
+ const path = `customers/${customerId}/analysisQueries:startTransient`;
159
+ const data = { query: { queryText }, spec, destTable };
160
+ return this.sendRequestAndReturnResponse_(path, 'POST', data);
161
+ }
162
+
136
163
  /**
137
164
  * Creates a query and returns the unique query name in the form of
138
165
  * 'customers/[customerId]/analysisQueries/[resource_id]'.
@@ -140,12 +167,6 @@ class AdsDataHub {
140
167
  * @param {string} title The title of the query.
141
168
  * @param {string} queryText The content of the query
142
169
  * @return {!Promise<string>} Promised unique name of created query.
143
- *
144
- * TODO: currently here only take two properties of customers.analysisQueries
145
- * which may be not enough in future requests. If that happened, the
146
- * arguments of this function should be refactored into an object to
147
- * present an AnalysisQuery.
148
- * See https://developers.google.com/ads-data-hub/reference/rest/v1/customers.analysisQueries#resource:-analysisquery
149
170
  */
150
171
  async createQuery(title, queryText) {
151
172
  const path = `customers/${this.customerId}/analysisQueries`;
@@ -202,6 +223,19 @@ class AdsDataHub {
202
223
  async getQueryStatus(operationName) {
203
224
  return this.sendRequestAndReturnResponse_(operationName);
204
225
  }
226
+
227
+ /**
228
+ * Gets the query string of a parameter object.
229
+ * @param {Object} parameters The object of key-value pairs which will be
230
+ * converted into query string format.
231
+ * @return string
232
+ * @private
233
+ */
234
+ getQueryString_(parameters = {}) {
235
+ return Object.keys(parameters)
236
+ .map((key) => key + '=' + encodeURIComponent(parameters[key]))
237
+ .join('&');
238
+ }
205
239
  }
206
240
 
207
241
  exports.AdsDataHub = AdsDataHub;