Skip to content

Commit e27319f

Browse files
authored
Spotify improvements (#19420)
* Syntax improvements to spotify components * Adjusting default page size to 50 * Fixing search method * Removing remaining lodash calls * Version bumps * Adjusting response formats * Fixing more response formats * Fix * fixing silly validation * Adjusting retry delay * Adjusting request for max 20 albums * Fixing 'get recommendations'
1 parent 4807940 commit e27319f

File tree

30 files changed

+261
-266
lines changed

30 files changed

+261
-266
lines changed

components/factorial_api_keys/factorial_api_keys.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/flowii/flowii.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/hailey_hr/hailey_hr.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/nuvemshop/nuvemshop.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/simpleem/simpleem.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/spotify/actions/add-items-to-playlist/add-items-to-playlist.mjs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { axios } from "@pipedream/platform";
2-
import get from "lodash/get.js";
31
import spotify from "../../spotify.app.mjs";
42

53
export default {
64
name: "Add Items to a Playlist",
75
description: "Add one or more items to a user’s playlist. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/add-tracks-to-playlist).",
86
key: "spotify-add-items-to-playlist",
9-
version: "0.1.4",
7+
version: "0.1.5",
108
annotations: {
119
destructiveHint: false,
1210
openWorldHint: true,
@@ -46,14 +44,15 @@ export default {
4644
uris: this.spotify.sanitizedArray(uris),
4745
};
4846

49-
const resp = await axios($, this.spotify._getAxiosParams({
47+
const { data: resp } = await this.spotify._makeRequest({
48+
$,
5049
method: "POST",
51-
path: `/playlists/${get(playlistId, "value", playlistId)}/tracks`,
50+
url: `/playlists/${playlistId.value ?? playlistId}/tracks`,
5251
data,
53-
}));
52+
});
5453

5554
// eslint-disable-next-line multiline-ternary
56-
$.export("$summary", `Successfully added ${data.uris.length} ${data.uris.length == 1 ? "item" : "items"} to "${get(playlistId, "label", playlistId)}"`);
55+
$.export("$summary", `Successfully added ${data.uris.length} ${data.uris.length == 1 ? "item" : "items"} to "${playlistId.label ?? playlistId}"`);
5756

5857
return resp;
5958
},

components/spotify/actions/create-playlist/create-playlist.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { axios } from "@pipedream/platform";
21
import spotify from "../../spotify.app.mjs";
32

43
export default {
54
name: "Create a Playlist",
65
description: "Create a playlist for a Spotify user. The playlist will be empty until you add tracks. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/create-playlist).",
76
key: "spotify-create-playlist",
8-
version: "0.1.4",
7+
version: "0.1.5",
98
annotations: {
109
destructiveHint: false,
1110
openWorldHint: true,
@@ -53,11 +52,12 @@ export default {
5352
collaborative: isCollaborative,
5453
};
5554

56-
const resp = await axios($, this.spotify._getAxiosParams({
55+
const { data: resp } = await this.spotify._makeRequest({
56+
$,
5757
method: "POST",
58-
path: `/users/${this.spotify.$auth.oauth_uid}/playlists`,
58+
url: `/users/${this.spotify.$auth.oauth_uid}/playlists`,
5959
data,
60-
}));
60+
});
6161

6262
$.export("$summary", `Successfully created a new playlist, "${data.name}"`);
6363

components/spotify/actions/get-album-tracks/get-album-tracks.mjs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { axios } from "@pipedream/platform";
21
import spotify from "../../spotify.app.mjs";
3-
import { ITEM_TYPES } from "../../common/constants.mjs";
4-
const DEFAULT_LIMIT = 20;
2+
import {
3+
ITEM_TYPES,
4+
PAGE_SIZE,
5+
} from "../../common/constants.mjs";
56

67
export default {
78
name: "Get Album Tracks",
89
description: "Get all tracks in an album. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/get-an-albums-tracks)",
910
key: "spotify-get-album-tracks",
10-
version: "0.0.5",
11+
version: "0.0.6",
1112
annotations: {
1213
destructiveHint: false,
1314
openWorldHint: true,
@@ -25,12 +26,11 @@ export default {
2526
query,
2627
page,
2728
}) {
28-
const limit = DEFAULT_LIMIT;
2929
const albums = await this.spotify.getItems(
3030
ITEM_TYPES.ALBUM,
3131
query,
32-
limit,
33-
limit * page,
32+
PAGE_SIZE,
33+
PAGE_SIZE * page,
3434
);
3535
return {
3636
options: albums.map((album) => ({
@@ -43,19 +43,20 @@ export default {
4343
},
4444
async run({ $ }) {
4545
const params = {
46-
limit: DEFAULT_LIMIT,
46+
limit: PAGE_SIZE,
4747
offset: 0,
4848
};
4949
const tracks = [];
5050
let total = 0;
5151

5252
do {
53-
const { items } = await axios($, this.spotify._getAxiosParams({
54-
path: `/albums/${this.albumId}/tracks`,
53+
const { data } = await this.spotify._makeRequest({
54+
$,
55+
url: `/albums/${this.albumId}/tracks`,
5556
params,
56-
}));
57-
tracks.push(...items);
58-
total = items.length;
57+
});
58+
tracks.push(...data.items);
59+
total = data.items.length;
5960
params.offset += params.limit;
6061
} while (total === params.limit);
6162

components/spotify/actions/get-all-tracks-by-artist/get-all-tracks-by-artist.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import get from "lodash/get.js";
21
import spotify from "../../spotify.app.mjs";
32

43
export default {
54
name: "Get All Tracks by Artist",
65
description: "Get Spotify tracks information related with an artist's. [see docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-multiple-albums).",
76
key: "spotify-get-all-tracks-by-artist",
8-
version: "0.1.4",
7+
version: "0.1.5",
98
annotations: {
109
destructiveHint: false,
1110
openWorldHint: true,
@@ -34,16 +33,18 @@ export default {
3433
} = this;
3534

3635
const chunksOfAlbumIds = await this.spotify.fetchChunksOfAlbumsIds({
36+
$,
3737
artistId,
3838
market,
3939
});
4040

4141
const tracks = await this.spotify.getAllTracksByChunksOfAlbumIds({
42+
$,
4243
chunksOfAlbumIds,
4344
market,
4445
});
4546

46-
$.export("$summary", `Successfully fetched ${tracks.length} tracks for "${get(artistId, "label", artistId)}"`);
47+
$.export("$summary", `Successfully fetched ${tracks.length} tracks for "${artistId.label ?? artistId}"`);
4748

4849
return tracks;
4950
},

components/spotify/actions/get-artist-top-tracks/get-artist-top-tracks.mjs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { axios } from "@pipedream/platform";
2-
import get from "lodash/get.js";
31
import spotify from "../../spotify.app.mjs";
42

53
export default {
64
name: "Get an Artist's Top Tracks",
7-
description: "Get Spotify catalog information about an artists top tracks by country. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks).",
5+
description: "Get Spotify catalog information about an artist's top tracks by country. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks).",
86
key: "spotify-get-artist-top-tracks",
9-
version: "0.1.4",
7+
version: "0.1.5",
108
annotations: {
119
destructiveHint: false,
1210
openWorldHint: true,
@@ -34,16 +32,16 @@ export default {
3432
market,
3533
} = this;
3634

37-
const res = await axios($, this.spotify._getAxiosParams({
38-
method: "GET",
39-
path: `/artists/${get(artistId, "value", artistId)}/top-tracks`,
35+
const { data } = await this.spotify._makeRequest({
36+
$,
37+
url: `/artists/${artistId.value ?? artistId}/top-tracks`,
4038
params: {
4139
market,
4240
},
43-
}));
41+
});
4442

45-
$.export("$summary", `Successfully fetched top tracks for "${get(artistId, "label", artistId)}"`);
43+
$.export("$summary", `Successfully fetched top tracks for "${artistId.label ?? artistId}"`);
4644

47-
return get(res, "tracks", []);
45+
return data?.tracks ?? [];
4846
},
4947
};

0 commit comments

Comments
 (0)