Skip to content

Commit 1427059

Browse files
committed
Deprecate SpotifyWebAPI::usersFollowPlaylist()
1 parent ef9b92e commit 1427059

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

docs/examples/following-artists-playlists-and-users.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,10 @@ $api->followPlaylist('PLAYLIST_ID');
3434
$api->unfollowPlaylist('PLAYLIST_ID');
3535
```
3636

37-
## Checking if user(s) are following a playlist
37+
## Checking if the current user is following a playlist
3838

3939
```php
40-
$users = [
41-
'USER_1',
42-
'USER_2',
43-
];
44-
45-
$api->usersFollowsPlaylist('PLAYLIST_ID', [
46-
'ids' => $users,
47-
]);
40+
$api->currentUserFollowsPlaylist('PLAYLIST_ID');
4841
```
4942

5043
Please see the [method reference](/docs/method-reference/SpotifyWebAPI.md) for more available options for each method.

docs/method-reference/SpotifyWebAPI.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [changeVolume](#changevolume)
1212
* [createPlaylist](#createplaylist)
1313
* [currentUserFollows](#currentuserfollows)
14+
* [currentUserFollowsPlaylist](#currentuserfollowsplaylist)
1415
* [deleteMyAlbums](#deletemyalbums)
1516
* [deleteMyEpisodes](#deletemyepisodes)
1617
* [deleteMyShows](#deletemyshows)
@@ -277,6 +278,23 @@ https://developer.spotify.com/documentation/web-api/reference/check-current-user
277278
#### Return values
278279
* **array** Whether each user or artist is followed.
279280

281+
---
282+
### currentUserFollowsPlaylist
283+
284+
285+
```php
286+
SpotifyWebAPI::currentUserFollowsPlaylist($playlistId)
287+
```
288+
289+
Check if the current user is following a playlist.<br>
290+
https://developer.spotify.com/documentation/web-api/reference/check-if-user-follows-playlist
291+
292+
#### Arguments
293+
* `$playlistId` **string** - ID or URI of the playlist to check.
294+
295+
#### Return values
296+
* **array** Array containing one boolean describing whether the playlist is followed.
297+
280298
---
281299
### deleteMyAlbums
282300

@@ -1627,7 +1645,7 @@ Set the access token to use.
16271645
* `$accessToken` **string** - The access token.
16281646

16291647
#### Return values
1630-
* **self**
1648+
* **self**
16311649

16321650
---
16331651
### setOptions
@@ -1643,7 +1661,7 @@ Set options
16431661
* `$options` **array\|object** - Options to set.
16441662

16451663
#### Return values
1646-
* **self**
1664+
* **self**
16471665

16481666
---
16491667
### setSession
@@ -1659,7 +1677,7 @@ Set the Session object to use.
16591677
* `$session` **\SpotifyWebAPI\Session** - The Session object.
16601678

16611679
#### Return values
1662-
* **self**
1680+
* **self**
16631681

16641682
---
16651683
### shuffle
@@ -1758,6 +1776,7 @@ https://developer.spotify.com/documentation/web-api/reference/upload-custom-play
17581776
---
17591777
### usersFollowPlaylist
17601778

1779+
_Deprecated. Use SpotifyWebAPI::currentUserFollowsPlaylist() instead._
17611780

17621781
```php
17631782
SpotifyWebAPI::usersFollowPlaylist($playlistId, $options)
@@ -1768,10 +1787,10 @@ https://developer.spotify.com/documentation/web-api/reference/check-if-user-foll
17681787

17691788
#### Arguments
17701789
* `$playlistId` **string** - ID or URI of the playlist.
1771-
* `$options` **array\|object** - Options for the check.
1772-
* ids string\|array Required. IDs or URIs of the users to check for.
1790+
* `$options` **array\|object** - Optional. Options for the check.
1791+
* ids string\|array ID or URI of the current user.
17731792

17741793
#### Return values
1775-
* **array** Whether each user is following the playlist.
1794+
* **array** Whether the current user is following the playlist.
17761795

