Skip to content
Open
2 changes: 1 addition & 1 deletion components/factorial_api_keys/factorial_api_keys.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/flowii/flowii.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/hailey_hr/hailey_hr.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/nuvemshop/nuvemshop.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/simpleem/simpleem.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { axios } from "@pipedream/platform";
import get from "lodash/get.js";
import spotify from "../../spotify.app.mjs";

export default {
name: "Add Items to a Playlist",
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).",
key: "spotify-add-items-to-playlist",
version: "0.1.4",
version: "0.1.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -46,14 +44,15 @@ export default {
uris: this.spotify.sanitizedArray(uris),
};

const resp = await axios($, this.spotify._getAxiosParams({
const { data: resp } = await this.spotify._makeRequest({
$,
method: "POST",
path: `/playlists/${get(playlistId, "value", playlistId)}/tracks`,
url: `/playlists/${playlistId.value ?? playlistId}/tracks`,
data,
}));
});

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

return resp;
},
Expand Down
10 changes: 5 additions & 5 deletions components/spotify/actions/create-playlist/create-playlist.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { axios } from "@pipedream/platform";
import spotify from "../../spotify.app.mjs";

export default {
name: "Create a Playlist",
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).",
key: "spotify-create-playlist",
version: "0.1.4",
version: "0.1.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -53,11 +52,12 @@ export default {
collaborative: isCollaborative,
};

const resp = await axios($, this.spotify._getAxiosParams({
const { data: resp } = await this.spotify._makeRequest({
$,
method: "POST",
path: `/users/${this.spotify.$auth.oauth_uid}/playlists`,
url: `/users/${this.spotify.$auth.oauth_uid}/playlists`,
data,
}));
});

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

Expand Down
27 changes: 14 additions & 13 deletions components/spotify/actions/get-album-tracks/get-album-tracks.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { axios } from "@pipedream/platform";
import spotify from "../../spotify.app.mjs";
import { ITEM_TYPES } from "../../common/constants.mjs";
const DEFAULT_LIMIT = 20;
import {
ITEM_TYPES,
PAGE_SIZE,
} from "../../common/constants.mjs";

