Minor improvements to Google Books Node

This commit is contained in:
Jan Oberhauser 2020-11-04 16:11:51 +01:00
parent 9a1328ccfb
commit 709dcdd57c
2 changed files with 18 additions and 18 deletions

View file

@ -26,7 +26,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
body, body,
qs, qs,
uri: uri || `https://www.googleapis.com/books/${resource}`, uri: uri || `https://www.googleapis.com/books/${resource}`,
json: true json: true,
}; };
try { try {
if (Object.keys(headers).length !== 0) { if (Object.keys(headers).length !== 0) {
@ -67,7 +67,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
} }
// Try to return the error prettier // Try to return the error prettier
throw new Error( throw new Error(
`Google Books error response [${error.statusCode}]: ${errors}` `Google Books error response [${error.statusCode}]: ${errors}`,
); );
} }
throw error; throw error;
@ -117,7 +117,7 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa
'typ': 'JWT', 'typ': 'JWT',
'alg': 'RS256', 'alg': 'RS256',
}, },
} },
); );
const options: OptionsWithUri = { const options: OptionsWithUri = {
@ -130,7 +130,7 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa
assertion: signature, assertion: signature,
}, },
uri: 'https://oauth2.googleapis.com/token', uri: 'https://oauth2.googleapis.com/token',
json: true json: true,
}; };
//@ts-ignore //@ts-ignore

View file

@ -95,7 +95,7 @@ export class GoogleBooks implements INodeType {
}, },
], ],
default: 'bookshelf', default: 'bookshelf',
description: 'The resource to operate on', description: 'The resource to operate on.',
}, },
{ {
displayName: 'Operation', displayName: 'Operation',
@ -121,7 +121,7 @@ export class GoogleBooks implements INodeType {
}, },
}, },
default: 'get', default: 'get',
description: 'The operation to perform', description: 'The operation to perform.',
}, },
{ {
displayName: 'Operation', displayName: 'Operation',
@ -162,7 +162,7 @@ export class GoogleBooks implements INodeType {
}, },
}, },
default: 'getAll', default: 'getAll',
description: 'The operation to perform', description: 'The operation to perform.',
}, },
{ {
displayName: 'Operation', displayName: 'Operation',
@ -188,7 +188,7 @@ export class GoogleBooks implements INodeType {
}, },
}, },
default: 'get', default: 'get',
description: 'The operation to perform', description: 'The operation to perform.',
}, },
{ {
displayName: 'My Library', displayName: 'My Library',
@ -204,7 +204,7 @@ export class GoogleBooks implements INodeType {
], ],
resource: [ resource: [
'bookshelf', 'bookshelf',
'bookshelfVolume' 'bookshelfVolume',
], ],
}, },
}, },
@ -217,7 +217,7 @@ export class GoogleBooks implements INodeType {
displayName: 'Search Query', displayName: 'Search Query',
name: 'searchQuery', name: 'searchQuery',
type: 'string', type: 'string',
description: 'Full-text search query string', description: 'Full-text search query string.',
default: '', default: '',
required: true, required: true,
displayOptions: { displayOptions: {
@ -260,7 +260,7 @@ export class GoogleBooks implements INodeType {
displayName: 'Bookshelf ID', displayName: 'Bookshelf ID',
name: 'shelfId', name: 'shelfId',
type: 'string', type: 'string',
description: 'ID of the bookshelf', description: 'ID of the bookshelf.',
default: '', default: '',
required: true, required: true,
displayOptions: { displayOptions: {
@ -274,7 +274,7 @@ export class GoogleBooks implements INodeType {
], ],
resource: [ resource: [
'bookshelf', 'bookshelf',
'bookshelfVolume' 'bookshelfVolume',
], ],
}, },
}, },
@ -283,7 +283,7 @@ export class GoogleBooks implements INodeType {
displayName: 'Bookshelf ID', displayName: 'Bookshelf ID',
name: 'shelfId', name: 'shelfId',
type: 'string', type: 'string',
description: 'ID of the bookshelf', description: 'ID of the bookshelf.',
default: '', default: '',
required: true, required: true,
displayOptions: { displayOptions: {
@ -301,7 +301,7 @@ export class GoogleBooks implements INodeType {
displayName: 'Volume ID', displayName: 'Volume ID',
name: 'volumeId', name: 'volumeId',
type: 'string', type: 'string',
description: 'ID of the volume', description: 'ID of the volume.',
default: '', default: '',
required: true, required: true,
displayOptions: { displayOptions: {
@ -323,7 +323,7 @@ export class GoogleBooks implements INodeType {
displayName: 'Volume Position', displayName: 'Volume Position',
name: 'volumePosition', name: 'volumePosition',
type: 'string', type: 'string',
description: 'Position on shelf to move the item (0 puts the item before the current first item, 1 puts it between the first and the second and so on) ', description: 'Position on shelf to move the item (0 puts the item before the<br />current first item, 1 puts it between the first and the second and so on).',
default: '', default: '',
required: true, required: true,
displayOptions: { displayOptions: {
@ -389,7 +389,7 @@ export class GoogleBooks implements INodeType {
if (operation === 'get') { if (operation === 'get') {
const volumeId = this.getNodeParameter('volumeId', i) as string; const volumeId = this.getNodeParameter('volumeId', i) as string;
responseData = await googleApiRequest.call(this, 'GET', `v1/volumes/${volumeId}`, {}); responseData = await googleApiRequest.call(this, 'GET', `v1/volumes/${volumeId}`, {});
} else if (operation === 'getAll') { } else if (operation === 'getAll') {
const searchQuery = this.getNodeParameter('searchQuery', i) as string; const searchQuery = this.getNodeParameter('searchQuery', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean; const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll) { if (returnAll) {
@ -399,7 +399,7 @@ export class GoogleBooks implements INodeType {
responseData = await googleApiRequest.call(this, 'GET', `v1/volumes?q=${searchQuery}`, {}, qs); responseData = await googleApiRequest.call(this, 'GET', `v1/volumes?q=${searchQuery}`, {}, qs);
responseData = responseData.items || []; responseData = responseData.items || [];
} }
} }
} }
if (resource === 'bookshelf') { if (resource === 'bookshelf') {
@ -450,7 +450,7 @@ export class GoogleBooks implements INodeType {
responseData = await googleApiRequest.call(this, 'POST', `v1/mylibrary/bookshelves/${shelfId}/clearVolumes`); responseData = await googleApiRequest.call(this, 'POST', `v1/mylibrary/bookshelves/${shelfId}/clearVolumes`);
} }
if (operation === 'getAll') { if (operation === 'getAll') {
const shelfId = this.getNodeParameter('shelfId', i) as string; const shelfId = this.getNodeParameter('shelfId', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean; const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const myLibrary = this.getNodeParameter('myLibrary', i) as boolean; const myLibrary = this.getNodeParameter('myLibrary', i) as boolean;