Add user resource with GET endpoint

This commit is contained in:
Iván Ovejero 2021-01-17 21:01:53 -03:00
parent 36c3fb2039
commit 8bac78fe9c
2 changed files with 30 additions and 2 deletions

View file

@ -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,

View file

@ -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)