Skip to content

Commit

Permalink
Merge 8493ba8 into e96ed27
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwedgbury committed Apr 21, 2020
2 parents e96ed27 + 8493ba8 commit 4638f4b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/method-reference/SpotifyWebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,24 @@ Play the previous track in the current users's queue.<br>
#### Return values
* **boolean** Whether the track was successfully skipped.

---
### queue


```php
SpotifyWebAPI::queue($trackUri, $deviceId)
```

Add an item to the end of the user's current playback queue.<br>
[https://developer.spotify.com/documentation/web-api/reference/player/add-to-queue/](https://developer.spotify.com/documentation/web-api/reference/player/add-to-queue/)

#### Arguments
* `$trackUri` **string** - Required. The uri of the item to add to the queue. Must be a track or an episode uri.
* `$deviceId` **string** - Optional. ID of the device to target.

#### Return values
* **boolean** Whether the track was successfully added to the queue.

---
### reorderPlaylistTracks

Expand Down
25 changes: 25 additions & 0 deletions src/SpotifyWebAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,31 @@ public function previous($deviceId = '')
return $this->lastResponse['status'] == 204;
}

/**
* Add a song to the queue.
* https://developer.spotify.com/documentation/web-api/reference/player/add-to-queue/
*
* @param string $trackUri Required. The uri of the item to add to the queue. Must be a track or an episode uri.
* @param string $deviceId Optional. ID of the device to target.
*
* @return bool Whether the track was successfully skipped.
*/
public function queue($trackUri, $deviceId = '')
{
$uri = '/v1/me/player/queue';

$uri = $uri . '?uri=' . $trackUri;

// We need to manually append data to the URI since it's a POST request
if ($deviceId) {
$uri = $uri . '&device_id=' . $deviceId;
}

$this->lastResponse = $this->sendRequest('POST', $uri);

return $this->lastResponse['status'] == 204;
}

/**
* Reorder the tracks in a playlist.
* https://developer.spotify.com/documentation/web-api/reference/playlists/reorder-playlists-tracks/
Expand Down
25 changes: 25 additions & 0 deletions tests/SpotifyWebAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,31 @@ public function testPrevious()
$this->assertTrue($response);
}

public function testQueue()
{
$headers = [
'Authorization' => 'Bearer ' . $this->accessToken,
];

$return = [
'status' => 204,
];

$stub = $this->setupStub(
'POST',
'/v1/me/player/queue',
[],
$headers,
$return
);

$api = new SpotifyWebAPI\SpotifyWebAPI([], null, $stub);
$api->setAccessToken($this->accessToken);
$response = $api->queue('spotify:track:6ek0XS2AUbzrHS0B5wPNcU');

$this->assertTrue($response);
}

public function testReorderPlaylistTracks()
{
$options = [
Expand Down

0 comments on commit 4638f4b

Please sign in to comment.