From 8bac78fe9c0981fd375bada712835afaa1896db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Sun, 17 Jan 2021 21:01:53 -0300 Subject: [PATCH] Add user resource with GET endpoint --- .../nodes/Reddit/GenericFunctions.ts | 4 +-- .../nodes-base/nodes/Reddit/Reddit.node.ts | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Reddit/GenericFunctions.ts b/packages/nodes-base/nodes/Reddit/GenericFunctions.ts index 05c8c2d87f..7fcc137d28 100644 --- a/packages/nodes-base/nodes/Reddit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Reddit/GenericFunctions.ts @@ -13,7 +13,7 @@ import { /** - * Make an API request to Reddit. + * Make an authenticated or unauthenticated API request to Reddit. */ export async function redditApiRequest( this: IHookFunctions | IExecuteFunctions, @@ -61,7 +61,7 @@ export async function redditApiRequest( /** - * Make an API request to Reddit and return all results. + * Make an unauthenticated API request to Reddit and return all results. */ export async function redditApiRequestAllItems( this: IHookFunctions | IExecuteFunctions, diff --git a/packages/nodes-base/nodes/Reddit/Reddit.node.ts b/packages/nodes-base/nodes/Reddit/Reddit.node.ts index b299705599..44c16996ff 100644 --- a/packages/nodes-base/nodes/Reddit/Reddit.node.ts +++ b/packages/nodes-base/nodes/Reddit/Reddit.node.ts @@ -34,6 +34,11 @@ import { subredditOperations, } from './SubredditDescription'; +import { + userFields, + userOperations, +} from './UserDescription'; + export class Reddit implements INodeType { description: INodeTypeDescription = { displayName: 'Reddit', @@ -85,6 +90,10 @@ export class Reddit implements INodeType { name: 'Subreddit', value: 'subreddit', }, + { + name: 'User', + value: 'user', + }, ], default: 'myAccount', description: 'Resource to consume', @@ -105,6 +114,10 @@ export class Reddit implements INodeType { // subreddit ...subredditOperations, ...subredditFields, + + // user + ...userOperations, + ...userFields, ], }; @@ -219,6 +232,21 @@ export class Reddit implements INodeType { responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {}); } + + } else if (resource === 'user') { + + if (operation === 'get') { + + const username = this.getNodeParameter('username', i) as string; + const details = this.getNodeParameter('details', i) as string; + const endpoint = `user/${username}/${details}.json`; + + responseData = ['about', 'gilded'].includes(details) + ? await redditApiRequest.call(this, 'GET', endpoint, {}, {}) + : await handleListing.call(this, i, endpoint); + + } + } Array.isArray(responseData)