re-add .net standard 2.0 support

This commit is contained in:
Jonas Dellinger 2023-11-03 23:23:54 +01:00
parent 4aea443038
commit c5400fc937
12 changed files with 35 additions and 12 deletions

View File

@ -10,6 +10,9 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
dotnet-version: "4.8.1"
- uses: actions/setup-dotnet@v1 - uses: actions/setup-dotnet@v1
with: with:
dotnet-version: "5.x" dotnet-version: "5.x"
@ -49,21 +52,25 @@ jobs:
- name: Upload to GH Release - name: Upload to GH Release
if: startsWith( github.ref, 'refs/tags/') if: startsWith( github.ref, 'refs/tags/')
run: | run: |
zip -j SpotifyAPI.Web-netstandard2.0.zip SpotifyAPI.Web/bin/Release/netstandard2.0/*
zip -j SpotifyAPI.Web-netstandard2.1.zip SpotifyAPI.Web/bin/Release/netstandard2.1/* zip -j SpotifyAPI.Web-netstandard2.1.zip SpotifyAPI.Web/bin/Release/netstandard2.1/*
zip -j SpotifyAPI.Web-net5.0.zip SpotifyAPI.Web/bin/Release/net5.0/* zip -j SpotifyAPI.Web-net5.0.zip SpotifyAPI.Web/bin/Release/net5.0/*
zip -j SpotifyAPI.Web-net6.0.zip SpotifyAPI.Web/bin/Release/net6.0/* zip -j SpotifyAPI.Web-net6.0.zip SpotifyAPI.Web/bin/Release/net6.0/*
zip -j SpotifyAPI.Web-net7.0.zip SpotifyAPI.Web/bin/Release/net7.0/* zip -j SpotifyAPI.Web-net7.0.zip SpotifyAPI.Web/bin/Release/net7.0/*
zip -j SpotifyAPI.Web.Auth-netstandard2.0.zip SpotifyAPI.Web.Auth/bin/Release/netstandard2.0/*
zip -j SpotifyAPI.Web.Auth-netstandard2.1.zip SpotifyAPI.Web.Auth/bin/Release/netstandard2.1/* zip -j SpotifyAPI.Web.Auth-netstandard2.1.zip SpotifyAPI.Web.Auth/bin/Release/netstandard2.1/*
zip -j SpotifyAPI.Web.Auth-net5.0.zip SpotifyAPI.Web.Auth/bin/Release/net5.0/* zip -j SpotifyAPI.Web.Auth-net5.0.zip SpotifyAPI.Web.Auth/bin/Release/net5.0/*
zip -j SpotifyAPI.Web.Auth-net6.0.zip SpotifyAPI.Web.Auth/bin/Release/net6.0/* zip -j SpotifyAPI.Web.Auth-net6.0.zip SpotifyAPI.Web.Auth/bin/Release/net6.0/*
zip -j SpotifyAPI.Web.Auth-net7.0.zip SpotifyAPI.Web.Auth/bin/Release/net7.0/* zip -j SpotifyAPI.Web.Auth-net7.0.zip SpotifyAPI.Web.Auth/bin/Release/net7.0/*
hub release edit \ hub release edit \
-a "SpotifyAPI.Web-netstandard2.0.zip" \
-a "SpotifyAPI.Web-netstandard2.1.zip" \ -a "SpotifyAPI.Web-netstandard2.1.zip" \
-a "SpotifyAPI.Web-net5.0.zip" \ -a "SpotifyAPI.Web-net5.0.zip" \
-a "SpotifyAPI.Web-net6.0.zip" \ -a "SpotifyAPI.Web-net6.0.zip" \
-a "SpotifyAPI.Web-net7.0.zip" \ -a "SpotifyAPI.Web-net7.0.zip" \
-a "SpotifyAPI.Web.Auth-netstandard2.0.zip" \
-a "SpotifyAPI.Web.Auth-netstandard2.1.zip" \ -a "SpotifyAPI.Web.Auth-netstandard2.1.zip" \
-a "SpotifyAPI.Web.Auth-net5.0.zip" \ -a "SpotifyAPI.Web.Auth-net5.0.zip" \
-a "SpotifyAPI.Web.Auth-net6.0.zip" \ -a "SpotifyAPI.Web.Auth-net6.0.zip" \

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1</TargetFrameworks> <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<PackageId>SpotifyAPI.Web.Auth</PackageId> <PackageId>SpotifyAPI.Web.Auth</PackageId>

View File

@ -42,6 +42,7 @@ namespace SpotifyAPI.Web
CancellationToken cancel = default CancellationToken cancel = default
); );
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
/// <summary> /// <summary>
/// Fetches all pages and returns one by one using IAsyncEnumerable /// Fetches all pages and returns one by one using IAsyncEnumerable
/// </summary> /// </summary>
@ -71,5 +72,6 @@ namespace SpotifyAPI.Web
IAPIConnector connector, IAPIConnector connector,
CancellationToken cancel = default CancellationToken cancel = default
); );
#endif
} }
} }

View File

@ -131,6 +131,7 @@ namespace SpotifyAPI.Web
CancellationToken cancellationToken = default! CancellationToken cancellationToken = default!
); );
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
/// <summary> /// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8 /// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// The default paginator will fetch all available resources without a delay between requests. /// The default paginator will fetch all available resources without a delay between requests.
@ -167,6 +168,7 @@ namespace SpotifyAPI.Web
IPaginator? paginator = default!, IPaginator? paginator = default!,
CancellationToken cancel = default! CancellationToken cancel = default!
); );
#endif
public Task<Paging<T>> NextPage<T>(Paging<T> paging); public Task<Paging<T>> NextPage<T>(Paging<T> paging);

View File

@ -69,6 +69,7 @@ namespace SpotifyAPI.Web
return results; return results;
} }
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
public async IAsyncEnumerable<T> Paginate<T>( public async IAsyncEnumerable<T> Paginate<T>(
IPaginatable<T> firstPage, IPaginatable<T> firstPage,
IAPIConnector connector, IAPIConnector connector,
@ -125,5 +126,6 @@ namespace SpotifyAPI.Web
} }
} }
} }
#endif
} }
} }

View File

@ -196,7 +196,7 @@ namespace SpotifyAPI.Web
return FetchPage<TNext>(paging.Previous); return FetchPage<TNext>(paging.Previous);
} }
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
/// <summary> /// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8 /// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// The default paginator will fetch all available resources without a delay between requests. /// The default paginator will fetch all available resources without a delay between requests.
@ -303,5 +303,6 @@ namespace SpotifyAPI.Web
yield return item; yield return item;
} }
} }
#endif
} }
} }

View File

@ -221,7 +221,11 @@ namespace SpotifyAPI.Web.Http
{ {
if (_authenticator != null if (_authenticator != null
&& !request.Endpoint.IsAbsoluteUri && !request.Endpoint.IsAbsoluteUri
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|| request.Endpoint.AbsoluteUri.Contains("https://api.spotify.com", StringComparison.InvariantCulture)) || request.Endpoint.AbsoluteUri.Contains("https://api.spotify.com", StringComparison.InvariantCulture))
#else
|| request.Endpoint.AbsoluteUri.Contains("https://api.spotify.com"))
#endif
{ {
await _authenticator!.Apply(request, this).ConfigureAwait(false); await _authenticator!.Apply(request, this).ConfigureAwait(false);
} }

View File

@ -50,10 +50,10 @@ namespace SpotifyAPI.Web.Http
// We only support text stuff for now // We only support text stuff for now
using var content = responseMsg.Content; using var content = responseMsg.Content;
var headers = responseMsg.Headers.ToDictionary(header => header.Key, header => header.Value.First()); var headers = responseMsg.Headers.ToDictionary(header => header.Key, header => header.Value.First());
#if NETSTANDARD2_1 #if NET5_0_OR_GREATER
var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false);
#else
var body = await responseMsg.Content.ReadAsStringAsync(cancel).ConfigureAwait(false); var body = await responseMsg.Content.ReadAsStringAsync(cancel).ConfigureAwait(false);
#else
var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false);
#endif #endif
var contentType = content.Headers?.ContentType?.MediaType; var contentType = content.Headers?.ContentType?.MediaType;

View File

@ -7,7 +7,6 @@ namespace SpotifyAPI.Web.Http
{ {
private const string OnRequestFormat = "\n{0} {1} [{2}] {3}"; 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)); Ensure.ArgumentNotNull(request, nameof(request));
@ -23,12 +22,14 @@ namespace SpotifyAPI.Web.Http
Console.WriteLine(OnRequestFormat, 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)
{ {
Ensure.ArgumentNotNull(response, nameof(response)); Ensure.ArgumentNotNull(response, nameof(response));
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
string? body = response.Body?.ToString()?.Replace("\n", "", StringComparison.InvariantCulture); string? body = response.Body?.ToString()?.Replace("\n", "", StringComparison.InvariantCulture);
#else
string? body = response.Body?.ToString()?.Replace("\n", "");
#endif
body = body?.Substring(0, Math.Min(50, body.Length)); body = body?.Substring(0, Math.Min(50, body.Length));
Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body); Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body);
} }

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1</TargetFrameworks> <TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<PackageId>SpotifyAPI.Web</PackageId> <PackageId>SpotifyAPI.Web</PackageId>

View File

@ -63,11 +63,11 @@ namespace SpotifyAPI.Web
private static byte[] ComputeSHA256(string value) private static byte[] ComputeSHA256(string value)
{ {
#if NETSTANDARD2_1_OR_GREATER #if NET5_0_OR_GREATER
return SHA256.HashData(Encoding.UTF8.GetBytes(value));
#else
using var hash = SHA256.Create(); using var hash = SHA256.Create();
return hash.ComputeHash(Encoding.UTF8.GetBytes(value)); return hash.ComputeHash(Encoding.UTF8.GetBytes(value));
#else
return SHA256.HashData(Encoding.UTF8.GetBytes(value));
#endif #endif
} }
} }

View File

@ -15,7 +15,11 @@ namespace SpotifyAPI.Web
public string Value { get; } public string Value { get; }
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
public static bool GetValue(Type enumType, Enum enumValue, [NotNullWhen(true)] out string? result) public static bool GetValue(Type enumType, Enum enumValue, [NotNullWhen(true)] out string? result)
#else
public static bool GetValue(Type enumType, Enum enumValue, out string? result)
#endif
{ {
Ensure.ArgumentNotNull(enumType, nameof(enumType)); Ensure.ArgumentNotNull(enumType, nameof(enumType));
Ensure.ArgumentNotNull(enumValue, nameof(enumValue)); Ensure.ArgumentNotNull(enumValue, nameof(enumValue));