export default {
name: "Get Album Tracks",
description: "Get all tracks in an album. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/get-an-albums-tracks)",
key: "spotify-get-album-tracks",
version: "0.0.5",
version: "0.0.6",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand All @@ -25,12 +26,11 @@ export default {
query,
page,
}) {
const limit = DEFAULT_LIMIT;
const albums = await this.spotify.getItems(
ITEM_TYPES.ALBUM,
query,
limit,
limit * page,
PAGE_SIZE,
PAGE_SIZE * page,
);
return {
options: albums.map((album) => ({
Expand All @@ -43,19 +43,20 @@ export default {
},
async run({ $ }) {
const params = {
limit: DEFAULT_LIMIT,
limit: PAGE_SIZE,
offset: 0,
};
const tracks = [];
let total = 0;

do {
const { items } = await axios($, this.spotify._getAxiosParams({
path: `/albums/${this.albumId}/tracks`,
const { data } = await this.spotify._makeRequest({
$,
url: `/albums/${this.albumId}/tracks`,
params,
}));
tracks.push(...items);
total = items.length;
});
tracks.push(...data.items);
total = data.items.length;
params.offset += params.limit;
} while (total === params.limit);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import get from "lodash/get.js";
import spotify from "../../spotify.app.mjs";

export default {
name: "Get All Tracks by Artist",
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).",
key: "spotify-get-all-tracks-by-artist",
version: "0.1.4",
version: "0.1.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -34,16 +33,18 @@ export default {
} = this;

const chunksOfAlbumIds = await this.spotify.fetchChunksOfAlbumsIds({
$,
artistId,
market,
});

const tracks = await this.spotify.getAllTracksByChunksOfAlbumIds({
$,
chunksOfAlbumIds,
market,
});

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

return tracks;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { axios } from "@pipedream/platform";
import get from "lodash/get.js";
import spotify from "../../spotify.app.mjs";

export default {
name: "Get an Artist's Top Tracks",
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).",
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).",
key: "spotify-get-artist-top-tracks",
version: "0.1.4",
version: "0.1.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -34,16 +32,16 @@ export default {
market,
} = this;

const res = await axios($, this.spotify._getAxiosParams({
method: "GET",
path: `/artists/${get(artistId, "value", artistId)}/top-tracks`,
const { data } = await this.spotify._makeRequest({
$,
url: `/artists/${artistId.value ?? artistId}/top-tracks`,
params: {
market,
},
}));
});

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

return get(res, "tracks", []);
return data?.tracks ?? [];
},
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { axios } from "@pipedream/platform";
import get from "lodash/get.js";
import spotify from "../../spotify.app.mjs";

export default {
name: "Get Audio Features for a Track",
description: "Get audio feature information for a single track identified by its unique Spotify ID. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-audio-features).",
key: "spotify-get-audio-features-for-a-track",
version: "0.1.4",
version: "0.1.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand All @@ -24,13 +22,13 @@ export default {
},
async run({ $ }) {
const { trackId } = this;
const resp = await axios($, this.spotify._getAxiosParams({
method: "GET",
path: `/audio-features/${get(trackId, "value", trackId)}`,
}));
const { data } = await this.spotify._makeRequest({
$,
url: `/audio-features/${trackId.value ?? trackId}`,
});

$.export("$summary", `Successfully fetched audio info for the track, "${get(trackId, "label", trackId)}"`);
$.export("$summary", `Successfully fetched audio info for the track, "${trackId.label ?? trackId}"`);

return resp;
return data;
},
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { axios } from "@pipedream/platform";
import get from "lodash/get.js";
import spotify from "../../spotify.app.mjs";

export default {
name: "Get a Category's Playlists",
description: "Get a list of Spotify playlists tagged with a particular category. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-a-categories-playlists).",
key: "spotify-get-categorys-playlist",
version: "0.1.4",
version: "0.1.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -51,18 +49,18 @@ export default {
offset,
} = this;

const res = await axios($, this.spotify._getAxiosParams({
method: "GET",
path: `/browse/categories/${get(categoryId, "value", categoryId)}/playlists`,
const { data } = await this.spotify._makeRequest({
$,
url: `/browse/categories/${categoryId.value ?? categoryId}/playlists`,
params: {
limit,
offset,
country: market,
},
}));
});

$.export("$summary", `Successfully fetched playlists for the "${get(categoryId, "label", categoryId)}" category`);
$.export("$summary", `Successfully fetched playlists for the "${categoryId.label ?? categoryId}" category`);

return get(res, "playlists.items", []);
return data?.playlists?.items ?? [];
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { axios } from "@pipedream/platform";
import spotify from "../../spotify.app.mjs";
import { ITEM_TYPES } from "../../common/constants.mjs";

Expand All @@ -7,7 +6,7 @@ export default {
description:
"Get the object currently being played on the user's Spotify account. [See the documentation](https://developer.spotify.com/documentation/web-api/reference/get-the-users-currently-playing-track)",
key: "spotify-get-currently-playing-track",
version: "0.0.5",
version: "0.0.6",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand All @@ -28,20 +27,17 @@ export default {
const { market } = this;

try {
const res = await axios(
const { data: res } = await this.spotify._makeRequest({
$,
this.spotify._getAxiosParams({
method: "GET",
path: "/me/player/currently-playing",
params: {
market,
additional_types: [
ITEM_TYPES.TRACK,
ITEM_TYPES.EPISODE,
].join(","),
},
}),
);
url: "/me/player/currently-playing",
params: {
market,
additional_types: [
ITEM_TYPES.TRACK,
ITEM_TYPES.EPISODE,
].join(","),
},
});

const itemType = res?.currently_playing_type || "track";
const itemName = res?.item?.name || "Nothing";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { axios } from "@pipedream/platform";
import get from "lodash/get.js";
import spotify from "../../spotify.app.mjs";

export default {
name: "Get a Playlist's Items",
description: "Get full details of the items of a playlist owned by a Spotify user. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-playlists-tracks).",
key: "spotify-get-playlist-items",
version: "0.1.4",
version: "0.1.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -53,27 +51,25 @@ export default {
async run({ $ }) {
const {
playlistId,
market,
fields,
limit,
offset,
additionalTypes,
} = this;

const res = await axios($, this.spotify._getAxiosParams({
method: "GET",
path: `/playlists/${get(playlistId, "value", playlistId)}/tracks`,
const { data } = await this.spotify._makeRequest({
$,
url: `/playlists/${playlistId.value ?? playlistId}/tracks`,
params: {
fields,
market,
limit,
offset,
additional_types: additionalTypes && additionalTypes.join(",").toLowerCase(),
},
}));
});

$.export("$summary", `Successfully fetched details for "${get(playlistId, "label", playlistId)}"`);
$.export("$summary", `Successfully fetched details for "${playlistId.label ?? playlistId}"`);

return get(res, "items", []);
return data?.items ?? [];
},
};
Loading
Loading