Enrich subreddit search by keyword operation

This commit is contained in:
Iván Ovejero 2021-01-29 12:49:10 -03:00
parent 383df300da
commit a557c947ed
3 changed files with 13 additions and 10 deletions

View file

@ -75,8 +75,8 @@ export async function redditApiRequestAllItems(
console.log(responseData);
qs.after = responseData.after;
if (endpoint === 'api/search_reddit_names.json') {
responseData.names.forEach((name: IDataObject) => returnData.push(name));
if (endpoint === 'api/search_subreddits.json') {
responseData.subreddits.forEach((child: any) => returnData.push(child)); // tslint:disable-line:no-any
} else {
responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
}
@ -106,20 +106,23 @@ export async function handleListing(
const qs: IDataObject = {};
let requestMethod = 'GET';
if (resource === 'subreddit' && operation === 'getAll') {
const filters = this.getNodeParameter('filters', i) as IDataObject;
if (filters.query) {
qs.query = filters.query;
if (filters.keyword) {
qs.query = filters.keyword;
}
requestMethod = 'POST';
}
const returnAll = this.getNodeParameter('returnAll', i);
if (returnAll) {
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs);
responseData = await redditApiRequestAllItems.call(this, requestMethod, endpoint, qs);
} else {
qs.limit = this.getNodeParameter('limit', i);
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs);
responseData = await redditApiRequestAllItems.call(this, requestMethod, endpoint, qs);
responseData = responseData.splice(0, qs.limit);
}

View file

@ -211,7 +211,7 @@ export class Reddit implements INodeType {
const endpoint = 'api/trending_subreddits.json';
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
} else {
const endpoint = 'api/search_reddit_names.json';
const endpoint = 'api/search_subreddits.json';
responseData = await handleListing.call(this, i, endpoint);
}
}

View file

@ -158,11 +158,11 @@ export const subredditFields = [
default: {},
options: [
{
displayName: 'Query',
name: 'query',
displayName: 'Keyword',
name: 'keyword',
type: 'string',
default: '',
description: 'The term for the subreddit name search',
description: 'The keyword for the subreddit search.',
},
],
displayOptions: {