mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2025-01-10 21:57:46 +00:00
re-add .net standard 2.0 support
This commit is contained in:
parent
4aea443038
commit
c5400fc937
7
.github/workflows/cicd.yaml
vendored
7
.github/workflows/cicd.yaml
vendored
@ -10,6 +10,9 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: "4.8.1"
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: "5.x"
|
||||
@ -49,21 +52,25 @@ jobs:
|
||||
- name: Upload to GH Release
|
||||
if: startsWith( github.ref, 'refs/tags/')
|
||||
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-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-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-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-net7.0.zip SpotifyAPI.Web.Auth/bin/Release/net7.0/*
|
||||
|
||||
hub release edit \
|
||||
-a "SpotifyAPI.Web-netstandard2.0.zip" \
|
||||
-a "SpotifyAPI.Web-netstandard2.1.zip" \
|
||||
-a "SpotifyAPI.Web-net5.0.zip" \
|
||||
-a "SpotifyAPI.Web-net6.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-net5.0.zip" \
|
||||
-a "SpotifyAPI.Web.Auth-net6.0.zip" \
|
||||
|
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<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>
|
||||
<Nullable>enable</Nullable>
|
||||
<PackageId>SpotifyAPI.Web.Auth</PackageId>
|
||||
|
@ -42,6 +42,7 @@ namespace SpotifyAPI.Web
|
||||
CancellationToken cancel = default
|
||||
);
|
||||
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Fetches all pages and returns one by one using IAsyncEnumerable
|
||||
/// </summary>
|
||||
@ -71,5 +72,6 @@ namespace SpotifyAPI.Web
|
||||
IAPIConnector connector,
|
||||
CancellationToken cancel = default
|
||||
);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ namespace SpotifyAPI.Web
|
||||
CancellationToken cancellationToken = default!
|
||||
);
|
||||
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
|
||||
/// The default paginator will fetch all available resources without a delay between requests.
|
||||
@ -167,6 +168,7 @@ namespace SpotifyAPI.Web
|
||||
IPaginator? paginator = default!,
|
||||
CancellationToken cancel = default!
|
||||
);
|
||||
#endif
|
||||
|
||||
public Task<Paging<T>> NextPage<T>(Paging<T> paging);
|
||||
|
||||
|
@ -69,6 +69,7 @@ namespace SpotifyAPI.Web
|
||||
return results;
|
||||
}
|
||||
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
||||
public async IAsyncEnumerable<T> Paginate<T>(
|
||||
IPaginatable<T> firstPage,
|
||||
IAPIConnector connector,
|
||||
@ -125,5 +126,6 @@ namespace SpotifyAPI.Web
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ namespace SpotifyAPI.Web
|
||||
return FetchPage<TNext>(paging.Previous);
|
||||
}
|
||||
|
||||
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
|
||||
/// The default paginator will fetch all available resources without a delay between requests.
|
||||
@ -303,5 +303,6 @@ namespace SpotifyAPI.Web
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +221,11 @@ namespace SpotifyAPI.Web.Http
|
||||
{
|
||||
if (_authenticator != null
|
||||
&& !request.Endpoint.IsAbsoluteUri
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
||||
|| 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);
|
||||
}
|
||||
|
@ -50,10 +50,10 @@ namespace SpotifyAPI.Web.Http
|
||||
// We only support text stuff for now
|
||||
using var content = responseMsg.Content;
|
||||
var headers = responseMsg.Headers.ToDictionary(header => header.Key, header => header.Value.First());
|
||||
#if NETSTANDARD2_1
|
||||
var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
#else
|
||||
#if NET5_0_OR_GREATER
|
||||
var body = await responseMsg.Content.ReadAsStringAsync(cancel).ConfigureAwait(false);
|
||||
#else
|
||||
var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
#endif
|
||||
var contentType = content.Headers?.ContentType?.MediaType;
|
||||
|
||||
|
@ -7,7 +7,6 @@ namespace SpotifyAPI.Web.Http
|
||||
{
|
||||
private const string OnRequestFormat = "\n{0} {1} [{2}] {3}";
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")]
|
||||
public void OnRequest(IRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
@ -23,12 +22,14 @@ namespace SpotifyAPI.Web.Http
|
||||
Console.WriteLine(OnRequestFormat, request.Method, request.Endpoint, parameters, request.Body);
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")]
|
||||
public void OnResponse(IResponse response)
|
||||
{
|
||||
Ensure.ArgumentNotNull(response, nameof(response));
|
||||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
|
||||
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));
|
||||
Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<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>
|
||||
<Nullable>enable</Nullable>
|
||||
<PackageId>SpotifyAPI.Web</PackageId>
|
||||
|
@ -63,11 +63,11 @@ namespace SpotifyAPI.Web
|
||||
|
||||
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();
|
||||
return hash.ComputeHash(Encoding.UTF8.GetBytes(value));
|
||||
#else
|
||||
return SHA256.HashData(Encoding.UTF8.GetBytes(value));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,11 @@ namespace SpotifyAPI.Web
|
||||
|
||||
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)
|
||||
#else
|
||||
public static bool GetValue(Type enumType, Enum enumValue, out string? result)
|
||||
#endif
|
||||
{
|
||||
Ensure.ArgumentNotNull(enumType, nameof(enumType));
|
||||
Ensure.ArgumentNotNull(enumValue, nameof(enumValue));
|
||||
|
Loading…
Reference in New Issue
Block a user