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: [ options: [
{ {
name: 'Get identity', name: 'Get',
value: 'getIdentity', value: 'get',
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',
}, },
], ],
default: 'getIdentity', default: 'get',
description: 'Operation to perform', description: 'Operation to perform',
}, },
] as INodeProperties[]; ] 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'; } from './GenericFunctions';
import { import {
myAccountFields,
myAccountOperations, myAccountOperations,
} from './MyAccountDescription'; } from './MyAccountDescription';
@ -78,6 +79,7 @@ export class Reddit implements INodeType {
// myAccount // myAccount
...myAccountOperations, ...myAccountOperations,
...myAccountFields,
// submission // submission
...submissionOperations, ...submissionOperations,
@ -102,22 +104,24 @@ export class Reddit implements INodeType {
if (resource === 'myAccount') { if (resource === 'myAccount') {
if (operation === 'getIdentity') { if (operation === 'get') {
responseData = await redditApiRequest.call(this, 'GET', 'me'); const details = this.getNodeParameter('details', i) as string;
responseData = responseData.features;
} else {
const endpoints: {[key: string]: string} = { const endpoints: {[key: string]: string} = {
getBlockedUsers: 'blocked', identity: 'me',
getFriends: 'friends', blockedUsers: 'me/blocked',
getKarma: 'karma', friends: 'me/friends',
getPrefs: 'prefs', karma: 'me/karma',
getTrophies: 'trophies', 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;
}
} }