mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
feat(Reddit Node): Add possibility to query saved posts (#3034)
* chore: add nvmrc with required node version
* feat: added saved posts to reddit node with credentials on User resource
* Changed Details order
* Fixed lint issue
* Moved saved posts to profile as it only works for the logged in user, This avoids the breaking change
* Removed .nvmrc
* ⚡ Improvements
Co-authored-by: Yassine Fathi <hi@m4tt72.com>
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
parent
b5ecccb840
commit
5ba4c27d8c
|
@ -4,7 +4,7 @@ import {
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IDataObject, NodeApiError, NodeOperationError,
|
IDataObject, JsonObject, NodeApiError, NodeOperationError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -45,7 +45,7 @@ export async function redditApiRequest(
|
||||||
try {
|
try {
|
||||||
return await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options);
|
return await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(this.getNode(), error);
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,7 +53,7 @@ export async function redditApiRequest(
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request.call(this, options);
|
return await this.helpers.request.call(this, options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(this.getNode(), error);
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,11 @@ export const profileFields: INodeProperties[] = [
|
||||||
value: 'prefs',
|
value: 'prefs',
|
||||||
description: 'Return the settings preferences of the logged-in user',
|
description: 'Return the settings preferences of the logged-in user',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Saved',
|
||||||
|
value: 'saved',
|
||||||
|
description: 'Return the saved posts for the user',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Trophies',
|
name: 'Trophies',
|
||||||
value: 'trophies',
|
value: 'trophies',
|
||||||
|
@ -77,4 +82,51 @@ export const profileFields: INodeProperties[] = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Return all results.',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'profile',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
details: [
|
||||||
|
'saved',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
default: 100,
|
||||||
|
description: 'The number of results to return.',
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'profile',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
details: [
|
||||||
|
'saved',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -352,7 +352,15 @@ export class Reddit implements INodeType {
|
||||||
|
|
||||||
const details = this.getNodeParameter('details', i) as string;
|
const details = this.getNodeParameter('details', i) as string;
|
||||||
const endpoint = `api/v1/${endpoints[details]}`;
|
const endpoint = `api/v1/${endpoints[details]}`;
|
||||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
|
let username;
|
||||||
|
|
||||||
|
if (details === 'saved') {
|
||||||
|
({ name: username } = await redditApiRequest.call(this, 'GET', `api/v1/me`, {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = details === 'saved'
|
||||||
|
? await handleListing.call(this, i, `user/${username}/saved.json`)
|
||||||
|
: await redditApiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
|
||||||
if (details === 'identity') {
|
if (details === 'identity') {
|
||||||
responseData = responseData.features;
|
responseData = responseData.features;
|
||||||
|
|
Loading…
Reference in a new issue