Response Models -> no public set; Request models -> no set for collections

This commit is contained in:
Jonas Dellinger 2020-05-05 15:30:00 +02:00
parent 28531ab007
commit 997d29cfc5
74 changed files with 505 additions and 389 deletions

View File

@ -13,6 +13,9 @@ indent_size = 2
indent_size = 2 indent_size = 2
[*.{cs,vb}] [*.{cs,vb}]
# Does not seem to work...
dotnet_diagnostic.CA1303.severity = none
dotnet_diagnostic.CA1056.severity = none
# Sort using and Import directives with System.* appearing first # Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true dotnet_sort_system_directives_first = true
dotnet_style_require_accessibility_modifiers = always:warning dotnet_style_require_accessibility_modifiers = always:warning
@ -26,3 +29,5 @@ dotnet_style_qualification_for_event = false:warning
# Code-block preferences # Code-block preferences
csharp_prefer_braces = true:warning csharp_prefer_braces = true:warning
csharp_prefer_simple_using_statement = true:warning csharp_prefer_simple_using_statement = true:warning
# Custom disabled

View File

@ -20,7 +20,9 @@ namespace SpotifyAPI.Web
Task<Paging<SimplePlaylist>> GetUsers(string userId); Task<Paging<SimplePlaylist>> GetUsers(string userId);
Task<Paging<SimplePlaylist>> GetUsers(string userId, PlaylistGetUsersRequest request); Task<Paging<SimplePlaylist>> GetUsers(string userId, PlaylistGetUsersRequest request);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<FullPlaylist> Get(string playlistId); Task<FullPlaylist> Get(string playlistId);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<FullPlaylist> Get(string playlistId, PlaylistGetRequest request); Task<FullPlaylist> Get(string playlistId, PlaylistGetRequest request);
Task<bool> ReplaceItems(string playlistId, PlaylistReplaceItemsRequest request); Task<bool> ReplaceItems(string playlistId, PlaylistReplaceItemsRequest request);

View File

@ -4,7 +4,9 @@ namespace SpotifyAPI.Web
{ {
public interface IShowsClient public interface IShowsClient
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<FullShow> Get(string showId); Task<FullShow> Get(string showId);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<FullShow> Get(string showId, ShowRequest request); Task<FullShow> Get(string showId, ShowRequest request);
Task<ShowsResponse> GetSeveral(ShowsRequest request); Task<ShowsResponse> GetSeveral(ShowsRequest request);

View File

@ -19,6 +19,7 @@ namespace SpotifyAPI.Web
/// <param name="userId"></param> /// <param name="userId"></param>
/// <exception cref="APIUnauthorizedException">Thrown if the client is not authenticated.</exception> /// <exception cref="APIUnauthorizedException">Thrown if the client is not authenticated.</exception>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<PublicUser> Get(string userId); Task<PublicUser> Get(string userId);
} }
} }

View File

