Skip to content

Commit 7c94de2

Browse files
committed
Allow Enum in QueryParams and added more endpoints
1 parent c9a3740 commit 7c94de2

18 files changed

Lines changed: 222 additions & 15 deletions

SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ public interface IPlaylistsClient
2929
Task<Paging<SimplePlaylist>> CurrentUsers(PlaylistCurrentUsersRequest request);
3030

3131
Task<bool> ChangeDetails(string playlistId, PlaylistChangeDetailsRequest request);
32+
33+
Task<SnapshotResponse> ReorderItems(string playlistId, PlaylistReorderItemsRequest request);
3234
}
3335
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace SpotifyAPI.Web
4+
{
5+
public interface ISearchClient
6+
{
7+
Task<SearchResponse> Item(SearchRequest request);
8+
}
9+
}

SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ public interface ISpotifyClient
99
IShowsClient Shows { get; }
1010

1111
IPlaylistsClient Playlists { get; }
12+
13+
ISearchClient Search { get; }
1214
}
1315
}

SpotifyAPI.Web/Clients/PlaylistsClient.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,13 @@ public async Task<bool> ChangeDetails(string playlistId, PlaylistChangeDetailsRe
126126
var statusCode = await API.Put(URLs.Playlist(playlistId), null, request.BuildBodyParams());
127127
return statusCode == HttpStatusCode.OK;
128128
}
129+
130+
public Task<SnapshotResponse> ReorderItems(string playlistId, PlaylistReorderItemsRequest request)
131+
{
132+
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
133+
Ensure.ArgumentNotNull(request, nameof(request));
134+
135+
return API.Put<SnapshotResponse>(URLs.PlaylistTracks(playlistId), null, request.BuildBodyParams());
136+
}
129137
}
130138
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Threading.Tasks;
2+
using SpotifyAPI.Web.Http;
3+
using URLs = SpotifyAPI.Web.SpotifyUrls;
4+
5+
namespace SpotifyAPI.Web
6+
{
7+
public class SearchClient : APIClient, ISearchClient
8+
{
9+
public SearchClient(IAPIConnector apiConnector) : base(apiConnector) { }
10+
11+
public Task<SearchResponse> Item(SearchRequest request)
12+
{
13+
Ensure.ArgumentNotNull(request, nameof(request));
14+
15+
return API.Get<SearchResponse>(URLs.Search(), request.BuildQueryParams());
16+
}
17+
}
18+
}

SpotifyAPI.Web/Clients/SpotifyClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public SpotifyClient(SpotifyClientConfig config)
1919
Browse = new BrowseClient(_apiConnector);
2020
Shows = new ShowsClient(_apiConnector);
2121
Playlists = new PlaylistsClient(_apiConnector);
22+
Search = new SearchClient(_apiConnector);
2223
}
2324

2425
public IUserProfileClient UserProfile { get; }
@@ -28,5 +29,7 @@ public SpotifyClient(SpotifyClientConfig config)
2829
public IShowsClient Shows { get; }
2930

3031
public IPlaylistsClient Playlists { get; }
32+
33+
public ISearchClient Search { get; }
3134
}
3235
}

SpotifyAPI.Web/Clients/SpotifyClientConfig.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ IHTTPLogger httpLogger
4343
internal IAPIConnector CreateAPIConnector()
4444
{
4545
Ensure.ArgumentNotNull(BaseAddress, nameof(BaseAddress));
46-
Ensure.ArgumentNotNull(Authenticator, nameof(Authenticator),
47-
". Use WithToken or WithAuthenticator to specify a authentication");
46+
Ensure.ArgumentNotNull(Authenticator, nameof(Authenticator));
4847
Ensure.ArgumentNotNull(JSONSerializer, nameof(JSONSerializer));
4948
Ensure.ArgumentNotNull(HTTPClient, nameof(HTTPClient));
5049

SpotifyAPI.Web/Models/Request/PlaylistGetItemsRequest.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace SpotifyAPI.Web
@@ -6,7 +7,7 @@ public class PlaylistGetItemsRequest : RequestParams
67
{
78
public PlaylistGetItemsRequest()
89
{
9-
AdditionalTypes = new List<string>() { "track", "episode" };
10+
AdditionalTypes = AdditionalType.All;
1011
}
1112

1213
[QueryParam("fields")]
@@ -26,6 +27,16 @@ public PlaylistGetItemsRequest()
2627
/// </summary>
2728
/// <value></value>
2829
[QueryParam("additional_types")]
29-
public List<string> AdditionalTypes { get; set; }
30+
public AdditionalType AdditionalTypes { get; set; }
31+
32+
[Flags]
33+
public enum AdditionalType
34+
{
35+
[String("track")]
36+
Track = 0,
37+
[String("episode")]
38+
Episode = 1,
39+
All = Track | Episode
40+
}
3041
}
3142
}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace SpotifyAPI.Web
@@ -6,14 +7,24 @@ public class PlaylistGetRequest : RequestParams
67
{
78
public PlaylistGetRequest()
89
{
9-
AdditionalTypes = new List<string> { "track", "episode" };
10+
AdditionalTypes = AdditionalType.All;
1011
}
1112

1213
/// <summary>
1314
/// This is set to `"track", "episode"` by default.
1415
/// </summary>
1516
/// <value></value>
1617
[QueryParam("additional_types")]
17-
public List<string> AdditionalTypes { get; set; }
18+
public AdditionalType AdditionalTypes { get; set; }
19+
20+
[Flags]
21+
public enum AdditionalType
22+
{
23+
[String("track")]
24+
Track = 0,
25+
[String("episode")]
26+
Episode = 1,
27+
All = Track | Episode
28+
}
1829
}
1930
}

SpotifyAPI.Web/Models/Request/PlaylistRemoveItemsRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ namespace SpotifyAPI.Web
55
{
66
public class PlaylistRemoveItemsRequest : RequestParams
77
{
8-
public PlaylistRemoveItemsRequest(List<Item> tracks)
9-
{
10-
Tracks = tracks;
11-
}
12-
138
[BodyParam("tracks")]
149
public List<Item> Tracks { get; set; }
10+
1511
[BodyParam("snapshot_id")]
1612
public string SnapshotId { get; set; }
1713

@@ -26,8 +22,12 @@ public Item(string uri)
2622
{
2723
Uri = uri;
2824
}
25+
2926
[JsonProperty("uri")]
3027
public string Uri { get; set; }
28+
29+
[JsonProperty("positions", NullValueHandling = NullValueHandling.Ignore)]
30+
public List<int> Positions { get; set; }
3131
}
3232
}
3333
}

0 commit comments

Comments
 (0)