Added missing async methods

This commit is contained in:
Jonas Dellinger 2018-07-27 00:29:10 +02:00
parent df53f75368
commit 73976e0d6b

View File

@ -1864,6 +1864,15 @@ namespace SpotifyAPI.Web
return DownloadData<AvailabeDevices>(_builder.GetDevices());
}
/// <summary>
/// Get information about a users available devices.
/// </summary>
/// <returns></returns>
public Task<AvailabeDevices> GetDevicesAsync()
{
return DownloadDataAsync<AvailabeDevices>(_builder.GetDevices());
}
/// <summary>
/// Get information about the users current playback state, including track, track progress, and active device.
/// </summary>
@ -1874,6 +1883,16 @@ namespace SpotifyAPI.Web
return DownloadData<PlaybackContext>(_builder.GetPlayback(market));
}
/// <summary>
/// Get information about the users current playback state, including track, track progress, and active device.
/// </summary>
/// <param name="market">An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.</param>
/// <returns></returns>
public Task<PlaybackContext> GetPlaybackAsync(string market = "")
{
return DownloadDataAsync<PlaybackContext>(_builder.GetPlayback(market));
}
/// <summary>
/// Get the object currently being played on the users Spotify account.
/// </summary>
@ -1884,6 +1903,16 @@ namespace SpotifyAPI.Web
return DownloadData<PlaybackContext>(_builder.GetPlayingTrack(market));
}
/// <summary>
/// Get the object currently being played on the users Spotify account.
/// </summary>
/// <param name="market">An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.</param>
/// <returns></returns>
public Task<PlaybackContext> GetPlayingTrackAsync(string market = "")
{
return DownloadDataAsync<PlaybackContext>(_builder.GetPlayingTrack(market));
}
/// <summary>
/// Transfer playback to a new device and determine if it should start playing.
/// </summary>
@ -1896,6 +1925,18 @@ namespace SpotifyAPI.Web
public ErrorResponse TransferPlayback(string deviceId, bool play = false) => TransferPlayback(
new List<string> { deviceId }, play);
/// <summary>
/// Transfer playback to a new device and determine if it should start playing.
/// </summary>
/// <param name="deviceId">ID of the device on which playback should be started/transferred to</param>
/// <param name="play">
/// true: ensure playback happens on new device.
/// false or not provided: keep the current playback state.
/// </param>
/// <returns></returns>
public Task<ErrorResponse> TransferPlaybackAsync(string deviceId, bool play = false) => TransferPlaybackAsync(
new List<string> { deviceId }, play);
/// <summary>
/// Transfer playback to a new device and determine if it should start playing.
/// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request
@ -1916,6 +1957,26 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT");
}
/// <summary>
/// Transfer playback to a new device and determine if it should start playing.
/// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request
/// </summary>
/// <param name="deviceIds">A array containing the ID of the device on which playback should be started/transferred.</param>
/// <param name="play">
/// true: ensure playback happens on new device.
/// false or not provided: keep the current playback state.
/// </param>
/// <returns></returns>
public Task<ErrorResponse> TransferPlaybackAsync(List<string> deviceIds, bool play = false)
{
JObject ob = new JObject()
{
{ "play", play },
{ "device_ids", new JArray(deviceIds) }
};
return UploadDataAsync<ErrorResponse>(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT");
}
/// <summary>
/// Start a new context or resume current playback on the users active device.
/// </summary>
@ -1938,6 +1999,28 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
}
/// <summary>
/// Start a new context or resume current playback on the users active device.
/// </summary>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <param name="contextUri">Spotify URI of the context to play.</param>
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
/// <param name="offset">Indicates from where in the context playback should start.
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
/// <returns></returns>
public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string contextUri = "", List<string> uris = null,
int? offset = null)
{
JObject ob = new JObject();
if (!string.IsNullOrEmpty(contextUri))
ob.Add("context_uri", contextUri);
if (uris != null)
ob.Add("uris", new JArray(uris));
if (offset != null)
ob.Add("offset", new JObject { { "position", offset } });
return UploadDataAsync<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
}
/// <summary>
/// Start a new context or resume current playback on the users active device.
/// </summary>
@ -1960,6 +2043,28 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
}
/// <summary>
/// Start a new context or resume current playback on the users active device.
/// </summary>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <param name="contextUri">Spotify URI of the context to play.</param>
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
/// <param name="offset">Indicates from where in the context playback should start.
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
/// <returns></returns>
public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string contextUri = "", List<string> uris = null,
string offset = "")
{
JObject ob = new JObject();
if (!string.IsNullOrEmpty(contextUri))
ob.Add("context_uri", contextUri);
if (uris != null)
ob.Add("uris", new JArray(uris));
if (!string.IsNullOrEmpty(offset))
ob.Add("offset", new JObject { { "uri", offset } });
return UploadDataAsync<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
}
/// <summary>
/// Pause playback on the users account.
/// </summary>
@ -1970,6 +2075,16 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.PausePlayback(deviceId), string.Empty, "PUT");
}
/// <summary>
/// Pause playback on the users account.
/// </summary>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> PausePlaybackAsync(string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.PausePlayback(deviceId), string.Empty, "PUT");
}
/// <summary>
/// Skips to next track in the users queue.
/// </summary>
@ -1980,6 +2095,16 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.SkipPlaybackToNext(deviceId), string.Empty);
}
/// <summary>
/// Skips to next track in the users queue.
/// </summary>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> SkipPlaybackToNextAsync(string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.SkipPlaybackToNext(deviceId), string.Empty);
}
/// <summary>
/// Skips to previous track in the users queue.
/// Note that this will ALWAYS skip to the previous track, regardless of the current tracks progress.
@ -1992,6 +2117,18 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.SkipPlaybackToPrevious(deviceId), string.Empty);
}
/// <summary>
/// Skips to previous track in the users queue.
/// Note that this will ALWAYS skip to the previous track, regardless of the current tracks progress.
/// Returning to the start of the current track should be performed using the https://api.spotify.com/v1/me/player/seek endpoint.
/// </summary>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> SkipPlaybackToPreviousAsync(string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.SkipPlaybackToPrevious(deviceId), string.Empty);
}
/// <summary>
/// Seeks to the given position in the users currently playing track.
/// </summary>
@ -2004,6 +2141,18 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.SeekPlayback(positionMs, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Seeks to the given position in the users currently playing track.
/// </summary>
/// <param name="positionMs">The position in milliseconds to seek to. Must be a positive number.
/// Passing in a position that is greater than the length of the track will cause the player to start playing the next song.</param>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> SeekPlaybackAsync(int positionMs, string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.SeekPlayback(positionMs, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Set the repeat mode for the users playback. Options are repeat-track, repeat-context, and off.
/// </summary>
@ -2015,6 +2164,17 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.SetRepeatMode(state, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Set the repeat mode for the users playback. Options are repeat-track, repeat-context, and off.
/// </summary>
/// <param name="state">track, context or off. </param>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> SetRepeatModeAsync(RepeatState state, string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.SetRepeatMode(state, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Set the volume for the users current playback device.
/// </summary>
@ -2026,6 +2186,17 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.SetVolume(volumePercent, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Set the volume for the users current playback device.
/// </summary>
/// <param name="volumePercent">Integer. The volume to set. Must be a value from 0 to 100 inclusive.</param>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> SetVolumeAsync(int volumePercent, string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.SetVolume(volumePercent, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Toggle shuffle on or off for users playback.
/// </summary>
@ -2037,6 +2208,17 @@ namespace SpotifyAPI.Web
return UploadData<ErrorResponse>(_builder.SetShuffle(shuffle, deviceId), string.Empty, "PUT");
}
/// <summary>
/// Toggle shuffle on or off for users playback.
/// </summary>
/// <param name="shuffle">True or False</param>
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
/// <returns></returns>
public Task<ErrorResponse> SetShuffleAsync(bool shuffle, string deviceId = "")
{
return UploadDataAsync<ErrorResponse>(_builder.SetShuffle(shuffle, deviceId), string.Empty, "PUT");
}
#endregion
#region Util