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