Skip to content

Commit b375878

Browse files
committed
Add support for Chapters endpoints
1 parent 0442c46 commit b375878

File tree

9 files changed

+179
-0
lines changed

9 files changed

+179
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using SpotifyAPI.Web.Http;
4+
using URLs = SpotifyAPI.Web.SpotifyUrls;
5+
6+
namespace SpotifyAPI.Web
7+
{
8+
public class ChaptersClient : APIClient, IChaptersClient
9+
{
10+
public ChaptersClient(IAPIConnector apiConnector) : base(apiConnector) { }
11+
12+
public Task<FullAudiobookChapter> Get(string chapterId, CancellationToken cancel = default)
13+
{
14+
Ensure.ArgumentNotNullOrEmptyString(chapterId, nameof(chapterId));
15+
16+
return API.Get<FullAudiobookChapter>(URLs.Chapter(chapterId), cancel);
17+
}
18+
19+
public Task<FullAudiobookChapter> Get(string chapterId, ChapterRequest request, CancellationToken cancel = default)
20+
{
21+
Ensure.ArgumentNotNullOrEmptyString(chapterId, nameof(chapterId));
22+
Ensure.ArgumentNotNull(request, nameof(request));
23+
24+
return API.Get<FullAudiobookChapter>(URLs.Chapter(chapterId), request.BuildQueryParams(), cancel);
25+
}
26+
27+
public Task<ChaptersResponse> GetSeveral(ChaptersRequest request, CancellationToken cancel = default)
28+
{
29+
Ensure.ArgumentNotNull(request, nameof(request));
30+
31+
return API.Get<ChaptersResponse>(URLs.Chapters(), request.BuildQueryParams(), cancel);
32+
}
33+
}
34+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
namespace SpotifyAPI.Web
5+
{
6+
/// <summary>
7+
/// Endpoints for retrieving information about one or more chapters from the Spotify catalog.
8+
/// </summary>
9+
public interface IChaptersClient
10+
{
11+
/// <summary>
12+
/// Get Spotify catalog information for a single audiobook chapter. Chapters are only available within the US, UK, Canada, Ireland, New Zealand and Australia markets.
13+
/// </summary>
14+
/// <param name="chapterId">The Spotify ID for the chapter.</param>
15+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
16+
/// <remarks>
17+
/// https://developer.spotify.com/documentation/web-api/reference/get-a-chapter
18+
/// </remarks>
19+
/// <returns></returns>
20+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
21+
Task<FullAudiobookChapter> Get(string chapterId, CancellationToken cancel = default);
22+
23+
/// <summary>
24+
/// Get Spotify catalog information for a single audiobook chapter. Chapters are only available within the US, UK, Canada, Ireland, New Zealand and Australia markets.
25+
/// </summary>
26+
/// <param name="chapterId">The Spotify ID for the chapter.</param>
27+
/// <param name="request">The request-model which contains required and optional parameters.</param>
28+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
29+
/// <remarks>
30+
/// https://developer.spotify.com/documentation/web-api/reference/get-a-chapter
31+
/// </remarks>
32+
/// <returns></returns>
33+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
34+
Task<FullAudiobookChapter> Get(string chapterId, ChapterRequest request, CancellationToken cancel = default);
35+
36+
/// <summary>
37+
/// Get Spotify catalog information for several audiobook chapters identified by their Spotify IDs. Chapters are only available within the US, UK, Canada, Ireland, New Zealand and Australia markets.
38+
/// </summary>
39+
/// <param name="request">The request-model which contains required and optional parameters.</param>
40+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
41+
/// <remarks>
42+
/// https://developer.spotify.com/documentation/web-api/reference/get-several-chapters
43+
/// </remarks>
44+
/// <returns></returns>
45+
Task<ChaptersResponse> GetSeveral(ChaptersRequest request, CancellationToken cancel = default);
46+
}
47+
}

SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ public interface ISpotifyClient
9898
/// <value></value>
9999
IAudiobooksClient Audiobooks { get; }
100100

101+
/// <summary>
102+
/// Operations related to Spotify Audiobook Chapters
103+
/// </summary>
104+
/// <value></value>
105+
IChaptersClient Chapters { get; }
106+
101107
/// <summary>
102108
/// Returns the last response received by an API call.
103109
/// </summary>

SpotifyAPI.Web/Clients/SpotifyClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public SpotifyClient(SpotifyClientConfig config)
5353
Library = new LibraryClient(_apiConnector);
5454
Markets = new MarketsClient(_apiConnector);
5555
Audiobooks = new AudiobooksClient(_apiConnector);
56+
Chapters = new ChaptersClient(_apiConnector);
5657
}
5758

