mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Enrich subreddit search by keyword operation
This commit is contained in:
parent
383df300da
commit
a557c947ed
|
@ -75,8 +75,8 @@ export async function redditApiRequestAllItems(
|
||||||
console.log(responseData);
|
console.log(responseData);
|
||||||
qs.after = responseData.after;
|
qs.after = responseData.after;
|
||||||
|
|
||||||
if (endpoint === 'api/search_reddit_names.json') {
|
if (endpoint === 'api/search_subreddits.json') {
|
||||||
responseData.names.forEach((name: IDataObject) => returnData.push(name));
|
responseData.subreddits.forEach((child: any) => returnData.push(child)); // tslint:disable-line:no-any
|
||||||
} else {
|
} else {
|
||||||
responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
|
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 = {};
|
const qs: IDataObject = {};
|
||||||
|
|
||||||
|
let requestMethod = 'GET';
|
||||||
|
|
||||||
if (resource === 'subreddit' && operation === 'getAll') {
|
if (resource === 'subreddit' && operation === 'getAll') {
|
||||||
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||||
if (filters.query) {
|
if (filters.keyword) {
|
||||||
qs.query = filters.query;
|
qs.query = filters.keyword;
|
||||||
}
|
}
|
||||||
|
requestMethod = 'POST';
|
||||||
}
|
}
|
||||||
|
|
||||||
const returnAll = this.getNodeParameter('returnAll', i);
|
const returnAll = this.getNodeParameter('returnAll', i);
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs);
|
responseData = await redditApiRequestAllItems.call(this, requestMethod, endpoint, qs);
|
||||||
} else {
|
} else {
|
||||||
qs.limit = this.getNodeParameter('limit', i);
|
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);
|
responseData = responseData.splice(0, qs.limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ export class Reddit implements INodeType {
|
||||||
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 {
|
} else {
|
||||||
const endpoint = 'api/search_reddit_names.json';
|
const endpoint = 'api/search_subreddits.json';
|
||||||
responseData = await handleListing.call(this, i, endpoint);
|
responseData = await handleListing.call(this, i, endpoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,11 +158,11 @@ export const subredditFields = [
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Query',
|
displayName: 'Keyword',
|
||||||
name: 'query',
|
name: 'keyword',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The term for the subreddit name search',
|
description: 'The keyword for the subreddit search.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
|
|
Loading…
Reference in a new issue