mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
Made more fields nullable, they can be excluded using fields query param, fixes #477
This commit is contained in:
parent
6f0e1b6f80
commit
f3c8a9d620
@ -26,7 +26,7 @@ else
|
|||||||
|
|
||||||
private PrivateUser _me;
|
private PrivateUser _me;
|
||||||
|
|
||||||
private int _totalPlaylistCount;
|
private int? _totalPlaylistCount;
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ else
|
|||||||
|
|
||||||
private PrivateUser _me;
|
private PrivateUser _me;
|
||||||
|
|
||||||
private int _totalPlaylistCount;
|
private int? _totalPlaylistCount;
|
||||||
|
|
||||||
private Uri _authUri;
|
private Uri _authUri;
|
||||||
|
|
||||||
|
@ -64,6 +64,10 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
Ensure.ArgumentNotNull(firstPage, nameof(firstPage));
|
Ensure.ArgumentNotNull(firstPage, nameof(firstPage));
|
||||||
Ensure.ArgumentNotNull(connector, nameof(connector));
|
Ensure.ArgumentNotNull(connector, nameof(connector));
|
||||||
|
if (firstPage.Items == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("The first page has to contain an Items list!", nameof(firstPage));
|
||||||
|
}
|
||||||
|
|
||||||
var page = firstPage;
|
var page = firstPage;
|
||||||
foreach (var item in page.Items)
|
foreach (var item in page.Items)
|
||||||
@ -73,7 +77,7 @@ namespace SpotifyAPI.Web
|
|||||||
while (page.Next != null)
|
while (page.Next != null)
|
||||||
{
|
{
|
||||||
page = await connector.Get<Paging<T>>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false);
|
page = await connector.Get<Paging<T>>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false);
|
||||||
foreach (var item in page.Items)
|
foreach (var item in page.Items!)
|
||||||
{
|
{
|
||||||
yield return item;
|
yield return item;
|
||||||
}
|
}
|
||||||
@ -89,6 +93,10 @@ namespace SpotifyAPI.Web
|
|||||||
Ensure.ArgumentNotNull(firstPage, nameof(firstPage));
|
Ensure.ArgumentNotNull(firstPage, nameof(firstPage));
|
||||||
Ensure.ArgumentNotNull(mapper, nameof(mapper));
|
Ensure.ArgumentNotNull(mapper, nameof(mapper));
|
||||||
Ensure.ArgumentNotNull(connector, nameof(connector));
|
Ensure.ArgumentNotNull(connector, nameof(connector));
|
||||||
|
if (firstPage.Items == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("The first page has to contain an Items list!", nameof(firstPage));
|
||||||
|
}
|
||||||
|
|
||||||
var page = firstPage;
|
var page = firstPage;
|
||||||
foreach (var item in page.Items)
|
foreach (var item in page.Items)
|
||||||
@ -99,7 +107,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
var next = await connector.Get<TNext>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false);
|
var next = await connector.Get<TNext>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false);
|
||||||
page = mapper(next);
|
page = mapper(next);
|
||||||
foreach (var item in page.Items)
|
foreach (var item in page.Items!)
|
||||||
{
|
{
|
||||||
yield return item;
|
yield return item;
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,17 @@ namespace SpotifyAPI.Web
|
|||||||
public interface IPaginatable<T>
|
public interface IPaginatable<T>
|
||||||
{
|
{
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
|
||||||
string Next { get; set; }
|
string? Next { get; set; }
|
||||||
|
|
||||||
List<T> Items { get; set; }
|
List<T>? Items { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IPaginatable<T, TNext>
|
public interface IPaginatable<T, TNext>
|
||||||
{
|
{
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
|
||||||
string Next { get; set; }
|
string? Next { get; set; }
|
||||||
|
|
||||||
List<T> Items { get; set; }
|
List<T>? Items { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,8 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
if (StringAttribute.GetValue(enumType, enumVal, out var stringVal))
|
if (StringAttribute.GetValue(enumType, enumVal, out var stringVal))
|
||||||
{
|
{
|
||||||
valueList.Add(stringVal);
|
// .netstandard2.0 requires !
|
||||||
|
valueList.Add(stringVal!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +132,8 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
if (StringAttribute.GetValue(enumType, valueAsEnum, out var stringVal))
|
if (StringAttribute.GetValue(enumType, valueAsEnum, out var stringVal))
|
||||||
{
|
{
|
||||||
valueList.Add(stringVal);
|
// .netstandard2.0 requires !
|
||||||
|
valueList.Add(stringVal!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queryParams.Add(attribute.Key ?? prop.Name, string.Join(",", valueList));
|
queryParams.Add(attribute.Key ?? prop.Name, string.Join(",", valueList));
|
||||||
|
@ -5,9 +5,9 @@ namespace SpotifyAPI.Web
|
|||||||
public class CursorPaging<T> : IPaginatable<T>
|
public class CursorPaging<T> : IPaginatable<T>
|
||||||
{
|
{
|
||||||
public string Href { get; set; } = default!;
|
public string Href { get; set; } = default!;
|
||||||
public List<T> Items { get; set; } = default!;
|
public List<T>? Items { get; set; } = default!;
|
||||||
public int Limit { get; set; }
|
public int Limit { get; set; }
|
||||||
public string Next { get; set; } = default!;
|
public string? Next { get; set; } = default!;
|
||||||
public Cursor Cursors { get; set; } = default!;
|
public Cursor Cursors { get; set; } = default!;
|
||||||
public int Total { get; set; }
|
public int Total { get; set; }
|
||||||
}
|
}
|
||||||
@ -15,9 +15,9 @@ namespace SpotifyAPI.Web
|
|||||||
public class CursorPaging<T, TNext> : IPaginatable<T, TNext>
|
public class CursorPaging<T, TNext> : IPaginatable<T, TNext>
|
||||||
{
|
{
|
||||||
public string Href { get; set; } = default!;
|
public string Href { get; set; } = default!;
|
||||||
public List<T> Items { get; set; } = default!;
|
public List<T>? Items { get; set; } = default!;
|
||||||
public int Limit { get; set; }
|
public int Limit { get; set; }
|
||||||
public string Next { get; set; } = default!;
|
public string? Next { get; set; } = default!;
|
||||||
public Cursor Cursors { get; set; } = default!;
|
public Cursor Cursors { get; set; } = default!;
|
||||||
public int Total { get; set; }
|
public int Total { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -3,23 +3,23 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
public class FullPlaylist
|
public class FullPlaylist
|
||||||
{
|
{
|
||||||
public bool Collaborative { get; set; }
|
public bool? Collaborative { get; set; }
|
||||||
public Dictionary<string, string> ExternalUrls { get; set; } = default!;
|
public Dictionary<string, string>? ExternalUrls { get; set; } = default!;
|
||||||
public string Href { get; set; } = default!;
|
public string? Href { get; set; } = default!;
|
||||||
public string Id { get; set; } = default!;
|
public string? Id { get; set; } = default!;
|
||||||
public List<Image> Images { get; set; } = default!;
|
public List<Image>? Images { get; set; } = default!;
|
||||||
public string Name { get; set; } = default!;
|
public string? Name { get; set; } = default!;
|
||||||
public PublicUser Owner { get; set; } = default!;
|
public PublicUser? Owner { get; set; } = default!;
|
||||||
public bool Public { get; set; }
|
public bool? Public { get; set; }
|
||||||
public string SnapshotId { get; set; } = default!;
|
public string? SnapshotId { get; set; } = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
|
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
|
public Paging<PlaylistTrack<IPlayableItem>>? Tracks { get; set; } = default!;
|
||||||
public string Type { get; set; } = default!;
|
public string? Type { get; set; } = default!;
|
||||||
public string Uri { get; set; } = default!;
|
public string? Uri { get; set; } = default!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,24 +4,24 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
public class Paging<T> : IPaginatable<T>
|
public class Paging<T> : IPaginatable<T>
|
||||||
{
|
{
|
||||||
public string Href { get; set; } = default!;
|
public string? Href { get; set; } = default!;
|
||||||
public List<T> Items { get; set; } = default!;
|
public List<T>? Items { get; set; } = default!;
|
||||||
public int Limit { get; set; }
|
public int? Limit { get; set; } = default!;
|
||||||
public string Next { get; set; } = default!;
|
public string? Next { get; set; } = default!;
|
||||||
public int Offset { get; set; }
|
public int? Offset { get; set; } = default!;
|
||||||
public string Previous { get; set; } = default!;
|
public string? Previous { get; set; } = default!;
|
||||||
public int Total { get; set; }
|
public int? Total { get; set; } = default!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Paging<T, TNext> : IPaginatable<T, TNext>
|
public class Paging<T, TNext> : IPaginatable<T, TNext>
|
||||||
{
|
{
|
||||||
public string Href { get; set; } = default!;
|
public string? Href { get; set; } = default!;
|
||||||
public List<T> Items { get; set; } = default!;
|
public List<T>? Items { get; set; } = default!;
|
||||||
public int Limit { get; set; }
|
public int? Limit { get; set; } = default!;
|
||||||
public string Next { get; set; } = default!;
|
public string? Next { get; set; } = default!;
|
||||||
public int Offset { get; set; }
|
public int? Offset { get; set; } = default!;
|
||||||
public string Previous { get; set; } = default!;
|
public string? Previous { get; set; } = default!;
|
||||||
public int Total { get; set; }
|
public int? Total { get; set; } = default!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user