Add listing resource

This commit is contained in:
Iván Ovejero 2021-01-17 15:01:18 -03:00
parent c346560ec6
commit 13ad0b84fb
2 changed files with 98 additions and 3 deletions

View file

@ -0,0 +1,58 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const listingOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
default: 'get',
description: 'Operation to perform',
options: [
{
name: 'Get',
value: 'get',
},
],
displayOptions: {
show: {
resource: [
'listing',
],
},
},
},
] as INodeProperties[];
export const listingFields = [
{
displayName: 'Type',
name: 'type',
type: 'options',
required: true,
default: 'trending',
description: 'Type of listing to retrieve',
options: [
{
name: 'Trending',
value: 'trending',
},
{
name: 'Best',
value: 'best',
},
],
displayOptions: {
show: {
resource: [
'listing',
],
operation: [
'get',
],
},
},
},
] as INodeProperties[];

View file

@ -23,6 +23,15 @@ import {
submissionOperations,
} from './SubmissionDescription';
import {
listingFields,
listingOperations,
} from './ListingDescription';
import {
snakeCase,
} from 'change-case';
export class Reddit implements INodeType {
description: INodeTypeDescription = {
displayName: 'Reddit',
@ -58,6 +67,10 @@ export class Reddit implements INodeType {
name: 'Submission',
value: 'submission',
},
{
name: 'Listing',
value: 'listing',
},
],
default: 'myAccount',
description: 'Resource to consume',
@ -67,8 +80,12 @@ export class Reddit implements INodeType {
...myAccountOperations,
// submission
...submissionFields,
...submissionOperations,
...submissionFields,
// listing
...listingOperations,
...listingFields,
],
};
@ -104,9 +121,9 @@ export class Reddit implements INodeType {
}
} else if (resource === 'post') {
} else if (resource === 'submission') {
if (operation === 'submit') {
if (operation === 'post') {
const body: IDataObject = {
title: this.getNodeParameter('title', i),
@ -128,6 +145,26 @@ export class Reddit implements INodeType {
}
} else if (resource === 'listing') {
if (operation === 'get') {
const type = this.getNodeParameter('type', i) as string;
if (type === 'trending') {
const endpoint = 'api/trending_subreddits.json';
responseData = await redditApiRequest.call(this, 'GET', endpoint, {}, {}, true);
} else if (type === 'best') {
const endpoint = 'best.json';
responseData = await redditApiRequest.call(this, 'GET', endpoint, {}, {}, true);
}
}
}
Array.isArray(responseData)