Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add promise support #1091

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add promise support
  • Loading branch information
JustinBeckwith committed Mar 29, 2018
commit 297a1b26bb3b41f7aeec340de47063c18cfed704
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ urlshortener.url.get(params, (err, response) => {
});
```

You can also use promises:

``` js
urlshortener.url.get(params)
.then(response => {
console.log('Long url is', response.data.longUrl);
})
.catch(error => console.error);
```

Or async/await:

``` js
async function runSample() {
const response = await urlshortener.url.get(params);
console.log('Long url is', response.data.longUrl);
}
runSample().catch(console.error);
```


**Example** Updates an email message's labels, using the `resource`
parameter to specify the request body.

Expand Down Expand Up @@ -256,7 +277,7 @@ const {google} = require('googleapis');
const plus = google.plus('v1');
const OAuth2 = google.auth.OAuth2;

// WARNING: Make sure your CLIENT_SECRET is stored in a safe place.
// WARNING: Make sure your CLIENT_SECRET is stored in a safe place.
const oauth2Client = new OAuth2(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
Expand Down Expand Up @@ -420,9 +441,9 @@ This client supports multipart media uploads. The resource parameters are specif
This example uploads a plain text file to Google Drive with the title "Test" and contents "Hello World".

``` js
const drive = google.drive({
version: 'v3',
auth: oauth2Client
const drive = google.drive({
version: 'v3',
auth: oauth2Client
});

drive.files.create({
Expand All @@ -445,8 +466,8 @@ Note: Your readable stream may be [unstable][stability]. Use at your own risk.

```js
const fs = require('fs');
const drive = google.drive({
version: 'v3',
const drive = google.drive({
version: 'v3',
auth: oauth2Client
});

Expand Down Expand Up @@ -565,7 +586,7 @@ google.auth.getApplicationDefault((err, authClient, projectId) => {
bigquery.datasets.delete(request, (err, response) => {
if (err) {
throw err;
}
}
console.log(response.data);
});
});
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions samples/analyticsReporting/batchGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const analyticsreporting = google.analyticsreporting({
auth: sampleClient.oAuth2Client
});

function runSample (callback) {
analyticsreporting.reports.batchGet({
async function runSample () {
const res = await analyticsreporting.reports.batchGet({
resource: {
reportRequests: [{
viewId: '65704806',
Expand All @@ -42,13 +42,9 @@ function runSample (callback) {
]
}]
}
}, (err, res) => {
if (err) {
throw err;
}
console.log(res.data);
callback(res.data);
});
console.log(res.data);
return res.data;
}

// if invoked directly (not tests), authenticate and run the samples
Expand All @@ -58,7 +54,7 @@ if (module === require.main) {
if (err) {
throw err;
}
runSample(() => { /* sample complete */ });
runSample().catch(e => console.error);
});
}

Expand Down
151 changes: 99 additions & 52 deletions src/apis/abusiveexperiencereport/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import {AxiosPromise} from 'axios';

import {GoogleApis} from '../..';
import {BodyResponseCallback, GlobalOptions, MethodOptions} from '../../lib/api';
import {createAPIRequest} from '../../lib/apirequest';
Expand Down Expand Up @@ -53,10 +55,15 @@ export class Abusiveexperiencereport {
constructor(options: GlobalOptions, google: GoogleApis) {
this._options = options || {};
this.google = google;
this.getRoot.bind(this);

this.sites = new Resource$Sites(this);
this.violatingSites = new Resource$Violatingsites(this);
}

getRoot() {
return this.root;
}
}

/**
Expand Down Expand Up @@ -106,8 +113,14 @@ export class Resource$Sites {
root: Abusiveexperiencereport;
constructor(root: Abusiveexperiencereport) {
this.root = root;
this.getRoot.bind(this);
}

getRoot() {
return this.root;
}


/**
* abusiveexperiencereport.sites.get
* @desc Gets a summary of the abusive experience rating of a site.
Expand All @@ -120,39 +133,58 @@ export class Resource$Sites {
* @param {callback} callback The callback that handles the response.
* @return {object} Request object
*/
get =
(params: any,
options: MethodOptions|BodyResponseCallback<Schema$SiteSummaryResponse>,
callback?: BodyResponseCallback<Schema$SiteSummaryResponse>) => {
if (typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
const rootUrl = options.rootUrl ||
'https://abusiveexperiencereport.googleapis.com/';
const parameters = {
options: Object.assign(
{
url: (rootUrl + '/v1/{name}').replace(/([^:]\/)\/+/g, '$1'),
method: 'GET'
},
options),
params,
requiredParams: ['name'],
pathParams: ['name'],
context: this.root
};
createAPIRequest<Schema$SiteSummaryResponse>(parameters, callback!);
};
get(params: any,
options?: MethodOptions): AxiosPromise<Schema$SiteSummaryResponse>;
get(params: any,
options: MethodOptions|BodyResponseCallback<Schema$SiteSummaryResponse>,
callback?: BodyResponseCallback<Schema$SiteSummaryResponse>): void;
get(params: any,
options?: MethodOptions|BodyResponseCallback<Schema$SiteSummaryResponse>,
callback?: BodyResponseCallback<Schema$SiteSummaryResponse>):
void|AxiosPromise<Schema$SiteSummaryResponse> {
if (typeof options === 'function') {
callback = options;
options = {};
}
if (typeof params === 'function') {
callback = params;
params = {};
}
options = options || {};
const rootUrl =
options.rootUrl || 'https://abusiveexperiencereport.googleapis.com/';
const parameters = {
options: Object.assign(
{
url: (rootUrl + '/v1/{name}').replace(/([^:]\/)\/+/g, '$1'),
method: 'GET'
},
options),
params,
requiredParams: ['name'],
pathParams: ['name'],
context: this.getRoot()
};
if (callback) {
createAPIRequest<Schema$SiteSummaryResponse>(parameters, callback);
} else {
return createAPIRequest<Schema$SiteSummaryResponse>(parameters);
}
}
}

export class Resource$Violatingsites {
root: Abusiveexperiencereport;
constructor(root: Abusiveexperiencereport) {
this.root = root;
this.getRoot.bind(this);
}

getRoot() {
return this.root;
}


/**
* abusiveexperiencereport.violatingSites.list
* @desc Lists sites with Abusive Experience Report statuses of "Failing".
Expand All @@ -164,31 +196,46 @@ export class Resource$Violatingsites {
* @param {callback} callback The callback that handles the response.
* @return {object} Request object
*/
list =
(params: any,
options: MethodOptions|
BodyResponseCallback<Schema$ViolatingSitesResponse>,
callback?: BodyResponseCallback<Schema$ViolatingSitesResponse>) => {
if (typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
const rootUrl = options.rootUrl ||
'https://abusiveexperiencereport.googleapis.com/';
const parameters = {
options: Object.assign(
{
url: (rootUrl + '/v1/violatingSites')
.replace(/([^:]\/)\/+/g, '$1'),
method: 'GET'
},
options),
params,
requiredParams: [],
pathParams: [],
context: this.root
};
createAPIRequest<Schema$ViolatingSitesResponse>(parameters, callback!);
};
list(params: any, options?: MethodOptions):
AxiosPromise<Schema$ViolatingSitesResponse>;
list(
params: any,
options: MethodOptions|
BodyResponseCallback<Schema$ViolatingSitesResponse>,
callback?: BodyResponseCallback<Schema$ViolatingSitesResponse>): void;
list(
params: any,
options?: MethodOptions|
BodyResponseCallback<Schema$ViolatingSitesResponse>,
callback?: BodyResponseCallback<Schema$ViolatingSitesResponse>):
void|AxiosPromise<Schema$ViolatingSitesResponse> {
if (typeof options === 'function') {
callback = options;
options = {};
}
if (typeof params === 'function') {
callback = params;
params = {};
}
options = options || {};
const rootUrl =
options.rootUrl || 'https://abusiveexperiencereport.googleapis.com/';
const parameters = {
options: Object.assign(
{
url: (rootUrl + '/v1/violatingSites').replace(/([^:]\/)\/+/g, '$1'),
method: 'GET'
},
options),
params,
requiredParams: [],
pathParams: [],
context: this.getRoot()
};
if (callback) {
createAPIRequest<Schema$ViolatingSitesResponse>(parameters, callback);
} else {
return createAPIRequest<Schema$ViolatingSitesResponse>(parameters);
}
}
}
Loading