Skip to content

Commit 870b13e

Browse files
committed
Finished shows, started playlists
1 parent be7bdb6 commit 870b13e

26 files changed

Lines changed: 337 additions & 28 deletions
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 IPlaylistsClient
6+
{
7+
Task<SnapshotResponse> RemoveItems(string playlistId, PlaylistRemoveItemsRequest request);
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Threading.Tasks;
2+
3+
namespace SpotifyAPI.Web
4+
{
5+
public interface IShowsClient
6+
{
7+
Task<FullShow> Get(string showId);
8+
Task<FullShow> Get(string showId, ShowRequest request);
9+
10+
Task<ShowsResponse> GetSeveral(ShowsRequest request);
11+
12+
Task<Paging<SimpleEpisode>> GetEpisodes(string showId);
13+
Task<Paging<SimpleEpisode>> GetEpisodes(string showId, ShowEpisodesRequest request);
14+
}
15+
}

‎SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ public interface ISpotifyClient
55
IUserProfileClient UserProfile { get; }
66

77
IBrowseClient Browse { get; }
8+
9+
IShowsClient Shows { get; }
10+
11+
IPlaylistsClient Playlists { get; }
812
}
913
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 PlaylistsClient : APIClient, IPlaylistsClient
8+
{
9+
public PlaylistsClient(IAPIConnector connector) : base(connector) { }
10+
11+
public Task<SnapshotResponse> RemoveItems(string playlistId, PlaylistRemoveItemsRequest request)
12+
{
13+
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
14+
Ensure.ArgumentNotNull(request, nameof(request));
15+
16+
return API.Delete<SnapshotResponse>(URLs.PlaylistTracks(playlistId), null, request.BuildBodyParams());
17+
}
18+
}
19+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 ShowsClient : APIClient, IShowsClient
8+
{
9+
public ShowsClient(IAPIConnector connector) : base(connector) { }
10+
11+
public Task<FullShow> Get(string showId)
12+
{
13+
Ensure.ArgumentNotNullOrEmptyString(showId, nameof(showId));
14+
15+
return API.Get<FullShow>(URLs.Show(showId));
16+
}
17+
18+
public Task<FullShow> Get(string showId, ShowRequest request)
19+
{
20+
Ensure.ArgumentNotNullOrEmptyString(showId, nameof(showId));
21+
Ensure.ArgumentNotNull(request, nameof(request));
22+
23+
return API.Get<FullShow>(URLs.Show(showId), request.BuildQueryParams());
24+
}
25+
26+
public Task<ShowsResponse> GetSeveral(ShowsRequest request)
27+
{
28+
Ensure.ArgumentNotNull(request, nameof(request));
29+
30+
return API.Get<ShowsResponse>(URLs.Shows(), request.BuildQueryParams());
31+
}
32+
33+
public Task<Paging<SimpleEpisode>> GetEpisodes(string showId)
34+
{
35+
Ensure.ArgumentNotNullOrEmptyString(showId, nameof(showId));
36+
37+
return API.Get<Paging<SimpleEpisode>>(URLs.ShowEpisodes(showId));
38+
}
39+
40+
public Task<Paging<SimpleEpisode>> GetEpisodes(string showId, ShowEpisodesRequest request)
41+
{
42+
Ensure.ArgumentNotNullOrEmptyString(showId, nameof(showId));
43+
Ensure.ArgumentNotNull(request, nameof(request));
44+
45+
return API.Get<Paging<SimpleEpisode>>(URLs.ShowEpisodes(showId), request.BuildQueryParams());
46+
}
47+
}
48+
}

‎SpotifyAPI.Web/Clients/SpotifyClient.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ public SpotifyClient(SpotifyClientConfig config)
1717
_apiConnector = config.CreateAPIConnector();
1818
UserProfile = new UserProfileClient(_apiConnector);
1919
Browse = new BrowseClient(_apiConnector);
20+
Shows = new ShowsClient(_apiConnector);
21+
Playlists = new PlaylistsClient(_apiConnector);
2022
}
2123

