From ccca927d708481c2e6ab007491c76f02892685b9 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Fri, 4 Jun 2021 19:15:03 -0400 Subject: [PATCH] :sparkles: Add "Get Following Artists" on Spotify node (#1823) * Add follow resource * :zap: Improvements to #1812 * :zap: Minor improvements Co-authored-by: Sam Roquitte Co-authored-by: Jan Oberhauser --- .../SpotifyOAuth2Api.credentials.ts | 2 +- .../nodes-base/nodes/Spotify/Spotify.node.ts | 80 ++++++++++++++++--- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/packages/nodes-base/credentials/SpotifyOAuth2Api.credentials.ts b/packages/nodes-base/credentials/SpotifyOAuth2Api.credentials.ts index d2fc2c9054..43d71aa794 100644 --- a/packages/nodes-base/credentials/SpotifyOAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/SpotifyOAuth2Api.credentials.ts @@ -36,7 +36,7 @@ export class SpotifyOAuth2Api implements ICredentialType { displayName: 'Scope', name: 'scope', type: 'hidden' as NodePropertyTypes, - default: 'user-read-playback-state playlist-read-collaborative user-modify-playback-state playlist-modify-public user-read-currently-playing playlist-read-private user-read-recently-played playlist-modify-private user-library-read', + default: 'user-read-playback-state playlist-read-collaborative user-modify-playback-state playlist-modify-public user-read-currently-playing playlist-read-private user-read-recently-played playlist-modify-private user-library-read user-follow-read', }, { displayName: 'Auth URI Query Parameters', diff --git a/packages/nodes-base/nodes/Spotify/Spotify.node.ts b/packages/nodes-base/nodes/Spotify/Spotify.node.ts index 696e1fff33..972c321b49 100644 --- a/packages/nodes-base/nodes/Spotify/Spotify.node.ts +++ b/packages/nodes-base/nodes/Spotify/Spotify.node.ts @@ -40,10 +40,10 @@ export class Spotify implements INodeType { }, ], properties: [ - // ---------------------------------------------------------- + // ---------------------------------------------------------------- // Resource to Operate on - // Player, Album, Artisits, Playlists, Tracks - // ---------------------------------------------------------- + // Album, Artist, Library, My Data, Player, Playlist, Track + // ---------------------------------------------------------------- { displayName: 'Resource', name: 'resource', @@ -61,6 +61,10 @@ export class Spotify implements INodeType { name: 'Library', value: 'library', }, + { + name: 'My Data', + value: 'myData', + }, { name: 'Player', value: 'player', @@ -77,9 +81,10 @@ export class Spotify implements INodeType { default: 'player', description: 'The resource to operate on.', }, + // -------------------------------------------------------------------------------------------------------- // Player Operations - // Pause, Play, Get Recently Played, Get Currently Playing, Next Song, Previous Song, Add to Queue + // Pause, Play, Get Recently Played, Get Currently Playing, Next Song, Previous Song, Add to Queue // -------------------------------------------------------------------------------------------------------- { displayName: 'Operation', @@ -170,9 +175,10 @@ export class Spotify implements INodeType { placeholder: 'spotify:track:0xE4LEFzSNGsz1F6kvXsHU', description: `Enter a track URI or ID.`, }, + // ----------------------------------------------- // Album Operations - // Get an Album, Get an Album's Tracks + // Get an Album, Get an Album's Tracks // ----------------------------------------------- { displayName: 'Operation', @@ -225,9 +231,10 @@ export class Spotify implements INodeType { placeholder: 'spotify:album:1YZ3k65Mqw3G8FzYlW1mmp', description: `The album's Spotify URI or ID.`, }, + // ------------------------------------------------------------------------------------------------------------- // Artist Operations - // Get an Artist, Get an Artist's Related Artists, Get an Artist's Top Tracks, Get an Artist's Albums + // Get an Artist, Get an Artist's Related Artists, Get an Artist's Top Tracks, Get an Artist's Albums // ------------------------------------------------------------------------------------------------------------- { displayName: 'Operation', @@ -300,9 +307,10 @@ export class Spotify implements INodeType { placeholder: 'US', description: `Top tracks in which country? Enter the postal abbriviation.`, }, + // ------------------------------------------------------------------------------------------------------------- // Playlist Operations - // Get a Playlist, Get a Playlist's Tracks, Add/Remove a Song from a Playlist, Get a User's Playlists + // Get a Playlist, Get a Playlist's Tracks, Add/Remove a Song from a Playlist, Get a User's Playlists // ------------------------------------------------------------------------------------------------------------- { displayName: 'Operation', @@ -478,7 +486,7 @@ export class Spotify implements INodeType { // ----------------------------------------------------- // Track Operations - // Get a Track, Get a Track's Audio Features + // Get a Track, Get a Track's Audio Features // ----------------------------------------------------- { displayName: 'Operation', @@ -522,10 +530,11 @@ export class Spotify implements INodeType { placeholder: 'spotify:track:0xE4LEFzSNGsz1F6kvXsHU', description: `The track's Spotify URI or ID.`, }, - // -------------------------------------------------------------------------------------------------------- + + // ----------------------------------------------------- // Library Operations - // Get liked tracks - // -------------------------------------------------------------------------------------------------------- + // Get liked tracks + // ----------------------------------------------------- { displayName: 'Operation', name: 'operation', @@ -546,6 +555,32 @@ export class Spotify implements INodeType { ], default: 'getLikedTracks', }, + + // --------------------------------------- + // My Data Operations + // Get Followed Artists + // --------------------------------------- + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'myData', + ], + }, + }, + options: [ + { + name: 'Get Following Artists', + value: 'getFollowingArtists', + description: 'Get your followed artists.', + }, + ], + default: 'getFollowingArtists', + description: 'The operation to perform.', + }, { displayName: 'Return All', name: 'returnAll', @@ -558,6 +593,7 @@ export class Spotify implements INodeType { 'album', 'artist', 'library', + 'myData', 'playlist', ], operation: [ @@ -566,6 +602,7 @@ export class Spotify implements INodeType { 'getUserPlaylists', 'getNewReleases', 'getLikedTracks', + 'getFollowingArtists', ], }, }, @@ -612,9 +649,11 @@ export class Spotify implements INodeType { displayOptions: { show: { resource: [ + 'myData', 'player', ], operation: [ + 'getFollowingArtists', 'recentlyPlayed', ], }, @@ -1046,6 +1085,25 @@ export class Spotify implements INodeType { responseData = responseData.items; } } + } else if (resource === 'myData') { + + if (operation === 'getFollowingArtists') { + requestMethod = 'GET'; + + endpoint = `/me/following`; + + propertyName = 'artists.items'; + + if (!returnAll) { + const limit = this.getNodeParameter('limit', i) as number; + qs = { + type: 'artist', + limit, + }; + responseData = await spotifyApiRequest.call(this, requestMethod, endpoint, body, qs); + responseData = responseData.artists.items; + } + } } if (returnAll) {