@ -7,7 +7,7 @@ namespace SpotifyAPI.Web
{ {
public class SimplePaginator : IPaginator public class SimplePaginator : IPaginator
{ {
protected bool ShouldContinue<T>(List<T> results, Paging<T> page) protected virtual bool ShouldContinue<T>(List<T> results, Paging<T> page)
{ {
return true; return true;
} }

View File

@ -105,7 +105,7 @@ namespace SpotifyAPI.Web
public static SpotifyClientConfig CreateDefault(IAuthenticator authenticator) public static SpotifyClientConfig CreateDefault(IAuthenticator authenticator)
{ {
return new SpotifyClientConfig( return new SpotifyClientConfig(
SpotifyUrls.API_V1, SpotifyUrls.APIV1,
authenticator, authenticator,
new NewtonsoftJSONSerializer(), new NewtonsoftJSONSerializer(),
new NetHttpClient(), new NetHttpClient(),

View File

@ -1,13 +1,16 @@
using System.Net;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using SpotifyAPI.Web.Http; using SpotifyAPI.Web.Http;
using System;
using System.Runtime.Serialization;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
[System.Serializable] [Serializable]
public class APIException : System.Exception public class APIException : System.Exception
{ {
public IResponse Response { get; set; }
public APIException(IResponse response) : base(ParseAPIErrorMessage(response)) public APIException(IResponse response) : base(ParseAPIErrorMessage(response))
{ {
Ensure.ArgumentNotNull(response, nameof(response)); Ensure.ArgumentNotNull(response, nameof(response));
@ -15,6 +18,23 @@ namespace SpotifyAPI.Web
Response = response; Response = response;
} }
public APIException()
{
}
public APIException(string message) : base(message)
{
}
public APIException(string message, System.Exception innerException) : base(message, innerException)
{
}
protected APIException(SerializationInfo info, StreamingContext context) : base(info, context)
{
Response = info.GetValue("APIException.Response", typeof(IResponse)) as IResponse;
}
private static string ParseAPIErrorMessage(IResponse response) private static string ParseAPIErrorMessage(IResponse response)
{ {
var body = response.Body as string; var body = response.Body as string;
@ -38,6 +58,10 @@ namespace SpotifyAPI.Web
return null; return null;
} }
public IResponse Response { get; set; } public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("APIException.Response", Response);
}
} }
} }

View File

@ -1,10 +1,20 @@
using System.Runtime.Serialization;
using System;
using SpotifyAPI.Web.Http; using SpotifyAPI.Web.Http;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
[System.Serializable] [Serializable]
public class APIUnauthorizedException : APIException public class APIUnauthorizedException : APIException
{ {
public APIUnauthorizedException(IResponse response) : base(response) { } public APIUnauthorizedException(IResponse response) : base(response) { }
public APIUnauthorizedException() { }
public APIUnauthorizedException(string message) : base(message) { }
public APIUnauthorizedException(string message, Exception innerException) : base(message, innerException) { }
protected APIUnauthorizedException(SerializationInfo info, StreamingContext context) : base(info, context) { }
} }
} }

View File

@ -158,10 +158,9 @@ namespace SpotifyAPI.Web.Http
Ensure.ArgumentNotNull(uri, nameof(uri)); Ensure.ArgumentNotNull(uri, nameof(uri));
Ensure.ArgumentNotNull(method, nameof(method)); Ensure.ArgumentNotNull(method, nameof(method));
return new Request return new Request(parameters)
{ {
BaseAddress = _baseAddress, BaseAddress = _baseAddress,
Parameters = parameters,
Endpoint = uri, Endpoint = uri,
Method = method, Method = method,
Body = body Body = body
@ -183,13 +182,13 @@ namespace SpotifyAPI.Web.Http
_httpLogger?.OnResponse(response); _httpLogger?.OnResponse(response);
if (_retryHandler != null) if (_retryHandler != null)
{ {
response = await _retryHandler?.HandleRetry(request, response, async (newRequest) => response = await _retryHandler.HandleRetry(request, response, async (newRequest) =>
{ {
await _authenticator.Apply(newRequest).ConfigureAwait(false); await _authenticator.Apply(newRequest).ConfigureAwait(false);
var newResponse = await _httpClient.DoRequest(request).ConfigureAwait(false); var newResponse = await _httpClient.DoRequest(request).ConfigureAwait(false);
_httpLogger?.OnResponse(newResponse); _httpLogger?.OnResponse(newResponse);
return newResponse; return newResponse;
}); }).ConfigureAwait(false);
} }
ProcessErrors(response); ProcessErrors(response);
return response; return response;
@ -214,7 +213,7 @@ namespace SpotifyAPI.Web.Http
) )
{ {
var request = CreateRequest(uri, method, parameters, body); var request = CreateRequest(uri, method, parameters, body);
IAPIResponse<T> apiResponse = await DoSerializedRequest<T>(request); IAPIResponse<T> apiResponse = await DoSerializedRequest<T>(request).ConfigureAwait(false);
return apiResponse.Body; return apiResponse.Body;
} }
@ -226,11 +225,11 @@ namespace SpotifyAPI.Web.Http
) )
{ {
var request = CreateRequest(uri, method, parameters, body); var request = CreateRequest(uri, method, parameters, body);
var response = await DoSerializedRequest<object>(request); var response = await DoSerializedRequest<object>(request).ConfigureAwait(false);
return response.Response; return response.Response;
} }
private void ProcessErrors(IResponse response) private static void ProcessErrors(IResponse response)
{ {
Ensure.ArgumentNotNull(response, nameof(response)); Ensure.ArgumentNotNull(response, nameof(response));

View File

@ -14,7 +14,9 @@ namespace SpotifyAPI.Web.Http
// IHTTPClient HTTPClient { get; } // IHTTPClient HTTPClient { get; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<T> Get<T>(Uri uri); Task<T> Get<T>(Uri uri);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<T> Get<T>(Uri uri, IDictionary<string, string> parameters); Task<T> Get<T>(Uri uri, IDictionary<string, string> parameters);
Task<T> Post<T>(Uri uri); Task<T> Post<T>(Uri uri);

View File

@ -28,7 +28,7 @@ namespace SpotifyAPI.Web.Http
return await BuildResponse(responseMsg).ConfigureAwait(false); return await BuildResponse(responseMsg).ConfigureAwait(false);
} }
private async Task<IResponse> BuildResponse(HttpResponseMessage responseMsg) private static async Task<IResponse> BuildResponse(HttpResponseMessage responseMsg)
{ {
Ensure.ArgumentNotNull(responseMsg, nameof(responseMsg)); Ensure.ArgumentNotNull(responseMsg, nameof(responseMsg));
@ -46,7 +46,7 @@ namespace SpotifyAPI.Web.Http
}; };
} }
private HttpRequestMessage BuildRequestMessage(IRequest request) private static HttpRequestMessage BuildRequestMessage(IRequest request)
{ {
Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(request, nameof(request));
@ -79,7 +79,7 @@ namespace SpotifyAPI.Web.Http
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
private void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.Reflection;
using System; using System;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
@ -13,13 +15,16 @@ namespace SpotifyAPI.Web.Http
public NewtonsoftJSONSerializer() public NewtonsoftJSONSerializer()
{ {
var contractResolver = new PrivateFieldDefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};
contractResolver.DefaultMembersSearchFlags |= BindingFlags.NonPublic;
_serializerSettings = new JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
{ {
NullValueHandling = NullValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new DefaultContractResolver ContractResolver = contractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
}; };
} }
@ -46,5 +51,16 @@ namespace SpotifyAPI.Web.Http
request.Body = JsonConvert.SerializeObject(request.Body, _serializerSettings); request.Body = JsonConvert.SerializeObject(request.Body, _serializerSettings);
} }
private class PrivateFieldDefaultContractResolver : DefaultContractResolver
{
protected override List<MemberInfo> GetSerializableMembers(Type objectType)
{
// Does not seem to work, still need DefaultMembersSearchFlags |= BindingFlags.NonPublic
var list = base.GetSerializableMembers(objectType);
list.AddRange(objectType.GetProperties(BindingFlags.NonPublic));
return list;
}
}
} }
} }

View File

@ -12,13 +12,25 @@ namespace SpotifyAPI.Web.Http
Parameters = new Dictionary<string, string>(); Parameters = new Dictionary<string, string>();
} }
public Request(IDictionary<string, string> headers)
{
Headers = headers;
Parameters = new Dictionary<string, string>();
}
public Request(IDictionary<string, string> headers, IDictionary<string, string> parameters)
{
Headers = headers;
Parameters = parameters;
}
public Uri BaseAddress { get; set; } public Uri BaseAddress { get; set; }
public Uri Endpoint { get; set; } public Uri Endpoint { get; set; }
public IDictionary<string, string> Headers { get; set; } public IDictionary<string, string> Headers { get; }
public IDictionary<string, string> Parameters { get; set; } public IDictionary<string, string> Parameters { get; }
public HttpMethod Method { get; set; } public HttpMethod Method { get; set; }

View File