5859
public IPaginator DefaultPaginator { get; }
@@ -87,6 +88,8 @@ public SpotifyClient(SpotifyClientConfig config)
8788

8889
public IAudiobooksClient Audiobooks { get; }
8990

91+
public IChaptersClient Chapters { get; }
92+
9093
public IResponse? LastResponse { get; private set; }
9194

9295
/// <summary>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace SpotifyAPI.Web
2+
{
3+
public class ChapterRequest : RequestParams
4+
{
5+
/// <summary>
6+
/// The market you’d like to request. Synonym for country.
7+
/// </summary>
8+
/// <value></value>
9+
[QueryParam("market")]
10+
public string? Market { get; set; }
11+
12+
/// <summary>
13+
/// The desired language, consisting of an ISO 639-1 language code and an ISO 3166-1 alpha-2 country code,
14+
/// joined by an underscore. For example: es_MX, meaning "Spanish (Mexico)".
15+
/// Provide this parameter if you want the category strings returned in a particular language.
16+
/// Note that, if locale is not supplied, or if the specified language is not available,
17+
/// the category strings returned will be in the Spotify default language (American English).
18+
/// </summary>
19+
/// <value></value>
20+
[QueryParam("locale")]
21+
public string? Locale { get; set; }
22+
}
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
3+
namespace SpotifyAPI.Web
4+
{
5+
public class ChaptersRequest : RequestParams
6+
{
7+
/// <summary>
8+
/// ChaptersRequest
9+
/// </summary>
10+
/// <param name="ids">A comma-separated list of the Spotify IDs for the chapters. Maximum: 50 IDs.</param>
11+
public ChaptersRequest(IList<string> ids)
12+
{
13+
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
14+
15+
Ids = ids;
16+
}
17+
18+
/// <summary>
19+
/// A comma-separated list of the Spotify IDs for the chapters. Maximum: 20 IDs.
20+
/// </summary>
21+
/// <value></value>
22+
[QueryParam("ids")]
23+
public IList<string> Ids { get; }
24+
25+
/// <summary>
26+
/// An ISO 3166-1 alpha-2 country code or the string from_token.
27+
/// Provide this parameter if you want to apply Track Relinking.
28+
/// </summary>
29+
/// <value></value>
30+
[QueryParam("market")]
31+
public string? Market { get; set; }
32+
33+
/// <summary>
34+
/// The desired language, consisting of an ISO 639-1 language code and an ISO 3166-1 alpha-2 country code,
35+
/// joined by an underscore. For example: es_MX, meaning "Spanish (Mexico)".
36+
/// Provide this parameter if you want the category strings returned in a particular language.
37+
/// Note that, if locale is not supplied, or if the specified language is not available,
38+
/// the category strings returned will be in the Spotify default language (American English).
39+
/// </summary>
40+
/// <value></value>
41+
[QueryParam("locale")]
42+
public string? Locale { get; set; }
43+
}
44+
}
45+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace SpotifyAPI.Web
4+
{
5+
public class ChaptersResponse
6+
{
7+
public List<FullAudiobookChapter> Chapters { get; set; } = default!;
8+
}
9+
}
10+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SpotifyAPI.Web
2+
{
3+
public class FullAudiobookChapter : SimpleAudiobookChapter
4+
{
5+
public SimpleAudiobook Audiobook { get; set; } = default!;
6+
}
7+
}

SpotifyAPI.Web/SpotifyUrls.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public static class SpotifyUrls
145145

146146
public static Uri AudiobookChapters(string audiobookId) => EUri($"audiobooks/{audiobookId}/chapters");
147147

148+
public static Uri Chapters() => EUri($"chapters");
149+
150+
public static Uri Chapter(string chapterId) => EUri($"chapters/${chapterId}");
151+
148152
private static Uri EUri(FormattableString path) => new(path.ToString(_provider), UriKind.Relative);
149153
}
150154
}

0 commit comments

Comments
 (0)