mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Add all operations for postComment resource
This commit is contained in:
parent
c2f43d8122
commit
dc38273fa7
|
@ -23,7 +23,7 @@ export async function redditApiRequest(
|
||||||
): Promise<any> { // tslint:disable-line:no-any
|
): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
const authRequired = ['profile', 'post', 'comment'].includes(resource);
|
const authRequired = ['profile', 'post', 'postComment'].includes(resource);
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -40,6 +40,7 @@ export async function redditApiRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log(options);
|
||||||
return authRequired
|
return authRequired
|
||||||
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
|
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
|
||||||
: await this.helpers.request.call(this, options);
|
: await this.helpers.request.call(this, options);
|
||||||
|
|
|
@ -13,18 +13,22 @@ export const postCommentOperations = [
|
||||||
{
|
{
|
||||||
name: 'Add',
|
name: 'Add',
|
||||||
value: 'add',
|
value: 'add',
|
||||||
|
description: 'Write a top-level comment in a post.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get All',
|
name: 'Get All',
|
||||||
value: 'getAll',
|
value: 'getAll',
|
||||||
|
description: 'Retrieve all comments in a post.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Remove',
|
name: 'Remove',
|
||||||
value: 'remove',
|
value: 'remove',
|
||||||
|
description: 'Remove a comment from a post.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Reply',
|
name: 'Reply',
|
||||||
value: 'reply',
|
value: 'reply',
|
||||||
|
description: 'Write a reply to a comment in a post.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
|
@ -42,12 +46,13 @@ export const postCommentFields = [
|
||||||
// postComment: add
|
// postComment: add
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Target ID',
|
displayName: 'Post ID',
|
||||||
name: 'targetId',
|
name: 'postId',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'ID of the comment target.',
|
description: 'ID of the post to write the comment to. Found in the post URL:<br><code>/r/[subreddit_name]/comments/[post_id]/[post_title]</code>',
|
||||||
placeholder: 't3_15bfi0',
|
placeholder: 'l0me7x',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
|
@ -60,8 +65,8 @@ export const postCommentFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Text',
|
displayName: 'Comment Text',
|
||||||
name: 'text',
|
name: 'commentText',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -77,4 +82,106 @@ export const postCommentFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// ----------------------------------
|
||||||
|
// postComment: getAll
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Subreddit',
|
||||||
|
name: 'subreddit',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'The name of subreddit where the post is.',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'postComment',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Post ID',
|
||||||
|
name: 'postId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'ID of the post to get all comments from. Found in the post URL:<br><code>/r/[subreddit_name]/comments/[post_id]/[post_title]</code>',
|
||||||
|
placeholder: 'l0me7x',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'postComment',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// ----------------------------------
|
||||||
|
// postComment: delete
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Comment ID',
|
||||||
|
name: 'commentId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'ID of the comment to remove. Found in the comment URL:<br><code>/r/[subreddit_name]/comments/[post_id]/[post_title]/[comment_id]</code>',
|
||||||
|
placeholder: 'gla7fmt',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'postComment',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'remove',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// ----------------------------------
|
||||||
|
// postComment: reply
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Comment ID',
|
||||||
|
name: 'commentId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'ID of the comment to reply to. To be found in the comment URL:<br><code>www.reddit.com/r/[subreddit_name]/comments/[post_id]/[post_title]/[comment_id]</code>',
|
||||||
|
placeholder: 'gl9iroa',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'postComment',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'reply',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Reply Text',
|
||||||
|
name: 'replyText',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'Text of the reply. Markdown supported.',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'postComment',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'reply',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -128,7 +128,7 @@ export class Reddit implements INodeType {
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
// post comment
|
// postComment
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
|
|
||||||
if (resource === 'postComment') {
|
if (resource === 'postComment') {
|
||||||
|
@ -139,24 +139,54 @@ export class Reddit implements INodeType {
|
||||||
|
|
||||||
if (operation === 'add') {
|
if (operation === 'add') {
|
||||||
|
|
||||||
|
// https://www.reddit.com/dev/api/#POST_api_comment
|
||||||
|
|
||||||
|
const postTypePrefix = 't3_';
|
||||||
|
|
||||||
const qs: IDataObject = {
|
const qs: IDataObject = {
|
||||||
text: this.getNodeParameter('text', i),
|
text: this.getNodeParameter('commentText', i),
|
||||||
thing_id: this.getNodeParameter('targetId', i),
|
thing_id: postTypePrefix + this.getNodeParameter('postId', i),
|
||||||
};
|
};
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'POST', 'api/comment', qs);
|
responseData = await redditApiRequest.call(this, 'POST', 'api/comment', qs);
|
||||||
|
delete responseData.jquery;
|
||||||
|
|
||||||
} else if (operation === 'getAll') {
|
} else if (operation === 'getAll') {
|
||||||
|
|
||||||
// ...
|
const subreddit = this.getNodeParameter('subreddit', i);
|
||||||
|
const postId = this.getNodeParameter('postId', i) as string;
|
||||||
|
const endpoint = `r/${subreddit}/comments/${postId}.json`;
|
||||||
|
|
||||||
|
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
responseData = responseData[1].data.children.map((child: any) => child.data); // tslint:disable-line:no-any
|
||||||
|
|
||||||
} else if (operation === 'remove') {
|
} else if (operation === 'remove') {
|
||||||
|
|
||||||
// ...
|
// https://www.reddit.com/dev/api/#POST_api_del
|
||||||
|
|
||||||
|
const commentTypePrefix = 't1_';
|
||||||
|
|
||||||
|
const qs: IDataObject = {
|
||||||
|
id: commentTypePrefix + this.getNodeParameter('commentId', i),
|
||||||
|
};
|
||||||
|
|
||||||
|
await redditApiRequest.call(this, 'POST', 'api/del', qs);
|
||||||
|
|
||||||
|
responseData = { success: true };
|
||||||
|
|
||||||
} else if (operation === 'reply') {
|
} else if (operation === 'reply') {
|
||||||
|
|
||||||
// ...
|
// https://www.reddit.com/dev/api/#POST_api_comment
|
||||||
|
|
||||||
|
const commentTypePrefix = 't1_';
|
||||||
|
|
||||||
|
const qs: IDataObject = {
|
||||||
|
text: this.getNodeParameter('replyText', i),
|
||||||
|
thing_id: commentTypePrefix + this.getNodeParameter('commentId', i),
|
||||||
|
};
|
||||||
|
|
||||||
|
responseData = await redditApiRequest.call(this, 'POST', 'api/comment', qs);
|
||||||
|
delete responseData.jquery;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,13 +244,11 @@ export class Reddit implements INodeType {
|
||||||
// https://www.reddit.com/dev/api/#GET_r_{subreddit}_about_rules
|
// https://www.reddit.com/dev/api/#GET_r_{subreddit}_about_rules
|
||||||
// https://www.reddit.com/dev/api/#GET_sticky
|
// https://www.reddit.com/dev/api/#GET_sticky
|
||||||
|
|
||||||
const qs: IDataObject = {};
|
|
||||||
|
|
||||||
const subreddit = this.getNodeParameter('subreddit', i);
|
const subreddit = this.getNodeParameter('subreddit', i);
|
||||||
const content = this.getNodeParameter('content', i) as string;
|
const content = this.getNodeParameter('content', i) as string;
|
||||||
const endpoint = `r/${subreddit}/about/${content}.json`;
|
const endpoint = `r/${subreddit}/about/${content}.json`;
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs);
|
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
|
||||||
if (content === 'rules') {
|
if (content === 'rules') {
|
||||||
responseData = responseData.rules;
|
responseData = responseData.rules;
|
||||||
|
|
Loading…
Reference in a new issue