Refactor My Account resource into details

This commit is contained in:
Iván Ovejero 2021-01-17 15:11:03 -03:00
parent 13ad0b84fb
commit cbbeb0f469
2 changed files with 73 additions and 40 deletions

View file

@ -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[];

View file

@ -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;
}
}