@ -5,19 +5,28 @@ namespace SpotifyAPI.Web.Http
{ {
public class SimpleHTTPLogger : IHTTPLogger public class SimpleHTTPLogger : IHTTPLogger
{ {
private const string OnRequestFormat = "\n{0} {1} [{2}] {3}";
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")]
public void OnRequest(IRequest request) public void OnRequest(IRequest request)
{ {
Ensure.ArgumentNotNull(request, nameof(request));
string parameters = null; string parameters = null;
if (request.Parameters != null) if (request.Parameters != null)
{ {
parameters = string.Join(",", request.Parameters?.Select(kv => kv.Key + "=" + kv.Value).ToArray()); parameters = string.Join(",", request.Parameters?.Select(kv => kv.Key + "=" + kv.Value).ToArray());
} }
Console.WriteLine("\n{0} {1} [{2}] {3}", request.Method, request.Endpoint, parameters, request.Body);
Console.WriteLine(OnRequestFormat, request.Method, request.Endpoint, parameters, request.Body);
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")]
public void OnResponse(IResponse response) public void OnResponse(IResponse response)
{ {
string body = response.Body?.ToString().Replace("\n", ""); Ensure.ArgumentNotNull(response, nameof(response));
string body = response.Body?.ToString().Replace("\n", "", StringComparison.InvariantCulture);
body = body?.Substring(0, Math.Min(50, body?.Length ?? 0)); body = body?.Substring(0, Math.Min(50, body?.Length ?? 0));
Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body); Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body);
} }

View File

@ -16,6 +16,8 @@ namespace SpotifyAPI.Web.Http
public Task Apply(IRequest request) public Task Apply(IRequest request)
{ {
Ensure.ArgumentNotNull(request, nameof(request));
request.Headers["Authorization"] = $"{TokenType} {Token}"; request.Headers["Authorization"] = $"{TokenType} {Token}";
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -11,6 +11,8 @@ namespace SpotifyAPI.Web
public override object ReadJson(JsonReader reader, Type objectType, public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer) object existingValue, JsonSerializer serializer)
{ {
Ensure.ArgumentNotNull(serializer, nameof(serializer));
var token = JToken.ReadFrom(reader); var token = JToken.ReadFrom(reader);
if (token.Type == JTokenType.Null) if (token.Type == JTokenType.Null)
{ {

View File

@ -1,3 +1,4 @@
using System.Globalization;
using System; using System;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
@ -14,9 +15,9 @@ namespace SpotifyAPI.Web
public DateTime? Timestamp { get; set; } public DateTime? Timestamp { get; set; }
[QueryParam("timestamp")] [QueryParam("timestamp")]
protected string _Timestamp protected string TimestampFormatted
{ {
get => Timestamp?.ToString("o"); get => Timestamp?.ToString("o", CultureInfo.InvariantCulture);
} }
} }
} }

View File

@ -4,19 +4,22 @@ namespace SpotifyAPI.Web
{ {
public class FollowCheckCurrentUserRequest : RequestParams public class FollowCheckCurrentUserRequest : RequestParams
{ {
[QueryParam("type")] public FollowCheckCurrentUserRequest(Type type, IList<string> ids)
public Types? Type { get; set; }
[QueryParam("ids")]
public List<string> Ids { get; set; }
protected override void CustomEnsure()
{ {
Ensure.ArgumentNotNull(Type, nameof(Type)); Ensure.ArgumentNotNull(type, nameof(type));
Ensure.ArgumentNotNullOrEmptyList(Ids, nameof(Ids)); Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
TypeParam = type;
Ids = ids;
} }
public enum Types [QueryParam("type")]
public Type TypeParam { get; }
[QueryParam("ids")]
public IList<string> Ids { get; }
public enum Type
{ {
[String("artist")] [String("artist")]
Artist, Artist,

View File

@ -4,12 +4,14 @@ namespace SpotifyAPI.Web
{ {
public class FollowCheckPlaylistRequest : RequestParams public class FollowCheckPlaylistRequest : RequestParams
{ {
[QueryParam("ids")] public FollowCheckPlaylistRequest(IList<string> ids)
public List<string> Ids { get; set; }
protected override void CustomEnsure()
{ {
Ensure.ArgumentNotNullOrEmptyList(Ids, nameof(Ids)); Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
Ids = ids;
} }
[QueryParam("ids")]
public IList<string> Ids { get; }
} }
} }

View File

@ -2,14 +2,13 @@ namespace SpotifyAPI.Web
{ {
public class FollowOfCurrentUserRequest : RequestParams public class FollowOfCurrentUserRequest : RequestParams
{ {
public FollowOfCurrentUserRequest() public FollowOfCurrentUserRequest(Type type = Type.Artist)
{ {
Type = Types.Artist; TypeParam = type;
} }
[QueryParam("type")] [QueryParam("type")]
public Types Type { get; set; } public Type TypeParam { get; set; }
[QueryParam("limit")] [QueryParam("limit")]
public int? Limit { get; set; } public int? Limit { get; set; }
@ -17,7 +16,7 @@ namespace SpotifyAPI.Web
[QueryParam("after")] [QueryParam("after")]
public string After { get; set; } public string After { get; set; }
public enum Types public enum Type
{ {
[String("artist")] [String("artist")]
Artist Artist

View File

@ -3,6 +3,6 @@ namespace SpotifyAPI.Web
public class FollowPlaylistRequest : RequestParams public class FollowPlaylistRequest : RequestParams
{ {
[BodyParam("public")] [BodyParam("public")]
public bool Public { get; set; } public bool? Public { get; set; }
} }
} }

View File

@ -4,17 +4,20 @@ namespace SpotifyAPI.Web
{ {
public class FollowRequest : RequestParams public class FollowRequest : RequestParams
{ {
public FollowRequest(Type type, IList<string> ids)
{
Ensure.ArgumentNotNull(type, nameof(type));
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
TypeParam = type;
Ids = ids;
}
[QueryParam("type")] [QueryParam("type")]
public Type? TypeParam { get; set; } public Type? TypeParam { get; set; }
[BodyParam("ids")] [BodyParam("ids")]
public List<string> Ids { get; set; } public IList<string> Ids { get; }
protected override void CustomEnsure()
{
Ensure.ArgumentNotNull(TypeParam, nameof(TypeParam));
Ensure.ArgumentNotNullOrEmptyList(Ids, nameof(Ids));
}
public enum Type public enum Type
{ {

View File

@ -1,12 +1,18 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
public class PlaylistAddItemsRequest : RequestParams public class PlaylistAddItemsRequest : RequestParams
{ {
public PlaylistAddItemsRequest(IList<string> uris)
{
Ensure.ArgumentNotNull(uris, nameof(uris));
Uris = uris;
}
[BodyParam("uris")] [BodyParam("uris")]
public List<string> Uris { get; set; } public IList<string> Uris { get; }
[BodyParam("position")] [BodyParam("position")]
public int? Position { get; set; } public int? Position { get; set; }

View File

@ -4,11 +4,13 @@ namespace SpotifyAPI.Web
{ {
public PlaylistCreateRequest(string name) public PlaylistCreateRequest(string name)
{ {
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Name = name; Name = name;
} }
[BodyParam("name")] [BodyParam("name")]
public string Name { get; set; } public string Name { get; }
[BodyParam("public")] [BodyParam("public")]
public bool? Public { get; set; } public bool? Public { get; set; }

View File

@ -5,13 +5,16 @@ namespace SpotifyAPI.Web
{ {
public class PlaylistGetItemsRequest : RequestParams public class PlaylistGetItemsRequest : RequestParams
{ {
public PlaylistGetItemsRequest() public PlaylistGetItemsRequest(AdditionalTypes types = AdditionalTypes.All)
{ {
AdditionalTypes = AdditionalType.All; Ensure.ArgumentNotNull(types, nameof(types));
AdditionalTypesParam = types;
Fields = new List<string>();
} }
[QueryParam("fields")] [QueryParam("fields")]
public List<string> Fields { get; set; } public IList<string> Fields { get; }
[QueryParam("limit")] [QueryParam("limit")]
public int? Limit { get; set; } public int? Limit { get; set; }
@ -27,15 +30,15 @@ namespace SpotifyAPI.Web
/// </summary> /// </summary>
/// <value></value> /// <value></value>
[QueryParam("additional_types")] [QueryParam("additional_types")]
public AdditionalType AdditionalTypes { get; set; } public AdditionalTypes AdditionalTypesParam { get; set; }
[Flags] [Flags]
public enum AdditionalType public enum AdditionalTypes
{ {
[String("track")] [String("track")]
Track = 0, Track = 1,
[String("episode")] [String("episode")]
Episode = 1, Episode = 2,
All = Track | Episode All = Track | Episode
} }
} }

View File

@ -5,9 +5,11 @@ namespace SpotifyAPI.Web
{ {
public class PlaylistGetRequest : RequestParams public class PlaylistGetRequest : RequestParams
{ {
public PlaylistGetRequest() public PlaylistGetRequest(AdditionalTypes types = AdditionalTypes.All)
{ {
AdditionalTypes = AdditionalType.All; Ensure.ArgumentNotNull(types, nameof(types));
AdditionalTypesParam = types;
} }
/// <summary> /// <summary>
@ -15,15 +17,15 @@ namespace SpotifyAPI.Web
/// </summary> /// </summary>
/// <value></value> /// <value></value>
[QueryParam("additional_types")] [QueryParam("additional_types")]
public AdditionalType AdditionalTypes { get; set; } public AdditionalTypes AdditionalTypesParam { get; set; }
[Flags] [Flags]
public enum AdditionalType public enum AdditionalTypes
{ {
[String("track")] [String("track")]
Track = 0, Track = 1,
[String("episode")] [String("episode")]
Episode = 1, Episode = 2,
All = Track | Episode All = Track | Episode
} }
} }

View File

@ -7,7 +7,5 @@ namespace SpotifyAPI.Web
[QueryParam("offset")] [QueryParam("offset")]
public int? Offset { get; set; } public int? Offset { get; set; }
} }
} }

View File

@ -5,27 +5,26 @@ namespace SpotifyAPI.Web
{ {
public class PlaylistRemoveItemsRequest : RequestParams public class PlaylistRemoveItemsRequest : RequestParams
{ {
public PlaylistRemoveItemsRequest(IList<Item> tracks)
{
Ensure.ArgumentNotNullOrEmptyList(tracks, nameof(tracks));
Tracks = tracks;
}
[BodyParam("tracks")] [BodyParam("tracks")]
public List<Item> Tracks { get; set; } public IList<Item> Tracks { get; }
[BodyParam("snapshot_id")] [BodyParam("snapshot_id")]
public string SnapshotId { get; set; } public string SnapshotId { get; set; }
protected override void CustomEnsure() [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034")]
{
Ensure.ArgumentNotNullOrEmptyList(Tracks, nameof(Tracks));
}
public class Item public class Item
{ {
public Item(string uri) [JsonProperty("uri", NullValueHandling = NullValueHandling.Ignore)]
{
Uri = uri;
}
[JsonProperty("uri")]
public string Uri { get; set; } public string Uri { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227")]
[JsonProperty("positions", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("positions", NullValueHandling = NullValueHandling.Ignore)]
public List<int> Positions { get; set; } public List<int> Positions { get; set; }
} }

View File

@ -2,22 +2,22 @@ namespace SpotifyAPI.Web
{ {
public class PlaylistReorderItemsRequest : RequestParams public class PlaylistReorderItemsRequest : RequestParams
{ {
public PlaylistReorderItemsRequest(int rangeStart, int insertBefore)
{
RangeStart = rangeStart;
InsertBefore = insertBefore;
}
[BodyParam("range_start")] [BodyParam("range_start")]
public int? RangeStart { get; set; } public int RangeStart { get; set; }
[BodyParam("insert_before")] [BodyParam("insert_before")]
public int? InsertBefore { get; set; } public int InsertBefore { get; set; }
[BodyParam("range_length")] [BodyParam("range_length")]
public int? RangeLength { get; set; } public int? RangeLength { get; set; }
[BodyParam("snapshot_id")] [BodyParam("snapshot_id")]
public string SnapshotId { get; set; } public string SnapshotId { get; set; }
protected override void CustomEnsure()
{
Ensure.ArgumentNotNull(RangeStart, nameof(RangeStart));
Ensure.ArgumentNotNull(InsertBefore, nameof(InsertBefore));
}
} }
} }

View File

@ -4,12 +4,14 @@ namespace SpotifyAPI.Web
{ {
public class PlaylistReplaceItemsRequest : RequestParams public class PlaylistReplaceItemsRequest : RequestParams
{ {
[BodyParam("uris")] public PlaylistReplaceItemsRequest(List<string> uris)
public List<string> Uris { get; set; }
protected override void CustomEnsure()
{ {
Ensure.ArgumentNotNullOrEmptyList(Uris, nameof(Uris)); Ensure.ArgumentNotNull(uris, nameof(uris));
Uris = uris;
} }
[BodyParam("uris")]
public IList<string> Uris { get; }
} }
} }

View File

@ -10,16 +10,19 @@ namespace SpotifyAPI.Web
Min = new Dictionary<string, string>(); Min = new Dictionary<string, string>();
Max = new Dictionary<string, string>(); Max = new Dictionary<string, string>();
Target = new Dictionary<string, string>(); Target = new Dictionary<string, string>();
SeedArtists = new List<string>();
SeedGenres = new List<string>();
SeedTracks = new List<string>();
} }
[QueryParam("seed_artists")] [QueryParam("seed_artists")]
public string SeedArtists { get; set; } public IList<string> SeedArtists { get; }
[QueryParam("seed_genres")] [QueryParam("seed_genres")]
public string SeedGenres { get; set; } public IList<string> SeedGenres { get; }
[QueryParam("seed_tracks")] [QueryParam("seed_tracks")]
public string SeedTracks { get; set; } public IList<string> SeedTracks { get; }
[QueryParam("limit")] [QueryParam("limit")]
public int? Limit { get; set; } public int? Limit { get; set; }
@ -27,20 +30,22 @@ namespace SpotifyAPI.Web
[QueryParam("market")] [QueryParam("market")]
public string Market { get; set; } public string Market { get; set; }
public Dictionary<string, string> Min { get; set; } public Dictionary<string, string> Min { get; }
public Dictionary<string, string> Max { get; set; } public Dictionary<string, string> Max { get; }
public Dictionary<string, string> Target { get; set; } public Dictionary<string, string> Target { get; }
protected override void CustomEnsure() protected override void CustomEnsure()
{ {
if (string.IsNullOrEmpty(SeedTracks) && string.IsNullOrEmpty(SeedGenres) && string.IsNullOrEmpty(SeedArtists)) if (SeedArtists.Count == 0 && SeedGenres.Count == 0 && SeedTracks.Count == 0)
{ {
throw new ArgumentException("At least one of the seeds has to be non-empty"); throw new ArgumentException("At least one of the seeds has to be non-empty");
} }
} }
protected override void AddCustomQueryParams(System.Collections.Generic.Dictionary<string, string> queryParams) protected override void AddCustomQueryParams(Dictionary<string, string> queryParams)
{ {
Ensure.ArgumentNotNull(queryParams, nameof(queryParams));
foreach (KeyValuePair<string, string> pair in Min) foreach (KeyValuePair<string, string> pair in Min)
{ {
queryParams.Add($"min_{pair.Key}", pair.Value); queryParams.Add($"min_{pair.Key}", pair.Value);

View File

@ -45,15 +45,13 @@ namespace SpotifyAPI.Web
object value = prop.GetValue(this); object value = prop.GetValue(this);
if (value != null) if (value != null)
{ {
if (value is List<string>) if (value is IList<string> list && list.Count > 0)
{ {
var list = value as List<string>;
var str = string.Join(",", list); var str = string.Join(",", list);
queryParams.Add(attribute.Key ?? prop.Name, str); queryParams.Add(attribute.Key ?? prop.Name, str);
} }
else if (value is Enum) else if (value is Enum valueAsEnum)
{ {
var valueAsEnum = value as Enum;
var enumType = valueAsEnum.GetType(); var enumType = valueAsEnum.GetType();
var valueList = new List<string>(); var valueList = new List<string>();
@ -88,6 +86,7 @@ namespace SpotifyAPI.Web
protected virtual void AddCustomQueryParams(Dictionary<string, string> queryParams) { } protected virtual void AddCustomQueryParams(Dictionary<string, string> queryParams) { }
} }
[AttributeUsage(AttributeTargets.Property)]
public class QueryParamAttribute : Attribute public class QueryParamAttribute : Attribute
{ {
public string Key { get; } public string Key { get; }
@ -99,6 +98,7 @@ namespace SpotifyAPI.Web
} }
} }
[AttributeUsage(AttributeTargets.Property)]
public class BodyParamAttribute : Attribute public class BodyParamAttribute : Attribute
{ {
public string Key { get; } public string Key { get; }

View File

@ -4,8 +4,17 @@ namespace SpotifyAPI.Web
{ {
public class SearchRequest : RequestParams public class SearchRequest : RequestParams
{ {
public SearchRequest(Types type, string query)
{
Ensure.ArgumentNotNull(type, nameof(type));
Ensure.ArgumentNotNullOrEmptyString(query, nameof(query));
Type = type;
Query = query;
}
[QueryParam("type")] [QueryParam("type")]
public Type? Types { get; set; } public Types Type { get; set; }
[QueryParam("q")] [QueryParam("q")]
public string Query { get; set; } public string Query { get; set; }
@ -20,36 +29,30 @@ namespace SpotifyAPI.Web
public int? Offset { get; set; } public int? Offset { get; set; }
[QueryParam("include_external")] [QueryParam("include_external")]
public External? IncludeExternal { get; set; } public IncludeExternals? IncludeExternal { get; set; }
protected override void CustomEnsure()
{
Ensure.ArgumentNotNull(Types, nameof(Types));
Ensure.ArgumentNotNullOrEmptyString(Query, nameof(Query));
}
[Flags] [Flags]
public enum External public enum IncludeExternals
{ {
[String("audio")] [String("audio")]
Audio = 0, Audio = 1,
} }
[Flags] [Flags]
public enum Type public enum Types
{ {
[String("album")] [String("album")]
Album = 0, Album = 1,
[String("artist")] [String("artist")]
Artist = 1, Artist = 2,
[String("playlist")] [String("playlist")]
Playlist = 2, Playlist = 4,
[String("track")] [String("track")]
Track = 4, Track = 8,
[String("show")] [String("show")]
Show = 8, Show = 16,
[String("episode")] [String("episode")]
Episode = 16, Episode = 32,
All = Album | Artist | Playlist | Track | Show | Episode All = Album | Artist | Playlist | Track | Show | Episode
} }
} }

View File

@ -4,19 +4,17 @@ namespace SpotifyAPI.Web
{ {
public class ShowsRequest : RequestParams public class ShowsRequest : RequestParams
{ {
public ShowsRequest(List<string> ids) public ShowsRequest(IList<string> ids)
{ {
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
Ids = ids; Ids = ids;
} }
[QueryParam("ids")] [QueryParam("ids")]
public List<string> Ids { get; set; } public IList<string> Ids { get; }
[QueryParam("market")] [QueryParam("market")]
public string Market { get; set; } public string Market { get; set; }
protected override void CustomEnsure()
{
Ensure.ArgumentNotNullOrEmptyList(Ids, nameof(Ids));
}
} }
} }

View File

@ -3,19 +3,22 @@ namespace SpotifyAPI.Web
{ {
public class UnfollowRequest : RequestParams public class UnfollowRequest : RequestParams
{ {
[QueryParam("type")] public UnfollowRequest(Type type, IList<string> ids)
public Types? Type { get; set; }
[BodyParam("ids")]
public List<string> Ids { get; set; }
protected override void CustomEnsure()
{ {
Ensure.ArgumentNotNull(Type, nameof(Type)); Ensure.ArgumentNotNull(type, nameof(type));
Ensure.ArgumentNotNullOrEmptyList(Ids, nameof(Ids)); Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
TypeParam = type;
Ids = ids;
} }
public enum Types [QueryParam("type")]
public Type TypeParam { get; }
[BodyParam("ids")]
public IList<string> Ids { get; }
public enum Type
{ {
[String("artist")] [String("artist")]
Artist, Artist,

View File

@ -2,6 +2,6 @@ namespace SpotifyAPI.Web
{ {
public class CategoriesResponse public class CategoriesResponse
{ {
public Paging<Category> Categories { get; set; } public Paging<Category> Categories { get; private set; }
} }
} }

View File

@ -4,9 +4,9 @@ namespace SpotifyAPI.Web
{ {
public class Category public class Category
{ {
public string Href { get; set; } public string Href { get; private set; }
public List<Image> Icons { get; set; } public List<Image> Icons { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
} }
} }

View File

@ -2,6 +2,6 @@ namespace SpotifyAPI.Web
{ {
public class CategoryPlaylistsResponse public class CategoryPlaylistsResponse
{ {
public Paging<SimplePlaylist> Playlists { get; set; } public Paging<SimplePlaylist> Playlists { get; private set; }
} }
} }

View File

@ -2,7 +2,7 @@ namespace SpotifyAPI.Web
{ {
public class Copyright public class Copyright
{ {
public string Text { get; set; } public string Text { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
} }
} }

View File

@ -2,7 +2,7 @@ namespace SpotifyAPI.Web
{ {
public class Cursor public class Cursor
{ {
public string Before { get; set; } public string Before { get; private set; }
public string After { get; set; } public string After { get; private set; }
} }
} }

View File

@ -4,11 +4,11 @@ namespace SpotifyAPI.Web
{ {
public class CursorPaging<T> public class CursorPaging<T>
{ {
public string Href { get; set; } public string Href { get; private set; }
public List<T> Items { get; set; } public List<T> Items { get; private set; }
public int Limit { get; set; } public int Limit { get; private set; }
public string Next { get; set; } public string Next { get; private set; }
public Cursor Cursors { get; set; } public Cursor Cursors { get; private set; }
public int Total { get; set; } public int Total { get; private set; }
} }
} }

View File

@ -2,7 +2,7 @@ namespace SpotifyAPI.Web
{ {
public class FeaturedPlaylistsResponse public class FeaturedPlaylistsResponse
{ {
public string Message { get; set; } public string Message { get; private set; }
public Paging<SimplePlaylist> Playlists { get; set; } public Paging<SimplePlaylist> Playlists { get; private set; }
} }
} }

View File

@ -2,6 +2,6 @@ namespace SpotifyAPI.Web
{ {
public class FollowedArtistsResponse public class FollowedArtistsResponse
{ {
public CursorPaging<FullArtist> Artists { get; set; } public CursorPaging<FullArtist> Artists { get; private set; }
} }
} }

View File

@ -2,8 +2,8 @@ namespace SpotifyAPI.Web
{ {
public class Followers public class Followers
{ {
public string Href { get; set; } public string Href { get; private set; }
public int Total { get; set; } public int Total { get; private set; }
} }
} }

View File

@ -4,15 +4,15 @@ namespace SpotifyAPI.Web
{ {
public class FullArtist public class FullArtist
{ {
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public Followers Followers { get; set; } public Followers Followers { get; private set; }
public List<string> Genres { get; set; } public List<string> Genres { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public int Popularity { get; set; } public int Popularity { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -6,25 +6,25 @@ namespace SpotifyAPI.Web
{ {
public class FullEpisode : IPlaylistItem public class FullEpisode : IPlaylistItem
{ {
public string AudioPreviewUrl { get; set; } public string AudioPreviewUrl { get; private set; }
public string Description { get; set; } public string Description { get; private set; }
public int DurationMs { get; set; } public int DurationMs { get; private set; }
public bool Explicit { get; set; } public bool Explicit { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public bool IsExternallyHosted { get; set; } public bool IsExternallyHosted { get; private set; }
public bool IsPlayable { get; set; } public bool IsPlayable { get; private set; }
public List<string> Languages { get; set; } public List<string> Languages { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public string ReleaseDate { get; set; } public string ReleaseDate { get; private set; }
public string ReleaseDatePrecision { get; set; } public string ReleaseDatePrecision { get; private set; }
public ResumePoint ResumePoint { get; set; } public ResumePoint ResumePoint { get; private set; }
public SimpleShow Show { get; set; } public SimpleShow Show { get; private set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public ItemType Type { get; set; } public ItemType Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -3,17 +3,17 @@ namespace SpotifyAPI.Web
{ {
public class FullPlaylist public class FullPlaylist
{ {
public bool Collaborative { get; set; } public bool Collaborative { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public PublicUser Owner { get; set; } public PublicUser Owner { get; private set; }
public bool Public { get; set; } public bool Public { get; private set; }
public string SnapshotId { get; set; } public string SnapshotId { get; private set; }
public Paging<PlaylistTrack<IPlaylistItem>> Tracks { get; set; } public Paging<PlaylistTrack<IPlaylistItem>> Tracks { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -4,21 +4,21 @@ namespace SpotifyAPI.Web
{ {
public class FullShow public class FullShow
{ {
public List<string> AvailableMarkets { get; set; } public List<string> AvailableMarkets { get; private set; }
public List<Copyright> Copyrights { get; set; } public List<Copyright> Copyrights { get; private set; }
public string Description { get; set; } public string Description { get; private set; }
public Paging<SimpleEpisode> Episodes { get; set; } public Paging<SimpleEpisode> Episodes { get; private set; }
public bool Explicit { get; set; } public bool Explicit { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public bool IsExternallyHosted { get; set; } public bool IsExternallyHosted { get; private set; }
public List<string> Languages { get; set; } public List<string> Languages { get; private set; }
public string MediaType { get; set; } public string MediaType { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public string Publisher { get; set; } public string Publisher { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -6,27 +6,27 @@ namespace SpotifyAPI.Web
{ {
public class FullTrack : IPlaylistItem public class FullTrack : IPlaylistItem
{ {
public SimpleAlbum Album { get; set; } public SimpleAlbum Album { get; private set; }
public List<SimpleArtist> Artists { get; set; } public List<SimpleArtist> Artists { get; private set; }
public List<string> AvailableMarkets { get; set; } public List<string> AvailableMarkets { get; private set; }
public int DiscNumber { get; set; } public int DiscNumber { get; private set; }
public int DurationMs { get; set; } public int DurationMs { get; private set; }
public bool Explicit { get; set; } public bool Explicit { get; private set; }
public Dictionary<string, string> ExternalIds { get; set; } public Dictionary<string, string> ExternalIds { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public bool IsPlayable { get; set; } public bool IsPlayable { get; private set; }
public LinkedTrack LinkedFrom { get; set; } public LinkedTrack LinkedFrom { get; private set; }
public Dictionary<string, string> Restrictions { get; set; } public Dictionary<string, string> Restrictions { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public int Popularity { get; set; } public int Popularity { get; private set; }
public string PreviewUrl { get; set; } public string PreviewUrl { get; private set; }
public int TrackNumber { get; set; } public int TrackNumber { get; private set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public ItemType Type { get; set; } public ItemType Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
public bool IsLocal { get; set; } public bool IsLocal { get; private set; }
} }
} }

View File

@ -2,8 +2,8 @@ namespace SpotifyAPI.Web
{ {
public class Image public class Image
{ {
public int Height { get; set; } public int Height { get; private set; }
public int Width { get; set; } public int Width { get; private set; }
public string Url { get; set; } public string Url { get; private set; }
} }
} }

View File

@ -12,6 +12,6 @@ namespace SpotifyAPI.Web
public interface IPlaylistItem public interface IPlaylistItem
{ {
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public ItemType Type { get; set; } public ItemType Type { get; }
} }
} }

View File

@ -3,10 +3,10 @@ namespace SpotifyAPI.Web
{ {
public class LinkedTrack public class LinkedTrack
{ {
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -1,8 +1,8 @@
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
public class NewReleasesResponse public class NewReleasesResponse
{ {
public string Message { get; set; } public string Message { get; private set; }
public Paging<SimpleAlbum> Albums { get; set; } public Paging<SimpleAlbum> Albums { get; private set; }
} }
} }

View File

@ -4,12 +4,12 @@ namespace SpotifyAPI.Web
{ {
public class Paging<T> public class Paging<T>
{ {
public string Href { get; set; } public string Href { get; private set; }
public List<T> Items { get; set; } public List<T> Items { get; private set; }
public int Limit { get; set; } public int Limit { get; private set; }
public string Next { get; set; } public string Next { get; private set; }
public int Offset { get; set; } public int Offset { get; private set; }
public string Previous { get; set; } public string Previous { get; private set; }
public int Total { get; set; } public int Total { get; private set; }
} }
} }

View File

@ -5,11 +5,11 @@ namespace SpotifyAPI.Web
{ {
public class PlaylistTrack<T> public class PlaylistTrack<T>
{ {
public DateTime? AddedAt { get; set; } public DateTime? AddedAt { get; private set; }
public PublicUser AddedBy { get; set; } public PublicUser AddedBy { get; private set; }
public bool IsLocal { get; set; } public bool IsLocal { get; private set; }
[JsonConverter(typeof(PlaylistElementConverter))] [JsonConverter(typeof(PlaylistElementConverter))]
public T Track { get; set; } public T Track { get; private set; }
} }
} }

View File

@ -5,16 +5,16 @@ namespace SpotifyAPI.Web.Models
{ {
public class PrivateUser public class PrivateUser
{ {
public string Country { get; set; } public string Country { get; private set; }
public string DisplayName { get; set; } public string DisplayName { get; private set; }
public string Email { get; set; } public string Email { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public Followers Followers { get; set; } public Followers Followers { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public string Product { get; set; } public string Product { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -5,13 +5,13 @@ namespace SpotifyAPI.Web
{ {
public class PublicUser public class PublicUser
{ {
public string DisplayName { get; set; } public string DisplayName { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public Followers Followers { get; set; } public Followers Followers { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -2,8 +2,8 @@ using System.Collections.Generic;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
public class RecommendationGenresResponse public class RecommendationGenresResponse
{ {
public List<string> Genres { get; set; } public List<string> Genres { get; private set; }
} }
} }

View File

@ -5,14 +5,14 @@ namespace SpotifyAPI.Web
public class RecommendationSeed public class RecommendationSeed
{ {
[JsonProperty("afterFilteringSize")] [JsonProperty("afterFilteringSize")]
public int AfterFiliteringSize { get; set; } public int AfterFiliteringSize { get; private set; }
[JsonProperty("afterRelinkingSize")] [JsonProperty("afterRelinkingSize")]
public int AfterRelinkingSize { get; set; } public int AfterRelinkingSize { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
[JsonProperty("initialPoolSize")] [JsonProperty("initialPoolSize")]
public int InitialPoolSize { get; set; } public int InitialPoolSize { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
} }
} }

View File

@ -4,7 +4,7 @@ namespace SpotifyAPI.Web
{ {
public class RecommendationsResponse public class RecommendationsResponse
{ {
public List<RecommendationSeed> Seeds { get; set; } public List<RecommendationSeed> Seeds { get; private set; }
public List<SimpleTrack> Tracks { get; set; } public List<SimpleTrack> Tracks { get; private set; }
} }
} }

View File

@ -2,7 +2,7 @@ namespace SpotifyAPI.Web
{ {
public class ResumePoint public class ResumePoint
{ {
public bool FullyPlayed { get; set; } public bool FullyPlayed { get; private set; }
public int ResumePositionMs { get; set; } public int ResumePositionMs { get; private set; }
} }
} }

View File

@ -2,10 +2,10 @@ namespace SpotifyAPI.Web
{ {
public class SearchResponse public class SearchResponse
{ {
public Paging<FullArtist> Artists { get; set; } public Paging<FullArtist> Artists { get; private set; }
public Paging<SimpleAlbum> Albums { get; set; } public Paging<SimpleAlbum> Albums { get; private set; }
public Paging<FullTrack> Tracks { get; set; } public Paging<FullTrack> Tracks { get; private set; }
public Paging<SimpleShow> Shows { get; set; } public Paging<SimpleShow> Shows { get; private set; }
public Paging<SimpleEpisode> Episodes { get; set; } public Paging<SimpleEpisode> Episodes { get; private set; }
} }
} }

View File

@ -4,6 +4,6 @@ namespace SpotifyAPI.Web
{ {
public class ShowsResponse public class ShowsResponse
{ {
public List<SimpleShow> Shows { get; set; } public List<SimpleShow> Shows { get; private set; }
} }
} }

View File

@ -4,19 +4,19 @@ namespace SpotifyAPI.Web
{ {
public class SimpleAlbum public class SimpleAlbum
{ {
public string AlbumGroup { get; set; } public string AlbumGroup { get; private set; }
public string AlbumType { get; set; } public string AlbumType { get; private set; }
public List<SimpleArtist> Artists { get; set; } public List<SimpleArtist> Artists { get; private set; }
public List<string> AvailableMarkets { get; set; } public List<string> AvailableMarkets { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public string ReleaseDate { get; set; } public string ReleaseDate { get; private set; }
public string ReleaseDatePrecision { get; set; } public string ReleaseDatePrecision { get; private set; }
public Dictionary<string, string> Restrictions { get; set; } public Dictionary<string, string> Restrictions { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -3,11 +3,11 @@ namespace SpotifyAPI.Web
{ {
public class SimpleArtist public class SimpleArtist
{ {
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -7,27 +7,27 @@ namespace SpotifyAPI.Web
{ {
public class SimpleEpisode public class SimpleEpisode
{ {
public string AudioPreviewUrl { get; set; } public string AudioPreviewUrl { get; private set; }
public string Description { get; set; } public string Description { get; private set; }
public int DurationMs { get; set; } public int DurationMs { get; private set; }
public bool Explicit { get; set; } public bool Explicit { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public bool IsExternallyHosted { get; set; } public bool IsExternallyHosted { get; private set; }
public bool IsPlayable { get; set; } public bool IsPlayable { get; private set; }
[Obsolete("This field is deprecated and might be removed in the future. Please use the languages field instead")] [Obsolete("This field is deprecated and might be removed in the future. Please use the languages field instead")]
public string Language { get; set; } public string Language { get; private set; }
public List<string> Languages { get; set; } public List<string> Languages { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public string ReleaseDate { get; set; } public string ReleaseDate { get; private set; }
public string ReleaseDatePrecision { get; set; } public string ReleaseDatePrecision { get; private set; }
public ResumePoint ResumePoint { get; set; } public ResumePoint ResumePoint { get; private set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public ItemType Type { get; set; } public ItemType Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -6,18 +6,18 @@ namespace SpotifyAPI.Web
/// </summary> /// </summary>
public class SimplePlaylist public class SimplePlaylist
{ {
public bool Collaborative { get; set; } public bool Collaborative { get; private set; }
public string Description { get; set; } public string Description { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public PublicUser Owner { get; set; } public PublicUser Owner { get; private set; }
public bool? Public { get; set; } public bool? Public { get; private set; }
public string SnapshotId { get; set; } public string SnapshotId { get; private set; }
public Paging<PlaylistTrack<IPlaylistItem>> Tracks { get; set; } public Paging<PlaylistTrack<IPlaylistItem>> Tracks { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -4,20 +4,20 @@ namespace SpotifyAPI.Web
{ {
public class SimpleShow public class SimpleShow
{ {
public List<string> AvailableMarkets { get; set; } public List<string> AvailableMarkets { get; private set; }
public List<Copyright> Copyrights { get; set; } public List<Copyright> Copyrights { get; private set; }
public string Description { get; set; } public string Description { get; private set; }
public bool Explicit { get; set; } public bool Explicit { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public List<Image> Images { get; set; } public List<Image> Images { get; private set; }
public bool IsExternallyHosted { get; set; } public bool IsExternallyHosted { get; private set; }
public List<string> Languages { get; set; } public List<string> Languages { get; private set; }
public string MediaType { get; set; } public string MediaType { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public string Publisher { get; set; } public string Publisher { get; private set; }
public string Type { get; set; } public string Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -6,22 +6,22 @@ namespace SpotifyAPI.Web
{ {
public class SimpleTrack public class SimpleTrack
{ {
public List<SimpleArtist> Artists { get; set; } public List<SimpleArtist> Artists { get; private set; }
public List<string> AvailableMarkets { get; set; } public List<string> AvailableMarkets { get; private set; }
public int DiscNumber { get; set; } public int DiscNumber { get; private set; }
public int DurationMs { get; set; } public int DurationMs { get; private set; }
public bool Explicit { get; set; } public bool Explicit { get; private set; }
public Dictionary<string, string> ExternalUrls { get; set; } public Dictionary<string, string> ExternalUrls { get; private set; }
public string Href { get; set; } public string Href { get; private set; }
public string Id { get; set; } public string Id { get; private set; }
public bool IsPlayable { get; set; } public bool IsPlayable { get; private set; }
public LinkedTrack LinkedFrom { get; set; } public LinkedTrack LinkedFrom { get; private set; }
public string Name { get; set; } public string Name { get; private set; }
public string PreviewUrl { get; set; } public string PreviewUrl { get; private set; }
public int TrackNumber { get; set; } public int TrackNumber { get; private set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public ItemType Type { get; set; } public ItemType Type { get; private set; }
public string Uri { get; set; } public string Uri { get; private set; }
} }
} }

View File

@ -2,6 +2,6 @@ namespace SpotifyAPI.Web
{ {
public class SnapshotResponse public class SnapshotResponse
{ {
public string SnapshotId { get; set; } public string SnapshotId { get; private set; }
} }
} }

View File

@ -5,7 +5,7 @@ namespace SpotifyAPI.Web
{ {
static private readonly URIParameterFormatProvider _provider = new URIParameterFormatProvider(); static private readonly URIParameterFormatProvider _provider = new URIParameterFormatProvider();
public static Uri API_V1 = new Uri("https://api.spotify.com/v1/"); public static readonly Uri APIV1 = new Uri("https://api.spotify.com/v1/");
public static Uri Me() => EUri($"me"); public static Uri Me() => EUri($"me");

View File

@ -39,7 +39,7 @@ namespace SpotifyAPI.Web
throw new ArgumentException("String is empty or null", name); throw new ArgumentException("String is empty or null", name);
} }
public static void ArgumentNotNullOrEmptyList<T>(List<T> value, string name) public static void ArgumentNotNullOrEmptyList<T>(IList<T> value, string name)
{ {
if (value != null && value.Any()) if (value != null && value.Any())
{ {

View File

@ -2,6 +2,7 @@ using System;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
[AttributeUsage(AttributeTargets.Field)]
public class StringAttribute : Attribute public class StringAttribute : Attribute
{ {
public StringAttribute(string value) public StringAttribute(string value)

View File

@ -16,7 +16,7 @@ namespace SpotifyAPI.Web
return formatType == typeof(ICustomFormatter) ? _formatter : null; return formatType == typeof(ICustomFormatter) ? _formatter : null;
} }
public class URIParameterFormatter : ICustomFormatter private class URIParameterFormatter : ICustomFormatter
{ {
public string Format(string format, object arg, IFormatProvider formatProvider) public string Format(string format, object arg, IFormatProvider formatProvider)
{ {