Refactor per feedback

This commit is contained in:
Iván Ovejero 2021-01-22 19:35:12 -03:00
parent 04ad3f2b77
commit 0b0213549b
7 changed files with 658 additions and 568 deletions

View file

@ -1,106 +1,106 @@
import { // import {
INodeProperties, // INodeProperties,
} from 'n8n-workflow'; // } from 'n8n-workflow';
export const allRedditOperations = [ // export const allRedditOperations = [
{ // {
displayName: 'Operation', // displayName: 'Operation',
name: 'operation', // name: 'operation',
type: 'options', // type: 'options',
default: 'get', // default: 'get',
description: 'Operation to perform', // description: 'Operation to perform',
options: [ // options: [
{ // {
name: 'Get', // name: 'Get All',
value: 'get', // value: 'getAll',
}, // },
], // ],
displayOptions: { // displayOptions: {
show: { // show: {
resource: [ // resource: [
'allReddit', // 'allReddit',
], // ],
}, // },
}, // },
}, // },
] as INodeProperties[]; // ] as INodeProperties[];
export const allRedditFields = [ // export const allRedditFields = [
{ // {
displayName: 'Information', // displayName: 'Information',
name: 'information', // name: 'information',
type: 'options', // type: 'options',
required: true, // required: true,
default: 'trending', // default: 'trending',
description: 'All-Reddit information to retrieve', // description: 'All-Reddit information to retrieve',
options: [ // options: [
{ // {
name: 'Trending', // name: 'Trending',
value: 'trending', // value: 'trending',
description: 'Currently trending subreddits', // description: 'Currently trending subreddits',
}, // },
{ // {
name: 'Best', // name: 'Best',
value: 'best', // value: 'best',
description: 'Top posts in all of Reddit', // description: 'Top posts in all of Reddit',
}, // },
], // ],
displayOptions: { // displayOptions: {
show: { // show: {
resource: [ // resource: [
'allReddit', // 'allReddit',
], // ],
operation: [ // operation: [
'get', // 'getAll',
], // ],
}, // },
}, // },
}, // },
{ // {
displayName: 'Return All', // displayName: 'Return All',
name: 'returnAll', // name: 'returnAll',
type: 'boolean', // type: 'boolean',
default: false, // default: false,
description: 'Return all results', // description: 'Return all results',
displayOptions: { // displayOptions: {
show: { // show: {
resource: [ // resource: [
'allReddit', // 'allReddit',
], // ],
operation: [ // operation: [
'get', // 'getAll',
], // ],
information: [ // information: [
'best', // 'best',
], // ],
}, // },
}, // },
}, // },
{ // {
displayName: 'Limit', // displayName: 'Limit',
name: 'limit', // name: 'limit',
type: 'number', // type: 'number',
default: 5, // default: 5,
description: 'The number of results to return', // description: 'The number of results to return',
typeOptions: { // typeOptions: {
minValue: 1, // minValue: 1,
maxValue: 100, // maxValue: 100,
}, // },
displayOptions: { // displayOptions: {
show: { // show: {
resource: [ // resource: [
'allReddit', // 'allReddit',
], // ],
operation: [ // operation: [
'get', // 'getAll',
], // ],
information: [ // information: [
'best', // 'best',
], // ],
returnAll: [ // returnAll: [
false, // false,
], // ],
}, // },
}, // },
}, // },
] as INodeProperties[]; // ] as INodeProperties[];

View file

@ -0,0 +1,68 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const commentOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
default: 'create',
description: 'Operation to perform',
options: [
{
name: 'Create',
value: 'create',
},
],
displayOptions: {
show: {
resource: [
'comment',
],
},
},
},
] as INodeProperties[];
export const commentFields = [
// ----------------------------------
// comment: create
// ----------------------------------
{
displayName: 'Target',
name: 'target',
type: 'string',
default: '',
description: 'ID of the comment target',
placeholder: 't3_15bfi0',
displayOptions: {
show: {
resource: [
'comment',
],
operation: [
'create',
],
},
},
},
{
displayName: 'Text',
name: 'text',
type: 'string',
required: true,
default: '',
description: 'Text of the comment (Markdown supported)',
displayOptions: {
show: {
resource: [
'comment',
],
operation: [
'create',
],
},
},
},
] as INodeProperties[];

View file

