Skip to content

Commit 73976e0

Browse files
author
Jonas Dellinger
committed
Added missing async methods
1 parent df53f75 commit 73976e0

1 file changed

Lines changed: 182 additions & 0 deletions

File tree

‎SpotifyAPI/Web/SpotifyWebAPI.cs‎

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,15 @@ public AvailabeDevices GetDevices()
18641864
return DownloadData<AvailabeDevices>(_builder.GetDevices());
18651865
}
18661866

1867+
/// <summary>
1868+
/// Get information about a user’s available devices.
1869+
/// </summary>
1870+
/// <returns></returns>
1871+
public Task<AvailabeDevices> GetDevicesAsync()
1872+
{
1873+
return DownloadDataAsync<AvailabeDevices>(_builder.GetDevices());
1874+
}
1875+
18671876
/// <summary>
18681877
/// Get information about the user’s current playback state, including track, track progress, and active device.
18691878
/// </summary>
@@ -1874,6 +1883,16 @@ public PlaybackContext GetPlayback(string market = "")
18741883
return DownloadData<PlaybackContext>(_builder.GetPlayback(market));
18751884
}
18761885

1886+
/// <summary>
1887+
/// Get information about the user’s current playback state, including track, track progress, and active device.
1888+
/// </summary>
1889+
/// <param name="market">An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.</param>
1890+
/// <returns></returns>
1891+
public Task<PlaybackContext> GetPlaybackAsync(string market = "")
1892+
{
1893+
return DownloadDataAsync<PlaybackContext>(_builder.GetPlayback(market));
1894+
}
1895+
18771896
/// <summary>
18781897
/// Get the object currently being played on the user’s Spotify account.
18791898
/// </summary>
@@ -1884,6 +1903,16 @@ public PlaybackContext GetPlayingTrack(string market = "")
18841903
return DownloadData<PlaybackContext>(_builder.GetPlayingTrack(market));
18851904
}
18861905

1906+
/// <summary>
1907+
/// Get the object currently being played on the user’s Spotify account.
1908+
/// </summary>
1909+
/// <param name="market">An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.</param>
1910+
/// <returns></returns>
1911+
public Task<PlaybackContext> GetPlayingTrackAsync(string market = "")
1912+
{
1913+
return DownloadDataAsync<PlaybackContext>(_builder.GetPlayingTrack(market));
1914+
}
1915+
18871916
/// <summary>
18881917
/// Transfer playback to a new device and determine if it should start playing.
18891918
/// </summary>
@@ -1896,6 +1925,18 @@ public PlaybackContext GetPlayingTrack(string market = "")
18961925
public ErrorResponse TransferPlayback(string deviceId, bool play = false) => TransferPlayback(
18971926
new List<string> { deviceId }, play);
18981927

1928+
/// <summary>
1929+
/// Transfer playback to a new device and determine if it should start playing.
1930+
/// </summary>
1931+
/// <param name="deviceId">ID of the device on which playback should be started/transferred to</param>
1932+
/// <param name="play">
1933+
/// true: ensure playback happens on new device.
1934+
/// false or not provided: keep the current playback state.
1935+
/// </param>
1936+
/// <returns></returns>
1937+
public Task<ErrorResponse> TransferPlaybackAsync(string deviceId, bool play = false) => TransferPlaybackAsync(
1938+
new List<string> { deviceId }, play);
1939+
18991940
/// <summary>
19001941
/// Transfer playback to a new device and determine if it should start playing.
19011942
/// 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 @@ public ErrorResponse TransferPlayback(List<string> deviceIds, bool play = false)
19161957
return UploadData<ErrorResponse>(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT");
19171958
}
19181959

1960+
/// <summary>
1961+
/// Transfer playback to a new device and determine if it should start playing.
1962+
/// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request
1963+
/// </summary>
1964+
/// <param name="deviceIds">A array containing the ID of the device on which playback should be started/transferred.</param>
1965+
/// <param name="play">
1966+
/// true: ensure playback happens on new device.
1967+
/// false or not provided: keep the current playback state.
1968+
/// </param>
1969+
/// <returns></returns>
1970+
public Task<ErrorResponse> TransferPlaybackAsync(List<string> deviceIds, bool play = false)
1971+
{
1972+
JObject ob = new JObject()
1973+
{
1974+
{ "play", play },
1975+
{ "device_ids", new JArray(deviceIds) }
1976+
};
1977+
return UploadDataAsync<ErrorResponse>(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT");
1978+
}
1979+
19191980
/// <summary>
19201981
/// Start a new context or resume current playback on the user’s active device.
19211982
/// </summary>
@@ -1938,6 +1999,28 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = ""
19381999
return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
19392000
}
19402001

2002+
/// <summary>
2003+
/// Start a new context or resume current playback on the user’s active device.
2004+
/// </summary>
2005+
/// <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>
2006+
/// <param name="contextUri">Spotify URI of the context to play.</param>
2007+
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
2008+
/// <param name="offset">Indicates from where in the context playback should start.
2009+
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
2010+
/// <returns></returns>
2011+
public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string contextUri = "", List<string> uris = null,
2012+
int? offset = null)
2013+
{
2014+
JObject ob = new JObject();
2015+
if (!string.IsNullOrEmpty(contextUri))
2016+
ob.Add("context_uri", contextUri);
2017+
if (uris != null)
2018+
ob.Add("uris", new JArray(uris));
2019+
if (offset != null)
2020+
ob.Add("offset", new JObject { { "position", offset } });
2021+
return UploadDataAsync<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
2022+
}
2023+
19412024
/// <summary>
19422025
/// Start a new context or resume current playback on the user’s active device.
19432026
/// </summary>
@@ -1960,6 +2043,28 @@ public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = ""
19602043
return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
19612044
}
19622045

2046+
/// <summary>
2047+
/// Start a new context or resume current playback on the user’s active device.
2048+
/// </summary>
2049+
/// <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>
2050+
/// <param name="contextUri">Spotify URI of the context to play.</param>
2051+
/// <param name="uris">A JSON array of the Spotify track URIs to play.</param>
2052+
/// <param name="offset">Indicates from where in the context playback should start.
2053+
/// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param>
2054+
/// <returns></returns>
2055+
public Task<ErrorResponse> ResumePlaybackAsync(string deviceId = "", string contextUri = "", List<string> uris = null,
2056+
string offset = "")
2057+
{
2058+
JObject ob = new JObject();
2059+
if (!string.IsNullOrEmpty(contextUri))
2060+
ob.Add("context_uri", contextUri);
2061+
if (uris != null)
2062+
ob.Add("uris", new JArray(uris));
2063+
if (!string.IsNullOrEmpty(offset))
2064+
ob.Add("offset", new JObject { { "uri", offset } });
2065+
return UploadDataAsync<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT");
2066+
}
2067+
19632068
/// <summary>
19642069
/// Pause playback on the user’s account.
19652070
/// </summary>
@@ -1970,6 +2075,16 @@ public ErrorResponse PausePlayback(string deviceId = "")
19702075
return UploadData<ErrorResponse>(_builder.PausePlayback(deviceId), string.Empty, "PUT");
19712076
}
19722077

2078+
/// <summary>
2079+
/// Pause playback on the user’s account.
2080+
/// </summary>
2081+
/// <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>
2082+
/// <returns></returns>
2083+
public Task<ErrorResponse> PausePlaybackAsync(string deviceId = "")
2084+
{
2085+
return UploadDataAsync<ErrorResponse>(_builder.PausePlayback(deviceId), string.Empty, "PUT");
2086+
}
2087+
19732088
/// <summary>
19742089
/// Skips to next track in the user’s queue.
19752090
/// </summary>
@@ -1980,6 +2095,16 @@ public ErrorResponse SkipPlaybackToNext(string deviceId = "")
19802095
return UploadData<ErrorResponse>(_builder.SkipPlaybackToNext(deviceId), string.Empty);
19812096
}
19822097

2098+
/// <summary>
2099+
/// Skips to next track in the user’s queue.
2100+
/// </summary>
2101+
/// <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>
2102+
/// <returns></returns>
2103+
public Task<ErrorResponse> SkipPlaybackToNextAsync(string deviceId = "")
2104+
{
2105+
return UploadDataAsync<ErrorResponse>(_builder.SkipPlaybackToNext(deviceId), string.Empty);
2106+
}
2107+
19832108
/// <summary>
19842109
/// Skips to previous track in the user’s queue.
19852110
/// Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress.
@@ -1992,6 +2117,18 @@ public ErrorResponse SkipPlaybackToPrevious(string deviceId = "")
19922117
return UploadData<ErrorResponse>(_builder.SkipPlaybackToPrevious(deviceId), string.Empty);
19932118
}
19942119

2120+
/// <summary>
2121+
/// Skips to previous track in the user’s queue.
2122+
/// Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress.
2123+
/// Returning to the start of the current track should be performed using the https://api.spotify.com/v1/me/player/seek endpoint.
2124+
/// </summary>
2125+
/// <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>
2126+
/// <returns></returns>
2127+
public Task<ErrorResponse> SkipPlaybackToPreviousAsync(string deviceId = "")
2128+
{
2129+
return UploadDataAsync<ErrorResponse>(_builder.SkipPlaybackToPrevious(deviceId), string.Empty);
2130+
}
2131+
19952132
/// <summary>
19962133
/// Seeks to the given position in the user’s currently playing track.
19972134
/// </summary>
@@ -2004,6 +2141,18 @@ public ErrorResponse SeekPlayback(int positionMs, string deviceId = "")
20042141
return UploadData<ErrorResponse>(_builder.SeekPlayback(positionMs, deviceId), string.Empty, "PUT");
20052142
}
20062143

2144+
/// <summary>
2145+
/// Seeks to the given position in the user’s currently playing track.
2146+
/// </summary>
2147+
/// <param name="positionMs">The position in milliseconds to seek to. Must be a positive number.
2148+
/// Passing in a position that is greater than the length of the track will cause the player to start playing the next song.</param>
2149+
/// <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>
2150+
/// <returns></returns>
2151+
public Task<ErrorResponse> SeekPlaybackAsync(int positionMs, string deviceId = "")
2152+
{
2153+
return UploadDataAsync<ErrorResponse>(_builder.SeekPlayback(positionMs, deviceId), string.Empty, "PUT");
2154+
}
2155+
20072156
/// <summary>
20082157
/// Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off.
20092158
/// </summary>
@@ -2015,6 +2164,17 @@ public ErrorResponse SetRepeatMode(RepeatState state, string deviceId = "")
20152164
return UploadData<ErrorResponse>(_builder.SetRepeatMode(state, deviceId), string.Empty, "PUT");
20162165
}
20172166

2167+
/// <summary>
2168+
/// Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off.
2169+
/// </summary>
2170+
/// <param name="state">track, context or off. </param>
2171+
/// <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>
2172+
/// <returns></returns>
2173+
public Task<ErrorResponse> SetRepeatModeAsync(RepeatState state, string deviceId = "")
2174+
{
2175+
return UploadDataAsync<ErrorResponse>(_builder.SetRepeatMode(state, deviceId), string.Empty, "PUT");
2176+
}
2177+
20182178
/// <summary>
20192179
/// Set the volume for the user’s current playback device.
20202180
/// </summary>
@@ -2026,6 +2186,17 @@ public ErrorResponse SetVolume(int volumePercent, string deviceId = "")
20262186
return UploadData<ErrorResponse>(_builder.SetVolume(volumePercent, deviceId), string.Empty, "PUT");
20272187
}
20282188

2189+
/// <summary>
2190+
/// Set the volume for the user’s current playback device.
2191+
/// </summary>
2192+
/// <param name="volumePercent">Integer. The volume to set. Must be a value from 0 to 100 inclusive.</param>
2193+
/// <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>
2194+
/// <returns></returns>
2195+
public Task<ErrorResponse> SetVolumeAsync(int volumePercent, string deviceId = "")
2196+
{
2197+
return UploadDataAsync<ErrorResponse>(_builder.SetVolume(volumePercent, deviceId), string.Empty, "PUT");
2198+
}
2199+
20292200
/// <summary>
20302201
/// Toggle shuffle on or off for user’s playback.
20312202
/// </summary>
@@ -2037,6 +2208,17 @@ public ErrorResponse SetShuffle(bool shuffle, string deviceId = "")
20372208
return UploadData<ErrorResponse>(_builder.SetShuffle(shuffle, deviceId), string.Empty, "PUT");
20382209
}
20392210

2211+
/// <summary>
2212+
/// Toggle shuffle on or off for user’s playback.
2213+
/// </summary>
2214+
/// <param name="shuffle">True or False</param>
2215+
/// <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>
2216+
/// <returns></returns>
2217+
public Task<ErrorResponse> SetShuffleAsync(bool shuffle, string deviceId = "")
2218+
{
2219+
return UploadDataAsync<ErrorResponse>(_builder.SetShuffle(shuffle, deviceId), string.Empty, "PUT");
2220+
}
2221+
20402222
#endregion
20412223

20422224
#region Util

0 commit comments

Comments
 (0)