Added AddToQueue

This commit is contained in:
Jonas Dellinger 2020-03-09 20:28:41 +01:00
parent 284d80ff6f
commit 307d69945e
3 changed files with 4066 additions and 4067 deletions

View File

@ -217,3 +217,21 @@ ErrorResponse error = _spotify.SetVolume(50);
```csharp
ErrorResponse error = _spotify.SetShuffle(false);
```
---
## AddToQueue
> Add an Item to the User's Playback Queue. BETA.
**Parameters**
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|uri|The uri of the item to add to the queue. Must be a track or an episode uri.| `spotify:track:7zrCVKp6x0AtolOsn2iMif`
|[deviceId]| The id of the device this command is targeting. If not supplied, the user's currently active device is the target. | `"XXXX-XXXX-XXXX-XXXX"`
**Usage**
```csharp
ErrorResponse error = _spotify.AddToQueue("spotify:track:7zrCVKp6x0AtolOsn2iMif");
```

View File

@ -1,13 +1,13 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SpotifyAPI.Web.Enums;
using SpotifyAPI.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SpotifyAPI.Web.Enums;
using SpotifyAPI.Web.Models;
namespace SpotifyAPI.Web
{
@ -16,9 +16,7 @@ namespace SpotifyAPI.Web
{
private readonly SpotifyWebBuilder _builder;
public SpotifyWebAPI() : this(null)
{
}
public SpotifyWebAPI() : this(null) { }
public SpotifyWebAPI(ProxyConfig proxyConfig)
{
@ -62,7 +60,6 @@ namespace SpotifyAPI.Web
/// </summary>
public IClient WebClient { get; set; }
/// <summary>
/// Specifies after how many miliseconds should a failed request be retried.
/// </summary>
@ -86,7 +83,7 @@ namespace SpotifyAPI.Web
/// <summary>
/// Error codes that will trigger auto-retry if <see cref="UseAutoRetry"/> is enabled.
/// </summary>
public IEnumerable<int> RetryErrorCodes { get; set; } = new[] { 500, 502, 503 };
public IEnumerable<int> RetryErrorCodes { get; set; } = new [] { 500, 502, 503 };
#endregion Configuration
@ -658,8 +655,7 @@ namespace SpotifyAPI.Web
public ErrorResponse Follow(FollowType followType, List<string> ids)
{
JObject ob = new JObject
{
{"ids", new JArray(ids)}
{ { "ids", new JArray(ids) }
};
return UploadData<ErrorResponse>(_builder.Follow(followType), ob.ToString(Formatting.None), "PUT") ?? new ErrorResponse();
}
@ -674,8 +670,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> FollowAsync(FollowType followType, List<string> ids)
{
JObject ob = new JObject
{
{"ids", new JArray(ids)}
{ { "ids", new JArray(ids) }
};
return await UploadDataAsync<ErrorResponse>(_builder.Follow(followType),
ob.ToString(Formatting.None), "PUT").ConfigureAwait(false) ?? new ErrorResponse();
@ -715,8 +710,7 @@ namespace SpotifyAPI.Web
public ErrorResponse Unfollow(FollowType followType, List<string> ids)
{
JObject ob = new JObject
{
{"ids", new JArray(ids)}
{ { "ids", new JArray(ids) }
};
return UploadData<ErrorResponse>(_builder.Unfollow(followType), ob.ToString(Formatting.None), "DELETE") ?? new ErrorResponse();
}
@ -731,8 +725,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> UnfollowAsync(FollowType followType, List<string> ids)
{
JObject ob = new JObject
{
{"ids", new JArray(ids)}
{ { "ids", new JArray(ids) }
};
return await UploadDataAsync<ErrorResponse>(_builder.Unfollow(followType), ob.ToString(Formatting.None), "DELETE").ConfigureAwait(false) ?? new ErrorResponse();
}
@ -777,8 +770,6 @@ namespace SpotifyAPI.Web
return DownloadList<bool>(url);
}
/// <summary>
/// Check to see if the current user is following one or more artists or other Spotify users asynchronously.
/// </summary>
@ -835,8 +826,7 @@ namespace SpotifyAPI.Web
public ErrorResponse FollowPlaylist(string ownerId, string playlistId, bool showPublic = true)
{
JObject body = new JObject
{
{"public", showPublic}
{ { "public", showPublic }
};
return UploadData<ErrorResponse>(_builder.FollowPlaylist(playlistId), body.ToString(Formatting.None), "PUT");
}
@ -857,8 +847,7 @@ namespace SpotifyAPI.Web
public Task<ErrorResponse> FollowPlaylistAsync(string playlistId, bool showPublic = true)
{
JObject body = new JObject
{
{"public", showPublic}
{ { "public", showPublic }
};
return UploadDataAsync<ErrorResponse>(_builder.FollowPlaylist(playlistId), body.ToString(Formatting.None), "PUT");
}
@ -925,7 +914,7 @@ namespace SpotifyAPI.Web
/// <param name="id">A Spotify User ID</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public ListResponse<bool> IsFollowingPlaylist( string playlistId, string id)
public ListResponse<bool> IsFollowingPlaylist(string playlistId, string id)
{
return IsFollowingPlaylist(playlistId, new List<string> { id });
}
@ -939,7 +928,7 @@ namespace SpotifyAPI.Web
/// <remarks>AUTH NEEDED</remarks>
public Task<ListResponse<bool>> IsFollowingPlaylistAsync(string playlistId, string id)
{
return IsFollowingPlaylistAsync( playlistId, new List<string> { id });
return IsFollowingPlaylistAsync(playlistId, new List<string> { id });
}
#endregion Follow
@ -1510,11 +1499,7 @@ namespace SpotifyAPI.Web
public FullPlaylist CreatePlaylist(string userId, string playlistName, bool isPublic = true, bool isCollaborative = false, string playlistDescription = "")
{
JObject body = new JObject
{
{"name", playlistName},
{"public", isPublic},
{"collaborative", isCollaborative},
{"description", playlistDescription}
{ { "name", playlistName }, { "public", isPublic }, { "collaborative", isCollaborative }, { "description", playlistDescription }
};
return UploadData<FullPlaylist>(_builder.CreatePlaylist(userId, playlistName, isPublic), body.ToString(Formatting.None));
}
@ -1539,11 +1524,7 @@ namespace SpotifyAPI.Web
public Task<FullPlaylist> CreatePlaylistAsync(string userId, string playlistName, bool isPublic = true, bool isCollaborative = false, string playlistDescription = "")
{
JObject body = new JObject
{
{"name", playlistName},
{"public", isPublic},
{"collaborative", isCollaborative},
{"description", playlistDescription}
{ { "name", playlistName }, { "public", isPublic }, { "collaborative", isCollaborative }, { "description", playlistDescription }
};
return UploadDataAsync<FullPlaylist>(_builder.CreatePlaylist(userId, playlistName, isPublic), body.ToString(Formatting.None));
}
@ -1714,8 +1695,7 @@ namespace SpotifyAPI.Web
public ErrorResponse ReplacePlaylistTracks(string userId, string playlistId, List<string> uris)
{
JObject body = new JObject
{
{"uris", new JArray(uris.Take(100))}
{ { "uris", new JArray(uris.Take(100)) }
};
return UploadData<ErrorResponse>(_builder.ReplacePlaylistTracks(userId, playlistId), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse();
}
@ -1731,8 +1711,7 @@ namespace SpotifyAPI.Web
public ErrorResponse ReplacePlaylistTracks(string playlistId, List<string> uris)
{
JObject body = new JObject
{
{"uris", new JArray(uris.Take(100))}
{ { "uris", new JArray(uris.Take(100)) }
};
return UploadData<ErrorResponse>(_builder.ReplacePlaylistTracks(playlistId), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse();
}
@ -1750,8 +1729,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> ReplacePlaylistTracksAsync(string userId, string playlistId, List<string> uris)
{
JObject body = new JObject
{
{"uris", new JArray(uris.Take(100))}
{ { "uris", new JArray(uris.Take(100)) }
};
return await UploadDataAsync<ErrorResponse>(_builder.ReplacePlaylistTracks(userId, playlistId), body.ToString(Formatting.None), "PUT").ConfigureAwait(false) ?? new ErrorResponse();
}
@ -1767,8 +1745,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> ReplacePlaylistTracksAsync(string playlistId, List<string> uris)
{
JObject body = new JObject
{
{"uris", new JArray(uris.Take(100))}
{ { "uris", new JArray(uris.Take(100)) }
};
return await UploadDataAsync<ErrorResponse>(_builder.ReplacePlaylistTracks(playlistId), body.ToString(Formatting.None), "PUT").ConfigureAwait(false) ?? new ErrorResponse();
}
@ -1788,8 +1765,7 @@ namespace SpotifyAPI.Web
public ErrorResponse RemovePlaylistTracks(string userId, string playlistId, List<DeleteTrackUri> uris)
{
JObject body = new JObject
{
{"tracks", JArray.FromObject(uris.Take(100))}
{ { "tracks", JArray.FromObject(uris.Take(100)) }
};
return UploadData<ErrorResponse>(_builder.RemovePlaylistTracks(userId, playlistId, uris), body.ToString(Formatting.None), "DELETE") ?? new ErrorResponse();
}
@ -1807,8 +1783,7 @@ namespace SpotifyAPI.Web
public ErrorResponse RemovePlaylistTracks(string playlistId, List<DeleteTrackUri> uris)
{
JObject body = new JObject
{
{"tracks", JArray.FromObject(uris.Take(100))}
{ { "tracks", JArray.FromObject(uris.Take(100)) }
};
return UploadData<ErrorResponse>(_builder.RemovePlaylistTracks(playlistId, uris), body.ToString(Formatting.None), "DELETE") ?? new ErrorResponse();
}
@ -1828,8 +1803,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> RemovePlaylistTracksAsync(string userId, string playlistId, List<DeleteTrackUri> uris)
{
JObject body = new JObject
{
{"tracks", JArray.FromObject(uris.Take(100))}
{ { "tracks", JArray.FromObject(uris.Take(100)) }
};
return await UploadDataAsync<ErrorResponse>(_builder.RemovePlaylistTracks(userId, playlistId, uris), body.ToString(Formatting.None), "DELETE").ConfigureAwait(false) ?? new ErrorResponse();
}
@ -1847,8 +1821,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> RemovePlaylistTracksAsync(string playlistId, List<DeleteTrackUri> uris)
{
JObject body = new JObject
{
{"tracks", JArray.FromObject(uris.Take(100))}
{ { "tracks", JArray.FromObject(uris.Take(100)) }
};
return await UploadDataAsync<ErrorResponse>(_builder.RemovePlaylistTracks(playlistId, uris), body.ToString(Formatting.None), "DELETE").ConfigureAwait(false) ?? new ErrorResponse();
}
@ -1918,8 +1891,7 @@ namespace SpotifyAPI.Web
public ErrorResponse AddPlaylistTracks(string userId, string playlistId, List<string> uris, int? position = null)
{
JObject body = new JObject
{
{"uris", JArray.FromObject(uris.Take(100))}
{ { "uris", JArray.FromObject(uris.Take(100)) }
};
return UploadData<ErrorResponse>(_builder.AddPlaylistTracks(userId, playlistId, uris, position), body.ToString(Formatting.None)) ?? new ErrorResponse();
}
@ -1935,8 +1907,7 @@ namespace SpotifyAPI.Web
public ErrorResponse AddPlaylistTracks(string playlistId, List<string> uris, int? position = null)
{
JObject body = new JObject
{
{"uris", JArray.FromObject(uris.Take(100))}
{ { "uris", JArray.FromObject(uris.Take(100)) }
};
return UploadData<ErrorResponse>(_builder.AddPlaylistTracks(playlistId, uris, position), body.ToString(Formatting.None)) ?? new ErrorResponse();
}
@ -1954,8 +1925,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> AddPlaylistTracksAsync(string userId, string playlistId, List<string> uris, int? position = null)
{
JObject body = new JObject
{
{"uris", JArray.FromObject(uris.Take(100))}
{ { "uris", JArray.FromObject(uris.Take(100)) }
};
return await UploadDataAsync<ErrorResponse>(_builder.AddPlaylistTracks(userId, playlistId, uris, position), body.ToString(Formatting.None)).ConfigureAwait(false) ?? new ErrorResponse();
}
@ -1971,8 +1941,7 @@ namespace SpotifyAPI.Web
public async Task<ErrorResponse> AddPlaylistTracksAsync(string playlistId, List<string> uris, int? position = null)
{
JObject body = new JObject
{
{"uris", JArray.FromObject(uris.Take(100))}
{ { "uris", JArray.FromObject(uris.Take(100)) }
};
return await UploadDataAsync<ErrorResponse>(_builder.AddPlaylistTracks(playlistId, uris, position), body.ToString(Formatting.None)).ConfigureAwait(false) ?? new ErrorResponse();
}
@ -1992,7 +1961,6 @@ namespace SpotifyAPI.Web
return AddPlaylistTracks(playlistId, new List<string> { uri }, position);
}
/// <summary>
/// Add a track to a users playlist.
/// </summary>
@ -2049,10 +2017,7 @@ namespace SpotifyAPI.Web
public Snapshot ReorderPlaylist(string userId, string playlistId, int rangeStart, int insertBefore, int rangeLength = 1, string snapshotId = "")
{
JObject body = new JObject
{
{"range_start", rangeStart},
{"range_length", rangeLength},
{"insert_before", insertBefore}
{ { "range_start", rangeStart }, { "range_length", rangeLength }, { "insert_before", insertBefore }
};
if (!string.IsNullOrEmpty(snapshotId))
body.Add("snapshot_id", snapshotId);
@ -2072,10 +2037,7 @@ namespace SpotifyAPI.Web
public Snapshot ReorderPlaylist(string playlistId, int rangeStart, int insertBefore, int rangeLength = 1, string snapshotId = "")
{
JObject body = new JObject
{
{"range_start", rangeStart},
{"range_length", rangeLength},
{"insert_before", insertBefore}
{ { "range_start", rangeStart }, { "range_length", rangeLength }, { "insert_before", insertBefore }
};
if (!string.IsNullOrEmpty(snapshotId))
body.Add("snapshot_id", snapshotId);
@ -2097,11 +2059,7 @@ namespace SpotifyAPI.Web
public Task<Snapshot> ReorderPlaylistAsync(string userId, string playlistId, int rangeStart, int insertBefore, int rangeLength = 1, string snapshotId = "")
{
JObject body = new JObject
{
{"range_start", rangeStart},
{"range_length", rangeLength},
{"insert_before", insertBefore},
{"snapshot_id", snapshotId}
{ { "range_start", rangeStart }, { "range_length", rangeLength }, { "insert_before", insertBefore }, { "snapshot_id", snapshotId }
};
if (!string.IsNullOrEmpty(snapshotId))
body.Add("snapshot_id", snapshotId);
@ -2121,11 +2079,7 @@ namespace SpotifyAPI.Web
public Task<Snapshot> ReorderPlaylistAsync(string playlistId, int rangeStart, int insertBefore, int rangeLength = 1, string snapshotId = "")
{
JObject body = new JObject
{
{"range_start", rangeStart},
{"range_length", rangeLength},
{"insert_before", insertBefore},
{"snapshot_id", snapshotId}
{ { "range_start", rangeStart }, { "range_length", rangeLength }, { "insert_before", insertBefore }, { "snapshot_id", snapshotId }
};
if (!string.IsNullOrEmpty(snapshotId))
body.Add("snapshot_id", snapshotId);
@ -2393,9 +2347,7 @@ namespace SpotifyAPI.Web
public ErrorResponse TransferPlayback(List<string> deviceIds, bool play = false)
{
JObject ob = new JObject
{
{ "play", play },
{ "device_ids", new JArray(deviceIds) }
{ { "play", play }, { "device_ids", new JArray(deviceIds) }
};
return UploadData<ErrorResponse>(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT");
}
@ -2413,9 +2365,7 @@ namespace SpotifyAPI.Web
public Task<ErrorResponse> TransferPlaybackAsync(List<string> deviceIds, bool play = false)
{
JObject ob = new JObject
{
{ "play", play },
{ "device_ids", new JArray(deviceIds) }
{ { "play", play }, { "device_ids", new JArray(deviceIds) }
};
return UploadDataAsync<ErrorResponse>(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT");
}
@ -2434,11 +2384,11 @@ namespace SpotifyAPI.Web
int? offset = null, int positionMs = 0)
{
JObject ob = new JObject();
if(!string.IsNullOrEmpty(contextUri))
if (!string.IsNullOrEmpty(contextUri))
ob.Add("context_uri", contextUri);
if(uris != null)
if (uris != null)
ob.Add("uris", new JArray(uris));
if(offset != null)
if (offset != null)
ob.Add("offset", new JObject { { "position", offset } });
if (positionMs > 0)
ob.Add("position_ms", positionMs);
@ -2489,7 +2439,7 @@ namespace SpotifyAPI.Web
if (uris != null)
ob.Add("uris", new JArray(uris));
if (!string.IsNullOrEmpty(offset))
ob.Add("offset", new JObject {{"uri", offset}});
ob.Add("offset", new JObject { { "uri", offset } });
if (positionMs > 0)
ob.Add("position_ms", positionMs);
return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
@ -2674,6 +2624,28 @@ namespace SpotifyAPI.Web
return UploadDataAsync<ErrorResponse>(_builder.SetShuffle(shuffle, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Add an Item to the User's Playback Queue. BETA
/// </summary>
/// <param name="uri">The uri of the item to add to the queue. Must be a track or an episode uri.</param>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the users currently active device is the target.</param>
/// <returns></returns>
public ErrorResponse AddToQueue(string uri, string deviceId = "")
{
return UploadData<ErrorResponse>(_builder.AddToQueue(uri, deviceId), string.Empty);
}
/// <summary>
/// Add an Item to the User's Playback Queue. BETA
/// </summary>
/// <param name="uri">The uri of the item to add to the queue. Must be a track or an episode uri.</param>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the users currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> AddToQueueAsync(string uri, string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.AddToQueue(uri, deviceId), string.Empty);
}
#endregion
#region Util
@ -2826,8 +2798,7 @@ namespace SpotifyAPI.Web
do
{
Dictionary<string, string> headers = new Dictionary<string, string>
{
{ "Authorization", TokenType + " " + AccessToken},
{ { "Authorization", TokenType + " " + AccessToken },
{ "Content-Type", "application/json" }
};
@ -2855,8 +2826,7 @@ namespace SpotifyAPI.Web
do
{
Dictionary<string, string> headers = new Dictionary<string, string>
{
{ "Authorization", TokenType + " " + AccessToken},
{ { "Authorization", TokenType + " " + AccessToken },
{ "Content-Type", "application/json" }
};
@ -2881,7 +2851,7 @@ namespace SpotifyAPI.Web
Tuple<ResponseInfo, T> response = null;
do
{
if(response != null) { Thread.Sleep(RetryAfter); }
if (response != null) { Thread.Sleep(RetryAfter); }
response = DownloadDataAlt<T>(url);
response.Item2.AddResponseInfo(response.Item1);
@ -2891,7 +2861,6 @@ namespace SpotifyAPI.Web
} while (UseAutoRetry && triesLeft > 0 && lastError != null && RetryErrorCodes.Contains(lastError.Status));
return response.Item2;
}
@ -2904,7 +2873,7 @@ namespace SpotifyAPI.Web
private int GetTooManyRequests(ResponseInfo info)
{
// 429 is "TooManyRequests" value specified in Spotify API
if (429 != (int)info.StatusCode)
if (429 != (int) info.StatusCode)
{
return -1;
}
@ -2943,11 +2912,10 @@ namespace SpotifyAPI.Web
triesLeft -= 1;
}
} while (UseAutoRetry
&& triesLeft > 0
&& (GetTooManyRequests(response.Item1) != -1
|| lastError != null && RetryErrorCodes.Contains(lastError.Status)));
} while (UseAutoRetry &&
triesLeft > 0 &&
(GetTooManyRequests(response.Item1) != -1 ||
lastError != null && RetryErrorCodes.Contains(lastError.Status)));
return response.Item2;
}

View File

@ -81,9 +81,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string GetSeveralAlbums(List<string> ids, string market = "")
{
return string.IsNullOrEmpty(market)
? $"{APIBase}/albums?ids={string.Join(",", ids.Take(20))}"
: $"{APIBase}/albums?market={market}&ids={string.Join(",", ids.Take(20))}";
return string.IsNullOrEmpty(market) ?
$"{APIBase}/albums?ids={string.Join(",", ids.Take(20))}" :
$"{APIBase}/albums?market={market}&ids={string.Join(",", ids.Take(20))}";
}
#endregion Albums
@ -820,9 +820,9 @@ namespace SpotifyAPI.Web
/// <remarks>AUTH NEEDED</remarks>
public string AddPlaylistTracks(string userId, string playlistId, List<string> uris, int? position = null)
{
return position == null
? $"{APIBase}/users/{userId}/playlists/{playlistId}/tracks"
: $"{APIBase}/users/{userId}/playlists/{playlistId}/tracks?position={position}";
return position == null ?
$"{APIBase}/users/{userId}/playlists/{playlistId}/tracks" :
$"{APIBase}/users/{userId}/playlists/{playlistId}/tracks?position={position}";
}
/// <summary>
@ -835,9 +835,9 @@ namespace SpotifyAPI.Web
/// <remarks>AUTH NEEDED</remarks>
public string AddPlaylistTracks(string playlistId, List<string> uris, int? position = null)
{
return position == null
? $"{APIBase}/playlists/{playlistId}/tracks"
: $"{APIBase}/playlists/{playlistId}/tracks?position={position}";
return position == null ?
$"{APIBase}/playlists/{playlistId}/tracks" :
$"{APIBase}/playlists/{playlistId}/tracks?position={position}";
}
/// <summary>
@ -922,9 +922,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string GetSeveralTracks(List<string> ids, string market = "")
{
return string.IsNullOrEmpty(market)
? $"{APIBase}/tracks?ids={string.Join(",", ids.Take(50))}"
: $"{APIBase}/tracks?market={market}&ids={string.Join(",", ids.Take(50))}";
return string.IsNullOrEmpty(market) ?
$"{APIBase}/tracks?ids={string.Join(",", ids.Take(50))}" :
$"{APIBase}/tracks?market={market}&ids={string.Join(",", ids.Take(50))}";
}
/// <summary>
@ -1001,9 +1001,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string GetPlayingTrack(string market = "")
{
return string.IsNullOrEmpty(market)
? $"{APIBase}/me/player/currently-playing"
: $"{APIBase}/me/player/currently-playing?market={market}";
return string.IsNullOrEmpty(market) ?
$"{APIBase}/me/player/currently-playing" :
$"{APIBase}/me/player/currently-playing?market={market}";
}
/// <summary>
@ -1022,9 +1022,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string ResumePlayback(string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/play"
: $"{APIBase}/me/player/play?device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/play" :
$"{APIBase}/me/player/play?device_id={deviceId}";
}
/// <summary>
@ -1034,9 +1034,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string PausePlayback(string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/pause"
: $"{APIBase}/me/player/pause?device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/pause" :
$"{APIBase}/me/player/pause?device_id={deviceId}";
}
/// <summary>
@ -1046,9 +1046,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string SkipPlaybackToNext(string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/next"
: $"{APIBase}/me/player/next?device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/next" :
$"{APIBase}/me/player/next?device_id={deviceId}";
}
/// <summary>
@ -1060,9 +1060,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string SkipPlaybackToPrevious(string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/previous"
: $"{APIBase}/me/player/previous?device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/previous" :
$"{APIBase}/me/player/previous?device_id={deviceId}";
}
/// <summary>
@ -1074,9 +1074,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string SeekPlayback(int positionMs, string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/seek?position_ms={positionMs}"
: $"{APIBase}/me/player/seek?position_ms={positionMs}&device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/seek?position_ms={positionMs}" :
$"{APIBase}/me/player/seek?position_ms={positionMs}&device_id={deviceId}";
}
/// <summary>
@ -1087,9 +1087,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string SetRepeatMode(RepeatState repeatState, string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/repeat?state={repeatState.GetStringAttribute()}"
: $"{APIBase}/me/player/repeat?state={repeatState.GetStringAttribute()}&device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/repeat?state={repeatState.GetStringAttribute()}" :
$"{APIBase}/me/player/repeat?state={repeatState.GetStringAttribute()}&device_id={deviceId}";
}
/// <summary>
@ -1100,9 +1100,9 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string SetVolume(int volumePercent, string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/volume?volume_percent={volumePercent}"
: $"{APIBase}/me/player/volume?volume_percent={volumePercent}&device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/volume?volume_percent={volumePercent}" :
$"{APIBase}/me/player/volume?volume_percent={volumePercent}&device_id={deviceId}";
}
/// <summary>
@ -1113,9 +1113,22 @@ namespace SpotifyAPI.Web
/// <returns></returns>
public string SetShuffle(bool shuffle, string deviceId = "")
{
return string.IsNullOrEmpty(deviceId)
? $"{APIBase}/me/player/shuffle?state={shuffle}"
: $"{APIBase}/me/player/shuffle?state={shuffle}&device_id={deviceId}";
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/shuffle?state={shuffle}" :
$"{APIBase}/me/player/shuffle?state={shuffle}&device_id={deviceId}";
}
/// <summary>
/// Add an Item to the User's Playback Queue.
/// </summary>
/// <param name="uri">The uri of the item to add to the queue. Must be a track or an episode uri.</param>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the users currently active device is the target.</param>
/// <returns></returns>
public string AddToQueue(string uri, string deviceId = "")
{
return string.IsNullOrEmpty(deviceId) ?
$"{APIBase}/me/player/queue?uri={uri}" :
$"{APIBase}/me/player/queue?uri={uri}&device_id={deviceId}";
}
#endregion
}