mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Add listing resource
This commit is contained in:
parent
c346560ec6
commit
13ad0b84fb
58
packages/nodes-base/nodes/Reddit/ListingDescription.ts
Normal file
58
packages/nodes-base/nodes/Reddit/ListingDescription.ts
Normal 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[];
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue