From cbbeb0f469ffd1da901b8cd02ede686e4fd7f007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Sun, 17 Jan 2021 15:11:03 -0300 Subject: [PATCH] Refactor My Account resource into details --- .../nodes/Reddit/MyAccountDescription.ts | 87 ++++++++++++------- .../nodes-base/nodes/Reddit/Reddit.node.ts | 26 +++--- 2 files changed, 73 insertions(+), 40 deletions(-) diff --git a/packages/nodes-base/nodes/Reddit/MyAccountDescription.ts b/packages/nodes-base/nodes/Reddit/MyAccountDescription.ts index 02347dc0ae..bcafb43203 100644 --- a/packages/nodes-base/nodes/Reddit/MyAccountDescription.ts +++ b/packages/nodes-base/nodes/Reddit/MyAccountDescription.ts @@ -16,37 +16,66 @@ export const myAccountOperations = [ }, options: [ { - name: 'Get identity', - value: 'getIdentity', - description: 'Return the identity of the logged-in user', - }, - { - name: 'Get blocked users', - value: 'getBlockedUsers', - description: 'Return the identity of the logged-in user', - }, - { - name: 'Get friends', - value: 'getFriends', - description: 'Return a list of friends for the logged-in user', - }, - { - name: 'Get karma', - value: 'getKarma', - description: 'Return a breakdown of subreddit karma', - }, - { - name: 'Get preferences', - value: 'getPrefs', - description: 'Return the preference settings of the logged-in user', - }, - { - name: 'Get trophies', - value: 'getTrophies', - description: 'Return a list of trophies for the logged-in user', + name: 'Get', + value: 'get', }, ], - default: 'getIdentity', + default: 'get', description: 'Operation to perform', }, ] as INodeProperties[]; + + +export const myAccountFields = [ + { + displayName: 'Details', + name: 'details', + type: 'options', + required: true, + default: 'identity', + description: 'Details of my account to retrieve', + options: [ + { + name: 'Identity', + value: 'identity', + description: 'Return the identity of the logged-in user', + }, + { + name: 'Blocked users', + value: 'blockedUsers', + description: 'Return the blocked users of the logged-in user', + }, + { + name: 'Friends', + value: 'friends', + description: 'Return the friends of the logged-in user', + }, + { + name: 'Karma', + value: 'karma', + description: 'Return the subreddit karma for the logged-in user', + }, + { + name: 'preferences', + value: 'prefs', + description: 'Return the settings preferences of the logged-in user', + }, + { + name: 'Trophies', + value: 'trophies', + description: 'Return the trophies of the logged-in user', + }, + ], + displayOptions: { + show: { + resource: [ + 'myAccount', + ], + operation: [ + 'get', + ], + }, + }, + }, + +] as INodeProperties[]; \ No newline at end of file diff --git a/packages/nodes-base/nodes/Reddit/Reddit.node.ts b/packages/nodes-base/nodes/Reddit/Reddit.node.ts index 97b16287bd..52df8c5d8d 100644 --- a/packages/nodes-base/nodes/Reddit/Reddit.node.ts +++ b/packages/nodes-base/nodes/Reddit/Reddit.node.ts @@ -15,6 +15,7 @@ import { } from './GenericFunctions'; import { + myAccountFields, myAccountOperations, } from './MyAccountDescription'; @@ -78,6 +79,7 @@ export class Reddit implements INodeType { // myAccount ...myAccountOperations, + ...myAccountFields, // submission ...submissionOperations, @@ -102,22 +104,24 @@ export class Reddit implements INodeType { if (resource === 'myAccount') { - if (operation === 'getIdentity') { + if (operation === 'get') { - responseData = await redditApiRequest.call(this, 'GET', 'me'); - responseData = responseData.features; - - } else { + const details = this.getNodeParameter('details', i) as string; const endpoints: {[key: string]: string} = { - getBlockedUsers: 'blocked', - getFriends: 'friends', - getKarma: 'karma', - getPrefs: 'prefs', - getTrophies: 'trophies', + identity: 'me', + blockedUsers: 'me/blocked', + friends: 'me/friends', + karma: 'me/karma', + prefs: 'me/prefs', + trophies: 'me/trophies', }; - responseData = await redditApiRequest.call(this, 'GET', `me/${endpoints[operation]}`); + responseData = await redditApiRequest.call(this, 'GET', endpoints[details]); + + if (details === 'identity') { + responseData = responseData.features; + } }