Add subreddit search functionality

This commit is contained in:
Iván Ovejero 2021-01-17 20:26:04 -03:00
parent 3f810629c4
commit 49001ce789
3 changed files with 78 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import {
import {
OptionsWithUri,
} from 'request';
import { queryString } from '../TheHive/QueryFunctions';
/**
@ -101,7 +102,9 @@ export async function handleListing(
return await redditApiRequestAllItems.call(this, 'GET', endpoint, {}, {}, true);
}
const qs: IDataObject = { limit: this.getNodeParameter('limit', i) };
const qs: IDataObject = {
limit: this.getNodeParameter('limit', i),
};
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs, {}, true);
responseData = responseData.splice(0, qs.limit);

View file

@ -210,6 +210,15 @@ export class Reddit implements INodeType {
}
} 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, {}, true);
}
}

View file

@ -30,6 +30,9 @@ export const subredditOperations = [
] as INodeProperties[];
export const subredditFields = [
// ----------------------------------
// get: subreddit
// ----------------------------------
{
displayName: 'Content',
name: 'content',
@ -153,4 +156,66 @@ export const subredditFields = [
},
},
},
// ----------------------------------
// search: subreddit
// ----------------------------------
{
displayName: 'Keyword',
name: 'keyword',
type: 'string',
required: true,
default: '',
description: 'The keyword for the subreddit name search',
displayOptions: {
show: {
resource: [
'subreddit',
],
operation: [
'search',
],
},
},
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
default: false,
description: 'Return all results',
displayOptions: {
show: {
resource: [
'subreddit',
],
operation: [
'search',
],
},
},
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 5,
description: 'The number of results to return',
typeOptions: {
minValue: 1,
maxValue: 100,
},
displayOptions: {
show: {
resource: [
'subreddit',
],
operation: [
'search',
],
returnAll: [
false,
],
},
},
},
] as INodeProperties[];