Skip to content

Commit

Permalink
Correct SpotifyWebAPI::deleteMy* request bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilsson committed Oct 9, 2024
1 parent 07a1de0 commit f61995e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
16 changes: 12 additions & 4 deletions src/SpotifyWebAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ public function currentUserFollows(string $type, string|array $ids): array
public function deleteMyAlbums(string|array $albums): bool
{
$albums = $this->uriToId($albums, 'album');
$albums = json_encode((array) $albums);
$albums = json_encode([
'ids' => (array) $albums,
]);

$headers = [
'Content-Type' => 'application/json',
Expand All @@ -466,7 +468,9 @@ public function deleteMyAlbums(string|array $albums): bool
public function deleteMyEpisodes(string|array $episodes): bool
{
$episodes = $this->uriToId($episodes, 'episode');
$episodes = json_encode((array) $episodes);
$episodes = json_encode([
'ids' => (array) $episodes,
]);

$headers = [
'Content-Type' => 'application/json',
Expand All @@ -490,7 +494,9 @@ public function deleteMyEpisodes(string|array $episodes): bool
public function deleteMyShows(string|array $shows): bool
{
$shows = $this->uriToId($shows, 'show');
$shows = json_encode((array) $shows);
$shows = json_encode([
'ids' => (array) $shows,
]);

$headers = [
'Content-Type' => 'application/json',
Expand All @@ -514,7 +520,9 @@ public function deleteMyShows(string|array $shows): bool
public function deleteMyTracks(string|array $tracks): bool
{
$tracks = $this->uriToId($tracks, 'track');
$tracks = json_encode((array) $tracks);
$tracks = json_encode([
'ids' => (array) $tracks,
]);

$headers = [
'Content-Type' => 'application/json',
Expand Down
34 changes: 21 additions & 13 deletions tests/SpotifyWebAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,15 @@ public function testDeleteMyAlbums()
$albums = [
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a',
'spotify:album:1oR3KrPIp4CbagPa3PhtPp'
'spotify:album:1oR3KrPIp4CbagPa3PhtPp',
];

$expected = json_encode([
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a',
'1oR3KrPIp4CbagPa3PhtPp'
'ids' => [
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a',
'1oR3KrPIp4CbagPa3PhtPp',
],
]);

$headers = ['Content-Type' => 'application/json'];
Expand All @@ -470,9 +472,11 @@ public function testDeleteMyEpisodes()
];

$expected = json_encode([
'0zov0kd6MA3BqT1FKpOeYO',
'3pLx6LaVQbWl5IfW8nxq56',
'6kSGLgKWhBg8AoCzylVfc2',
'ids' => [
'0zov0kd6MA3BqT1FKpOeYO',
'3pLx6LaVQbWl5IfW8nxq56',
'6kSGLgKWhBg8AoCzylVfc2',
],
]);

$headers = ['Content-Type' => 'application/json'];
Expand All @@ -499,9 +503,11 @@ public function testDeleteMyShows()
];

$expected = json_encode([
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a',
'1oR3KrPIp4CbagPa3PhtPp'
'ids' => [
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a',
'1oR3KrPIp4CbagPa3PhtPp',
],
]);

$headers = ['Content-Type' => 'application/json'];
Expand All @@ -528,9 +534,11 @@ public function testDeleteMyTracks()
];

$expected = json_encode([
'1id6H6vcwSB9GGv9NXh5cl',
'3mqRLlD9j92BBv1ueFhJ1l',
'1id6H6vcwSB9GGv9NXh5cl',
'ids' => [
'1id6H6vcwSB9GGv9NXh5cl',
'3mqRLlD9j92BBv1ueFhJ1l',
'1id6H6vcwSB9GGv9NXh5cl',
],
]);

$headers = ['Content-Type' => 'application/json'];
Expand Down

0 comments on commit f61995e

Please sign in to comment.