17771796
---

src/SpotifyWebAPI.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,25 @@ public function currentUserFollows(string $type, string|array $ids): array
433433
return $this->lastResponse['body'];
434434
}
435435

436+
/**
437+
* Check if the current user is following a playlist.
438+
* https://developer.spotify.com/documentation/web-api/reference/check-if-user-follows-playlist
439+
*
440+
* @param string $playlistId ID or URI of the playlist to check.
441+
*
442+
* @return array Array containing one boolean describing whether the playlist is followed.
443+
*/
444+
public function currentUserFollowsPlaylist(string $playlistId): array
445+
{
446+
$playlistId = $this->uriToId($playlistId, 'playlist');
447+
448+
$uri = '/v1/playlists/' . $playlistId . '/followers/contains';
449+
450+
$this->lastResponse = $this->sendRequest('GET', $uri);
451+
452+
return $this->lastResponse['body'];
453+
}
454+
436455
/**
437456
* Delete albums from the current user's Spotify library.
438457
* https://developer.spotify.com/documentation/web-api/reference/remove-albums-user
@@ -2234,14 +2253,22 @@ public function updatePlaylistImage(string $playlistId, string $imageData): bool
22342253
* Check if a set of users are following a playlist.
22352254
* https://developer.spotify.com/documentation/web-api/reference/check-if-user-follows-playlist
22362255
*
2256+
* @deprecated Use SpotifyWebAPI::currentUserFollowsPlaylist() instead.
2257+
*
22372258
* @param string $playlistId ID or URI of the playlist.
2238-
* @param array|object $options Options for the check.
2239-
* - ids string|array Required. IDs or URIs of the users to check for.
2259+
* @param array|object $options Optional. Options for the check.
2260+
* - ids string|array ID or URI of the current user.
22402261
*
2241-
* @return array Whether each user is following the playlist.
2262+
* @return array Whether the current user is following the playlist.
22422263
*/
2243-
public function usersFollowPlaylist(string $playlistId, array|object $options): array
2264+
public function usersFollowPlaylist(string $playlistId, array|object $options = []): array
22442265
{
2266+
trigger_error(
2267+
// phpcs:ignore
2268+
'SpotifyWebAPI::usersFollowPlaylist() is deprecated. Use SpotifyWebAPI::currentUserFollowsPlaylist() instead.',
2269+
E_USER_DEPRECATED
2270+
);
2271+
22452272
$options = (array) $options;
22462273

22472274
if (isset($options['ids'])) {

tests/SpotifyWebAPITest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,24 @@ public function testCurrentUserFollows()
432432
$this->assertTrue($response[0]);
433433
}
434434

435+
public function testCurrentUserFollowsPlaylist()
436+
{
437+
$return = ['body' => get_fixture('users-follows-playlist')];
438+
$api = $this->setupApi(
439+
'GET',
440+
'/v1/playlists/0UZ0Ll4HJHR7yvURYbHJe9/followers/contains',
441+
[],
442+
[],
443+
$return
444+
);
445+
446+
$response = $api->currentUserFollowsPlaylist(
447+
'spotify:playlist:0UZ0Ll4HJHR7yvURYbHJe9',
448+
);
449+
450+
$this->assertTrue($response[0]);
451+
}
452+
435453
public function testDeleteMyAlbums()
436454
{
437455
$albums = [
@@ -2363,13 +2381,12 @@ public function testUsersFollowPlaylist()
23632381
{
23642382
$options = [
23652383
'ids' => [
2366-
'possan',
2367-
'spotify:user:elogain',
2384+
'spotify:user:mcgurk',
23682385
],
23692386
];
23702387

23712388
$expected = [
2372-
'ids' => 'possan,elogain',
2389+
'ids' => 'mcgurk',
23732390
];
23742391

23752392
$return = ['body' => get_fixture('users-follows-playlist')];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[true, true]
1+
[true]

0 commit comments

Comments
 (0)