@ -20,35 +20,27 @@ export async function redditApiRequest(
method: string, method: string,
endpoint: string, endpoint: string,
qs: IDataObject, qs: IDataObject,
body: IDataObject,
): Promise<any> { // tslint:disable-line:no-any ): Promise<any> { // tslint:disable-line:no-any
const resource = this.getNodeParameter('resource', 0) as string; const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string; const authRequired = ['profile', 'post', 'comment'].includes(resource);
const requiresAuth = resource === 'myAccount' ||
(resource === 'submission' && ['post', 'comment'].includes(operation));
const options: OptionsWithUri = { const options: OptionsWithUri = {
headers: { headers: {
'user-agent': 'n8n', 'user-agent': 'n8n',
}, },
method, method,
uri: requiresAuth ? `https://oauth.reddit.com/${endpoint}` : `https://www.reddit.com/${endpoint}`, uri: authRequired ? `https://oauth.reddit.com/${endpoint}` : `https://www.reddit.com/${endpoint}`,
qs, qs,
body,
json: true, json: true,
}; };
if (!Object.keys(body).length) {
delete options.body;
}
if (!Object.keys(qs).length) { if (!Object.keys(qs).length) {
delete options.qs; delete options.qs;
} }
try { try {
return requiresAuth return authRequired
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options) ? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
: await this.helpers.request.call(this, options); : await this.helpers.request.call(this, options);
@ -70,16 +62,24 @@ export async function redditApiRequestAllItems(
method: string, method: string,
endpoint: string, endpoint: string,
qs: IDataObject, qs: IDataObject,
body: IDataObject,
): Promise<any> { // tslint:disable-line:no-any ): Promise<any> { // tslint:disable-line:no-any
let responseData; let responseData;
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
do { do {
responseData = await redditApiRequest.call(this, method, endpoint, qs, body); console.log(method);
console.log(endpoint);
console.log(qs);
responseData = await redditApiRequest.call(this, method, endpoint, qs);
console.log(responseData);
qs.after = responseData.after; qs.after = responseData.after;
responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
if (endpoint === 'api/search_reddit_names.json') {
responseData.names.forEach((name: IDataObject) => returnData.push(name));
} else {
responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
}
if (qs.limit && returnData.length >= qs.limit) { if (qs.limit && returnData.length >= qs.limit) {
return returnData; return returnData;
@ -98,18 +98,30 @@ export async function handleListing(
i: number, i: number,
endpoint: string, endpoint: string,
): Promise<any> { // tslint:disable-line:no-any ): Promise<any> { // tslint:disable-line:no-any
let responseData; let responseData;
const returnAll = this.getNodeParameter('returnAll', i); const resource = this.getNodeParameter('resource', 0);
if (returnAll) { const operation = this.getNodeParameter('operation', 0);
return await redditApiRequestAllItems.call(this, 'GET', endpoint, {}, {});
const qs: IDataObject = {};
if (resource === 'subreddit' && operation === 'getAll') {
const filters = this.getNodeParameter('filters', i) as IDataObject;
if (filters.query) {
qs.query = filters.query;
}
} }
const qs: IDataObject = { const returnAll = this.getNodeParameter('returnAll', i);
limit: this.getNodeParameter('limit', i),
}; if (returnAll) {
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs, {}); responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs);
responseData = responseData.splice(0, qs.limit); } else {
qs.limit = this.getNodeParameter('limit', i);
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs);
responseData = responseData.splice(0, qs.limit);
}
return responseData; return responseData;
} }

View file

@ -1,264 +1,306 @@
import { import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
export const submissionOperations = [ export const postOperations = [
{ {
displayName: 'Operation', displayName: 'Operation',
name: 'operation', name: 'operation',
type: 'options', type: 'options',
default: 'post', default: 'create',
description: 'Operation to perform', description: 'Operation to perform',
options: [ options: [
{ {
name: 'Post', name: 'Create',
value: 'post', value: 'create',
description: 'Post a submission to a subreddit', },
}, {
{ name: 'Get All',
name: 'Comment', value: 'getAll',
value: 'comment', },
description: 'Comment on a submission in a subreddit', ],
}, displayOptions: {
{ show: {
name: 'Search', resource: [
value: 'search', 'post',
description: 'Search for a submission in a subreddit', ],
}, },
], },
displayOptions: { },
show: { ] as INodeProperties[];
resource: [
'submission', export const postFields = [
], // ----------------------------------
}, // post: create
}, // ----------------------------------
}, {
] as INodeProperties[]; displayName: 'Subreddit',
name: 'subreddit',
export const submissionFields = [ type: 'string',
// ---------------------------------- required: true,
// post submission default: '',
// ---------------------------------- description: 'Subreddit to create the post in',
{ displayOptions: {
displayName: 'Title', show: {
name: 'title', resource: [
type: 'string', 'post',
required: true, ],
default: '', operation: [
description: 'Title of the submission, up to 300 characters long', 'create',
displayOptions: { ],
show: { },
resource: [ },
'submission', },
], {
operation: [ displayName: 'Kind',
'post', name: 'kind',
], type: 'options',
}, options: [
}, {
}, name: 'Text Post',
{ value: 'self',
displayName: 'Subreddit', },
name: 'subreddit', {
type: 'string', name: 'Link Post',
required: true, value: 'link',
default: '', },
description: 'Subreddit to post the submission to', {
displayOptions: { name: 'Image Post',
show: { value: 'image',
resource: [ },
'submission', {
], name: 'Video Post',
operation: [ value: 'video',
'post', },
], {
}, name: 'Video GIF Post',
}, value: 'videogif',
}, },
{ ],
displayName: 'Kind', default: 'self',
name: 'kind', description: 'The kind of the post to create',
type: 'options', displayOptions: {
options: [ show: {
{ resource: [
name: 'Text Post', 'post',
value: 'self', ],
}, operation: [
{ 'create',
name: 'Link Post', ],
value: 'link', },
}, },
{ },
name: 'Image Post', {
value: 'image', displayName: 'Title',
}, name: 'title',
{ type: 'string',
name: 'Video Post', required: true,
value: 'video', default: '',
}, description: 'Title of the post, up to 300 characters long',
{ displayOptions: {
name: 'Video GIF Post', show: {
value: 'videogif', resource: [
}, 'post',
], ],
default: 'self', operation: [
description: 'The kind of the submission to be posted', 'create',
displayOptions: { ],
show: { },
resource: [ },
'submission', },
], {
operation: [ displayName: 'URL',
'post', name: 'url',
], type: 'string',
}, required: true,
}, default: '',
}, description: 'URL of the post',
{ displayOptions: {
displayName: 'URL', show: {
name: 'url', resource: [
type: 'string', 'post',
required: true, ],
default: '', operation: [
description: 'URL of the content of the submission', 'create',
displayOptions: { ],
show: { kind: [
resource: [ 'link',
'submission', 'image',
], 'video',
operation: [ 'videogif',
'post', ],
], },
kind: [ },
'link', },
'image', {
'video', displayName: 'Text',
'videogif', name: 'text',
], type: 'string',
}, required: true,
}, default: '',
}, description: 'Text of the post (Markdown supported)',
{ displayOptions: {
displayName: 'Text', show: {
name: 'text', resource: [
type: 'string', 'post',
required: true, ],
default: '', operation: [
description: 'Text content of the submission (Markdown supported)', 'create',
displayOptions: { ],
show: { kind: [
resource: [ 'self',
'submission', ],
], },
operation: [ },
'post', },
], {
kind: [ displayName: 'Resubmit',
'self', name: 'resubmit',
], type: 'boolean',
}, default: false,
}, description: 'If toggled on, the URL will be posted even if<br>it was already posted to the subreddit before.<br>Otherwise, the re-posting will trigger an error.',
}, displayOptions: {
{ show: {
displayName: 'Resubmit', resource: [
name: 'resubmit', 'post',
type: 'boolean', ],
default: false, operation: [
description: 'If toggled on, the URL will be submitted even if<br>it was already submitted to the subreddit before.<br>Otherwise, a resubmission will trigger an error.', 'create',
displayOptions: { ],
show: { kind: [
resource: [ 'link',
'submission', 'image',
], 'video',
operation: [ 'videogif',
'post', ],
], },
kind: [ },
'link', },
'image', // ----------------------------------
'video', // post: getAll
'videogif', // ----------------------------------
], {
}, displayName: 'Best',
}, name: 'best',
}, type: 'boolean',
// ---------------------------------- default: false,
// comment on submission description: 'Best posts in all of Reddit',
// ---------------------------------- displayOptions: {
{ show: {
displayName: 'Target', resource: [
name: 'target', 'post',
type: 'string', ],
default: '', operation: [
description: 'ID of the target of the comment. The target can be either<br>the top-level submission or a reply in that submission.', 'getAll',
placeholder: 't3_15bfi0', ],
displayOptions: { },
show: { },
resource: [ },
'submission', {
], displayName: 'Subreddit',
operation: [ name: 'subreddit',
'comment', type: 'string',
], required: true,
}, default: '',
}, description: 'The name of subreddit to retrieve the posts from',
}, displayOptions: {
{ show: {
displayName: 'Text', resource: [
name: 'text', 'post',
type: 'string', ],
required: true, operation: [
default: '', 'getAll',
description: 'Text content of the comment (Markdown supported)', ],
displayOptions: { best: [
show: { false,
resource: [ ],
'submission', },
], },
operation: [ },
'comment', {
], displayName: 'Content',
}, name: 'content',
}, type: 'options',
}, required: true,
// ---------------------------------- default: 'top',
// search for submission description: 'Content of posts to retrieve',
// ---------------------------------- options: [
{ {
displayName: 'Subreddit', name: 'Top Posts',
name: 'subreddit', value: 'top',
type: 'string', },
required: true, {
default: '', name: 'Hot Posts',
description: 'Subreddit to search for posts', value: 'hot',
displayOptions: { },
show: { {
resource: [ name: 'New Posts',
'submission', value: 'new',
], },
operation: [ {
'search', name: 'Rising Posts',
], value: 'rising',
}, },
}, ],
}, displayOptions: {
{ show: {
displayName: 'Keyword', resource: [
name: 'keyword', 'post',
type: 'string', ],
required: true, operation: [
default: '', 'getAll',
description: 'The keyword for the subreddit post search', ],
displayOptions: { best: [
show: { false,
resource: [ ],
'submission', },
], },
operation: [ },
'search', {
], displayName: 'Return All',
}, name: 'returnAll',
}, type: 'boolean',
}, default: false,
] as INodeProperties[]; description: 'Return all results',
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'getAll',
],
best: [
false,
],
},
},
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 5,
description: 'The number of results to return',
typeOptions: {
minValue: 1,
maxValue: 100,
},
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'getAll',
],
returnAll: [
false,
],
best: [
false,
],
},
},
},
] as INodeProperties[];

