mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
Refactor subreddit:getAll
This commit is contained in:
parent
2918e01c18
commit
19d11664e6
|
@ -8,13 +8,9 @@ const scopes = [
|
|||
'edit',
|
||||
'history',
|
||||
'mysubreddits',
|
||||
'privatemessages',
|
||||
'read',
|
||||
'report',
|
||||
'save',
|
||||
'submit',
|
||||
'subscribe',
|
||||
'vote',
|
||||
];
|
||||
|
||||
// https://github.com/reddit-archive/reddit/wiki/OAuth2
|
||||
|
|
|
@ -98,25 +98,12 @@ export async function handleListing(
|
|||
this: IExecuteFunctions,
|
||||
i: number,
|
||||
endpoint: string,
|
||||
qs: IDataObject = {},
|
||||
requestMethod: 'GET' | 'POST' = 'GET',
|
||||
): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
let responseData;
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
const qs: IDataObject = {};
|
||||
|
||||
let requestMethod = 'GET';
|
||||
|
||||
if (resource === 'subreddit' && operation === 'getAll') {
|
||||
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||
if (filters.keyword) {
|
||||
qs.query = filters.keyword;
|
||||
}
|
||||
requestMethod = 'POST';
|
||||
}
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (returnAll) {
|
||||
|
|
|
@ -75,10 +75,6 @@ export class Reddit implements INodeType {
|
|||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Comment',
|
||||
value: 'comment',
|
||||
},
|
||||
{
|
||||
name: 'Post',
|
||||
value: 'post',
|
||||
|
@ -274,7 +270,6 @@ export class Reddit implements INodeType {
|
|||
|
||||
}
|
||||
|
||||
|
||||
// *********************************************************************
|
||||
// profile
|
||||
// *********************************************************************
|
||||
|
@ -350,14 +345,27 @@ export class Reddit implements INodeType {
|
|||
|
||||
// https://www.reddit.com/dev/api/#GET_api_trending_subreddits
|
||||
// https://www.reddit.com/dev/api/#POST_api_search_subreddits
|
||||
// https://www.reddit.com/r/subreddits.json
|
||||
|
||||
const trending = this.getNodeParameter('trending', i) as IDataObject;
|
||||
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||
|
||||
if (filters.trending) {
|
||||
|
||||
if (trending) {
|
||||
const endpoint = 'api/trending_subreddits.json';
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
|
||||
} else {
|
||||
responseData = responseData.subreddit_names.map((name: string) => ({ name }));
|
||||
|
||||
} else if (filters.keyword) {
|
||||
|
||||
const qs: IDataObject = {};
|
||||
const endpoint = 'api/search_subreddits.json';
|
||||
qs.query = filters.keyword;
|
||||
|
||||
responseData = await handleListing.call(this, i, endpoint, qs, 'POST');
|
||||
|
||||
} else {
|
||||
|
||||
const endpoint = 'r/subreddits.json';
|
||||
responseData = await handleListing.call(this, i, endpoint);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,12 @@ export const subredditOperations = [
|
|||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Retrieve background information about a subreddit.',
|
||||
},
|
||||
{
|
||||
name: 'Get All',
|
||||
value: 'getAll',
|
||||
description: 'Retrieve information about subreddits from all of Reddit.',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
|
@ -86,23 +88,6 @@ export const subredditFields = [
|
|||
// ----------------------------------
|
||||
// subreddit: getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Trending',
|
||||
name: 'trending',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Currently trending subreddits in all of Reddit.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'subreddit',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
|
@ -117,9 +102,6 @@ export const subredditFields = [
|
|||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
trending: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -144,9 +126,6 @@ export const subredditFields = [
|
|||
returnAll: [
|
||||
false,
|
||||
],
|
||||
trending: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -164,6 +143,13 @@ export const subredditFields = [
|
|||
default: '',
|
||||
description: 'The keyword for the subreddit search.',
|
||||
},
|
||||
{
|
||||
displayName: 'Trending',
|
||||
name: 'trending',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Currently trending subreddits in all of Reddit.',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
|
@ -173,9 +159,6 @@ export const subredditFields = [
|
|||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
trending: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue