Skip to content

Commit 98f3bf3

Browse files
author
Johnny @PC
committed
Added paylist-reordering
1 parent d0211fd commit 98f3bf3

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎SpotifyAPI/SpotifyAPI.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<Compile Include="SpotifyWebAPI\Models\SimpleAlbum.cs" />
8484
<Compile Include="SpotifyWebAPI\Models\SimpleArtist.cs" />
8585
<Compile Include="SpotifyWebAPI\Models\SimpleTrack.cs" />
86+
<Compile Include="SpotifyWebAPI\Models\Snapshot.cs" />
8687
<Compile Include="SpotifyWebAPI\Models\Token.cs" />
8788
<Compile Include="SpotifyWebAPI\Models\SimplePlaylist.cs" />
8889
<Compile Include="SpotifyWebAPI\Models\Paging.cs" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace SpotifyAPI.SpotifyWebAPI.Models
5+
{
6+
public class Snapshot : BasicModel
7+
{
8+
[JsonProperty("snapshot_id")]
9+
public String SnapshotId { get; set; }
10+
}
11+
}

‎SpotifyAPI/SpotifyWebAPI/SpotifyWebAPIClass.cs‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,25 @@ public ErrorResponse AddTracks(String userId, String playlistId, List<String> ur
161161
{
162162
if (position == int.MaxValue)
163163
return UploadData<ErrorResponse>("https://api.spotify.com/v1/users/" + userId + "/playlists/" + playlistId + "/tracks", JsonConvert.SerializeObject(uris));
164-
else
165-
{
166-
String tracks = string.Join(",", uris);
167-
return UploadData<ErrorResponse>("https://api.spotify.com/v1/users/" + userId + "/playlists/" + playlistId + "/tracks?position=" + position
168-
+ "&ids=" + tracks
169-
, JsonConvert.SerializeObject(uris));
170-
}
164+
String tracks = string.Join(",", uris);
165+
return UploadData<ErrorResponse>("https://api.spotify.com/v1/users/" + userId + "/playlists/" + playlistId + "/tracks?position=" + position
166+
+ "&ids=" + tracks
167+
, JsonConvert.SerializeObject(uris));
168+
}
169+
170+
public Snapshot ReorderPlaylist(String userId, String playlistId, int rangeStart, int rangeLength,
171+
int insertBefore, String snapshotId = "")
172+
{
173+
JObject ob = new JObject();
174+
ob.Add("range_start", rangeStart);
175+
ob.Add("range_length", rangeLength);
176+
ob.Add("insert_before", insertBefore);
177+
if(snapshotId != "")
178+
ob.Add("snapshot_id", snapshotId);
179+
return
180+
UploadData<Snapshot>(
181+
"https://api.spotify.com/v1/users/" + userId + "/playlists/" + playlistId + "/tracks",
182+
ob.ToString(Formatting.None), "PUT");
171183
}
172184
public FeaturedPlaylists GetFeaturedPlaylists(String locale = "", String country = "", DateTime timestamp = default(DateTime), int limit = 20, int offset = 0)
173185
{

0 commit comments

Comments
 (0)