View file

@ -2,7 +2,7 @@ import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
export const myAccountOperations = [ export const profileOperations = [
{ {
displayName: 'Operation', displayName: 'Operation',
name: 'operation', name: 'operation',
@ -10,7 +10,7 @@ export const myAccountOperations = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'myAccount', 'profile',
], ],
}, },
}, },
@ -26,7 +26,7 @@ export const myAccountOperations = [
] as INodeProperties[]; ] as INodeProperties[];
export const myAccountFields = [ export const profileFields = [
{ {
displayName: 'Details', displayName: 'Details',
name: 'details', name: 'details',
@ -69,7 +69,7 @@ export const myAccountFields = [
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'myAccount', 'profile',
], ],
operation: [ operation: [
'get', 'get',

View file

@ -15,19 +15,19 @@ import {
} from './GenericFunctions'; } from './GenericFunctions';
import { import {
allRedditFields, commentFields,
allRedditOperations, commentOperations,
} from './AllRedditDescription'; } from './CommentDescription';
import { import {
myAccountFields, postFields,
myAccountOperations, postOperations,
} from './MyAccountDescription'; } from './PostDescription';
import { import {
submissionFields, profileFields,
submissionOperations, profileOperations,
} from './SubmissionDescription'; } from './ProfileDescription';
import { import {
subredditFields, subredditFields,
@ -61,13 +61,9 @@ export class Reddit implements INodeType {
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'myAccount', 'profile',
'submission', 'comment',
], 'post',
},
hide: {
operation: [
'search',
], ],
}, },
}, },
@ -80,16 +76,16 @@ export class Reddit implements INodeType {
type: 'options', type: 'options',
options: [ options: [
{ {
name: 'All Reddit', name: 'Comment',
value: 'allReddit', value: 'comment',
}, },
{ {
name: 'My Account', name: 'Post',
value: 'myAccount', value: 'post',
}, },
{ {
name: 'Submission', name: 'Profile',
value: 'submission', value: 'profile',
}, },
{ {
name: 'Subreddit', name: 'Subreddit',
@ -100,27 +96,17 @@ export class Reddit implements INodeType {
value: 'user', value: 'user',
}, },
], ],
default: 'myAccount', default: 'comment',
description: 'Resource to consume', description: 'Resource to consume',
}, },
...commentOperations,
// allReddit ...commentFields,
...allRedditOperations, ...profileOperations,
...allRedditFields, ...profileFields,
// myAccount
...myAccountOperations,
...myAccountFields,
// submission
...submissionOperations,
...submissionFields,
// subreddit
...subredditOperations, ...subredditOperations,
...subredditFields, ...subredditFields,
...postOperations,
// user ...postFields,
...userOperations, ...userOperations,
...userFields, ...userFields,
], ],
@ -137,62 +123,90 @@ export class Reddit implements INodeType {
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
if (resource === 'allReddit') { if (resource === 'comment') {
// ---------------------------------- // ----------------------------------
// allReddit: get // comment: create
// ----------------------------------
const qs: IDataObject = {
thing_id: this.getNodeParameter('target', i),
text: this.getNodeParameter('text', i),
};
responseData = await redditApiRequest.call(this, 'POST', 'api/comment', qs);
} else if (resource === 'profile') {
// ----------------------------------
// profile: get
// ---------------------------------- // ----------------------------------
if (operation === 'get') { if (operation === 'get') {
const information = this.getNodeParameter('information', i) as string; const endpoints: {[key: string]: string} = {
identity: 'me',
blockedUsers: 'me/blocked',
friends: 'me/friends',
karma: 'me/karma',
prefs: 'me/prefs',
trophies: 'me/trophies',
};
if (information === 'trending') { const details = this.getNodeParameter('details', i) as string;
const endpoint = `api/v1/${endpoints[details]}`;
const endpoint = 'api/trending_subreddits.json'; responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
responseData = await redditApiRequest.call(this, 'GET', endpoint, {}, {});
} else {
const endpoint = 'best.json';
responseData = await handleListing.call(this, i, endpoint);
if (details === 'identity') {
responseData = responseData.features;
} }
} }
} else if (resource === 'myAccount') { } else if (resource === 'subreddit') {
// ---------------------------------- // ----------------------------------
// myAccount: get // subreddit: get
// ---------------------------------- // ----------------------------------
if (operation === 'get') { if (operation === 'get') {
const endpoints: {[key: string]: string} = { const qs: IDataObject = {};
identity: 'me',
blockedUsers: 'me/blocked',
friends: 'me/friends',
karma: 'me/karma',
prefs: 'me/prefs',
trophies: 'me/trophies',
};
const details = this.getNodeParameter('details', i) as string; const subreddit = this.getNodeParameter('subreddit', i);
responseData = await redditApiRequest.call(this, 'GET', `api/v1/${endpoints[details]}`, {}, {}); const content = this.getNodeParameter('content', i) as string;
const endpoint = `r/${subreddit}/about/${content}.json`;
if (details === 'identity') { responseData = await redditApiRequest.call(this, 'GET', endpoint, qs);
responseData = responseData.features;
if (content === 'rules') {
responseData = responseData.rules;
} }
// ----------------------------------
// subreddit: getAll
// ----------------------------------
} else if (operation === 'getAll') {
const trending = this.getNodeParameter('trending', i) as IDataObject;
if (trending) {
const endpoint = 'api/trending_subreddits.json';
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
} else {
const endpoint = 'api/search_reddit_names.json';
responseData = await handleListing.call(this, i, endpoint);
}
} }
} else if (resource === 'submission') { } else if (resource === 'post') {
// ---------------------------------- // ----------------------------------
// submission: post // post: create
// ---------------------------------- // ----------------------------------
if (operation === 'post') { if (operation === 'create') {
const qs: IDataObject = { const qs: IDataObject = {
title: this.getNodeParameter('title', i), title: this.getNodeParameter('title', i),
@ -208,73 +222,21 @@ export class Reddit implements INodeType {
qs.resubmit = this.getNodeParameter('resubmit', i); qs.resubmit = this.getNodeParameter('resubmit', i);
} }
responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs, {}); responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs);
// ----------------------------------
// submission: comment
// ----------------------------------
} else if (operation === 'comment') {
const qs: IDataObject = {
thing_id: this.getNodeParameter('target', i),
text: this.getNodeParameter('text', i),
};
responseData = await redditApiRequest.call(this, 'POST', 'api/comment', qs, {});
} else if (operation === 'search') {
const subreddit = this.getNodeParameter('subreddit', i);
const qs: IDataObject = {
q: this.getNodeParameter('keyword', i),
restrict_sr: 'on',
};
const endpoint = `r/${subreddit}/search.json`;
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
} }
} else if (resource === 'subreddit') { // ----------------------------------
// post: getAll
// ----------------------------------
// ---------------------------------- else if (operation === 'getAll') {
// subreddit: get
// ----------------------------------
if (operation === 'get') {
const qs: IDataObject = {};
const content = this.getNodeParameter('content', i) as string;
const subreddit = this.getNodeParameter('subreddit', i); const subreddit = this.getNodeParameter('subreddit', i);
const content = this.getNodeParameter('content', i);
const endpoint = `r/${subreddit}/${content}.json`;
if (['about', 'rules', 'sidebar', 'sticky'].includes(content)) { responseData = await handleListing.call(this, i, endpoint);
const endpoint = `r/${subreddit}/about/${content}.json`;
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
if (content === 'rules') {
responseData = responseData.rules;
}
} else if (['top', 'hot', 'new', 'rising'].includes(content)) {
const endpoint = `r/${subreddit}/${content}.json`;
responseData = await handleListing.call(this, i, endpoint);
}
} else if (operation === 'search') {
const endpoint = `api/search_reddit_names.json`;
const qs: IDataObject = {
query: this.getNodeParameter('keyword', i),
};
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
} }
@ -291,7 +253,7 @@ export class Reddit implements INodeType {
const endpoint = `user/${username}/${details}.json`; const endpoint = `user/${username}/${details}.json`;
responseData = ['about', 'gilded'].includes(details) responseData = ['about', 'gilded'].includes(details)
? await redditApiRequest.call(this, 'GET', endpoint, {}, {}) ? await redditApiRequest.call(this, 'GET', endpoint, {})
: await handleListing.call(this, i, endpoint); : await handleListing.call(this, i, endpoint);
} }

