@@ -59,6 +59,58 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
59
59
60
60
npm install --save @google-cloud/bigquery-data-transfer
61
61
62
+ ### Using the client library
63
+
64
+ ``` javascript
65
+
66
+ if (
67
+ ! process .env .GCLOUD_PROJECT ||
68
+ ! process .env .GOOGLE_APPLICATION_CREDENTIALS
69
+ ) {
70
+ throw new Error (
71
+ ' Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
72
+ );
73
+ }
74
+
75
+ const bigqueryDataTransfer = require (' @google-cloud/bigquery-data-transfer' );
76
+
77
+ const client = new bigqueryDataTransfer.v1.DataTransferServiceClient ({
78
+ // optional auth parameters.
79
+ });
80
+ const projectId = process .env .GCLOUD_PROJECT ;
81
+
82
+ // Iterate over all elements.
83
+ const formattedParent = client .locationPath (projectId, ' us-central1' );
84
+
85
+ client .listDataSources ({parent: formattedParent}).then (responses => {
86
+ const resources = responses[0 ];
87
+ for (let i = 0 ; i < resources .length ; i += 1 ) {
88
+ console .log (resources[i]);
89
+ }
90
+ });
91
+
92
+ const options = {autoPaginate: false };
93
+ const callback = responses => {
94
+ // The actual resources in a response.
95
+ const resources = responses[0 ];
96
+ // The next request if the response shows that there are more responses.
97
+ const nextRequest = responses[1 ];
98
+ // The actual response object, if necessary.
99
+ // const rawResponse = responses[2];
100
+ for (let i = 0 ; i < resources .length ; i += 1 ) {
101
+ console .log (resources[i]);
102
+ }
103
+ if (nextRequest) {
104
+ // Fetch the next page.
105
+ return client .listDataSources (nextRequest, options).then (callback);
106
+ }
107
+ };
108
+ client .listDataSources ({parent: formattedParent}, options).then (callback);
109
+
110
+ client .listDataSourcesStream ({parent: formattedParent}).on (' data' , element => {
111
+ console .log (element);
112
+ });
113
+ ```
62
114
63
115
64
116
The [ BigQuery Data Transfer Service Node.js Client API Reference] [ client-docs ] documentation
@@ -88,4 +140,4 @@ See [LICENSE](https://github.com/googleapis/nodejs-bigquery-data-transfer/blob/m
88
140
89
141
[ client-docs ] : https://cloud.google.com/nodejs/docs/reference/bigquery-data-transfer/latest/
90
142
[ product-docs ] : https://cloud.google.com/bigquery/docs/reference/datatransfer/rest/
91
- [ shell_img ] : http: //gstatic.com/cloudssh/images/open-btn.png
143
+ [ shell_img ] : //gstatic.com/cloudssh/images/open-btn.png
0 commit comments