2224
public IUserProfileClient UserProfile { get; }
2325

2426
public IBrowseClient Browse { get; }
27+
28+
public IShowsClient Shows { get; }
29+
30+
public IPlaylistsClient Playlists { get; }
2531
}
2632
}

‎SpotifyAPI.Web/Clients/SpotifyClientConfig.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ IRetryHandler retryHandler
3838

3939
internal IAPIConnector CreateAPIConnector()
4040
{
41-
Ensure.PropertyNotNull(BaseAddress, nameof(BaseAddress));
42-
Ensure.PropertyNotNull(Authenticator, nameof(Authenticator),
41+
Ensure.ArgumentNotNull(BaseAddress, nameof(BaseAddress));
42+
Ensure.ArgumentNotNull(Authenticator, nameof(Authenticator),
4343
". Use WithToken or WithAuthenticator to specify a authentication");
44-
Ensure.PropertyNotNull(JSONSerializer, nameof(JSONSerializer));
45-
Ensure.PropertyNotNull(HTTPClient, nameof(HTTPClient));
44+
Ensure.ArgumentNotNull(JSONSerializer, nameof(JSONSerializer));
45+
Ensure.ArgumentNotNull(HTTPClient, nameof(HTTPClient));
4646

4747
return new APIConnector(BaseAddress, Authenticator, JSONSerializer, HTTPClient, RetryHandler);
4848
}

‎SpotifyAPI.Web/Http/APIConnector.cs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ public async Task<T> SendAPIRequest<T>(
135135
_jsonSerializer.SerializeRequest(request);
136136
await _authenticator.Apply(request).ConfigureAwait(false);
137137
IResponse response = await _httpClient.DoRequest(request).ConfigureAwait(false);
138-
response = await _retryHandler?.HandleRetry(request, response, async (newRequest) =>
138+
if (_retryHandler != null)
139139
{
140-
await _authenticator.Apply(newRequest).ConfigureAwait(false);
141-
return await _httpClient.DoRequest(request).ConfigureAwait(false);
142-
});
140+
response = await _retryHandler?.HandleRetry(request, response, async (newRequest) =>
141+
{
142+
await _authenticator.Apply(newRequest).ConfigureAwait(false);
143+
return await _httpClient.DoRequest(request).ConfigureAwait(false);
144+
});
145+
}
143146
ProcessErrors(response);
144147

145148
IAPIResponse<T> apiResponse = _jsonSerializer.DeserializeResponse<T>(response);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace SpotifyAPI.Web
5+
{
6+
public class PlaylistRemoveItemsRequest : RequestParams
7+
{
8+
[BodyParam("tracks")]
9+
public List<Item> Tracks { get; set; }
10+
[BodyParam("snapshot_id")]
11+
public string SnapshotId { get; set; }
12+
13+
protected override void CustomEnsure()
14+
{
15+
Ensure.ArgumentNotNullOrEmptyList(Tracks, nameof(Tracks));
16+
}
17+
18+
public class Item
19+
{
20+
public Item(string uri)
21+
{
22+
Uri = uri;
23+
}
24+
[JsonProperty("uri")]
25+
public string Uri { get; set; }
26+
}
27+
}
28+
}

‎SpotifyAPI.Web/Models/Request/RecommendationsRequest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public RecommendationsRequest()
3131
public Dictionary<string, string> Max { get; set; }
3232
public Dictionary<string, string> Target { get; set; }
3333

34-
protected override void Ensure()
34+
protected override void CustomEnsure()
3535
{
3636
if (string.IsNullOrEmpty(SeedTracks) && string.IsNullOrEmpty(SeedGenres) && string.IsNullOrEmpty(SeedArtists))
3737
{

0 commit comments

Comments
 (0)