View file

@ -15,8 +15,8 @@ export const subredditOperations = [
value: 'get', value: 'get',
}, },
{ {
name: 'Search', name: 'Get All',
value: 'search', value: 'getAll',
}, },
], ],
displayOptions: { displayOptions: {
@ -31,7 +31,7 @@ export const subredditOperations = [
export const subredditFields = [ export const subredditFields = [
// ---------------------------------- // ----------------------------------
// get: subreddit // subreddit: get
// ---------------------------------- // ----------------------------------
{ {
displayName: 'Content', displayName: 'Content',
@ -57,22 +57,6 @@ export const subredditFields = [
name: 'Sticky Posts', name: 'Sticky Posts',
value: 'sticky', value: 'sticky',
}, },
{
name: 'Top Posts',
value: 'top',
},
{
name: 'Hot Posts',
value: 'hot',
},
{
name: 'New Posts',
value: 'new',
},
{
name: 'Rising Posts',
value: 'rising',
},
], ],
displayOptions: { displayOptions: {
show: { show: {
@ -117,12 +101,6 @@ export const subredditFields = [
operation: [ operation: [
'get', 'get',
], ],
content: [
'top',
'hot',
'new',
'rising',
],
}, },
}, },
}, },
@ -144,12 +122,6 @@ export const subredditFields = [
operation: [ operation: [
'get', 'get',
], ],
content: [
'top',
'hot',
'new',
'rising',
],
returnAll: [ returnAll: [
false, false,
], ],
@ -157,22 +129,21 @@ export const subredditFields = [
}, },
}, },
// ---------------------------------- // ----------------------------------
// search: subreddit // subreddit: getAll
// ---------------------------------- // ----------------------------------
{ {
displayName: 'Keyword', displayName: 'Trending',
name: 'keyword', name: 'trending',
type: 'string', type: 'boolean',
required: true, default: false,
default: '', description: 'Currently trending subreddits in all of Reddit',
description: 'The keyword for the subreddit name search',
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'subreddit', 'subreddit',
], ],
operation: [ operation: [
'search', 'getAll',
], ],
}, },
}, },
@ -189,7 +160,10 @@ export const subredditFields = [
'subreddit', 'subreddit',
], ],
operation: [ operation: [
'search', 'getAll',
],
trending: [
false,
], ],
}, },
}, },
@ -210,11 +184,43 @@ export const subredditFields = [
'subreddit', 'subreddit',
], ],
operation: [ operation: [
'search', 'getAll',
], ],
returnAll: [ returnAll: [
false, false,
], ],
trending: [
false,
],
},
},
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Field',
default: {},
options: [
{
displayName: 'Query',
name: 'query',
type: 'string',
default: '',
description: 'The term for the subreddit name search',
},
],
displayOptions: {
show: {
resource: [
'subreddit',
],
operation: [
'getAll',
],
trending: [
false,
],
}, },
}, },
}, },