Compare commits

..

12 Commits

Author SHA1 Message Date
Jonas Dellinger
46be74abd0 fix build: switch from hub to gh cli 2023-11-03 23:52:20 +01:00
Jonas Dellinger
94b2978126 chore: also ignore outdated SDK in tests 2023-11-03 23:41:49 +01:00
Jonas Dellinger
c5be9e4bd5 fix docs: specify lock file for caching 2023-11-03 23:39:14 +01:00
Jonas Dellinger
35b13341e6 fix docs: re-order pnpm setup action 2023-11-03 23:37:11 +01:00
Jonas Dellinger
d9bf33632b fix docs: update actions 2023-11-03 23:36:08 +01:00
Jonas Dellinger
a777f759e9 fix docs: update actions, explicitly run deploy pnpm script 2023-11-03 23:34:06 +01:00
Jonas Dellinger
a2f434968a fix build: setup pnpm, update image tags and ignore out of date warning for SDK versions 2023-11-03 23:31:40 +01:00
Jonas Dellinger
74a0f266b7 fix build: remove wrong sdk version 2023-11-03 23:26:45 +01:00
Jonas Dellinger
c5400fc937 re-add .net standard 2.0 support 2023-11-03 23:23:54 +01:00
Jonas Dellinger
4aea443038 use recommendations for latest .NET versions 2023-11-03 22:57:55 +01:00
Jonas Dellinger
16d898b344 add cancellationToken to another override of PaginateAll 2023-11-03 22:50:45 +01:00
Jonas Dellinger
21d9a5ff16 switch to pnpm and update packages 2023-11-03 22:43:54 +01:00
21 changed files with 9739 additions and 8046 deletions

View File

@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "5.x"
- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.x"
- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.203"
- name: Set RELEASE_VERSION
@ -49,25 +49,28 @@ 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.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.1.zip" \
-a "SpotifyAPI.Web.Auth-net5.0.zip" \
-a "SpotifyAPI.Web.Auth-net6.0.zip" \
-a "SpotifyAPI.Web.Auth-net7.0.zip" \
-m "" "$RELEASE_VERSION"
gh release upload "$RELEASE_VERSION" \
"SpotifyAPI.Web-netstandard2.0.zip" \
"SpotifyAPI.Web-netstandard2.1.zip" \
"SpotifyAPI.Web-net5.0.zip" \
"SpotifyAPI.Web-net6.0.zip" \
"SpotifyAPI.Web-net7.0.zip" \
"SpotifyAPI.Web.Auth-netstandard2.0.zip" \
"SpotifyAPI.Web.Auth-netstandard2.1.zip" \
"SpotifyAPI.Web.Auth-net5.0.zip" \
"SpotifyAPI.Web.Auth-net6.0.zip" \
"SpotifyAPI.Web.Auth-net7.0.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -10,11 +10,17 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.JS
uses: actions/setup-node@v1
uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
node-version: 18.12.1
version: 8
- name: Use Node.JS
uses: actions/setup-node@v3
with:
node-version: v20.9.0
cache: "pnpm"
cache-dependency-path: |
SpotifyAPI.Docs/pnpm-lock.yaml
- name: Setup GitHub Deploy SSH Key
uses: webfactory/ssh-agent@v0.4.1
with:

View File

@ -5,13 +5,13 @@ This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern
### Installation
```
$ yarn
$ pnpm
```
### Local Development
```
$ yarn start
$ pnpm start
```
This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.
@ -19,7 +19,7 @@ This command starts a local development server and open up a browser window. Mos
### Build
```
$ yarn build
$ pnpm build
```
This command generates static content into the `build` directory and can be served using any static contents hosting service.
@ -27,7 +27,7 @@ This command generates static content into the `build` directory and can be serv
### Deployment
```
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
$ GIT_USER=<Your GitHub username> USE_SSH=true pnpm deploy
```
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.

View File

@ -8,5 +8,5 @@ git config --global user.email "jonas@dellinger.dev"
git config --global user.name "GH Actions Docs Builder"
cd ./SpotifyAPI.Docs
yarn
USE_SSH=true GIT_USER=JohnnyCrazy yarn deploy
pnpm i --frozen-lockfile
USE_SSH=true GIT_USER=JohnnyCrazy pnpm run deploy

View File

@ -14,11 +14,12 @@
}
},
"dependencies": {
"@docusaurus/core": "^2.4.1",
"@docusaurus/preset-classic": "^2.4.1",
"@docusaurus/core": "^3.0.0",
"@docusaurus/preset-classic": "^3.0.0",
"@mdx-js/react": "^3.0.0",
"classnames": "^2.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-github-btn": "^1.2.0"
},
"browserslist": {
@ -35,7 +36,7 @@
},
"devDependencies": {
"import-sort-style-module": "^6.0.0",
"prettier": "^2.8.8",
"prettier": "^3.0.3",
"prettier-plugin-import-sort": "^0.0.7"
}
}

9635
SpotifyAPI.Docs/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
{
"version-5.1.1/someSidebar": [
"someSidebar": [
{
"type": "category",
"label": "SpotifyAPI-NET",
"items": [
{
"type": "doc",
"id": "version-5.1.1/home"
"id": "home"
}
]
},
@ -16,59 +16,59 @@
"items": [
{
"type": "doc",
"id": "version-5.1.1/web/getting_started"
"id": "web/getting_started"
},
{
"type": "doc",
"id": "version-5.1.1/web/albums"
"id": "web/albums"
},
{
"type": "doc",
"id": "version-5.1.1/web/artists"
"id": "web/artists"
},
{
"type": "doc",
"id": "version-5.1.1/web/browse"
"id": "web/browse"
},
{
"type": "doc",
"id": "version-5.1.1/web/follow"
"id": "web/follow"
},
{
"type": "doc",
"id": "version-5.1.1/web/library"
"id": "web/library"
},
{
"type": "doc",
"id": "version-5.1.1/web/personalization"
"id": "web/personalization"
},
{
"type": "doc",
"id": "version-5.1.1/web/player"
"id": "web/player"
},
{
"type": "doc",
"id": "version-5.1.1/web/playlists"
"id": "web/playlists"
},
{
"type": "doc",
"id": "version-5.1.1/web/profiles"
"id": "web/profiles"
},
{
"type": "doc",
"id": "version-5.1.1/web/proxy"
"id": "web/proxy"
},
{
"type": "doc",
"id": "version-5.1.1/web/search"
"id": "web/search"
},
{
"type": "doc",
"id": "version-5.1.1/web/tracks"
"id": "web/tracks"
},
{
"type": "doc",
"id": "version-5.1.1/web/utilities"
"id": "web/utilities"
}
]
},
@ -78,23 +78,23 @@
"items": [
{
"type": "doc",
"id": "version-5.1.1/auth/getting_started"
"id": "auth/getting_started"
},
{
"type": "doc",
"id": "version-5.1.1/auth/implicit_grant"
"id": "auth/implicit_grant"
},
{
"type": "doc",
"id": "version-5.1.1/auth/authorization_code"
"id": "auth/authorization_code"
},
{
"type": "doc",
"id": "version-5.1.1/auth/client_credentials"
"id": "auth/client_credentials"
},
{
"type": "doc",
"id": "version-5.1.1/auth/token_swap"
"id": "auth/token_swap"
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -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>
@ -23,6 +23,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<NoWarn>1591</NoWarn>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(APPVEYOR)' == 'true'">

View File

@ -4,6 +4,7 @@
<TargetFrameworks>net7.0;net6.0;net5.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -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
}
}

View File

@ -120,15 +120,18 @@ namespace SpotifyAPI.Web
/// <param name="firstPage">A first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">The cancellation-token to allow to cancel the request.</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns>A list containing all fetched pages</returns>
Task<IList<T>> PaginateAll<T, TNext>(
IPaginatable<T, TNext> firstPage,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = default!
IPaginator? paginator = default!,
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.
@ -142,7 +145,7 @@ namespace SpotifyAPI.Web
IAsyncEnumerable<T> Paginate<T>(
IPaginatable<T> firstPage,
IPaginator? paginator = default!,
CancellationToken cancel = default!
CancellationToken cancel = default
);
/// <summary>
@ -165,6 +168,7 @@ namespace SpotifyAPI.Web
IPaginator? paginator = default!,
CancellationToken cancel = default!
);
#endif
public Task<Paging<T>> NextPage<T>(Paging<T> paging);

View File

@ -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
}
}

View File

@ -109,16 +109,18 @@ namespace SpotifyAPI.Web
/// <param name="firstPage">A first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">The cancellation-token to allow to cancel the request.</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns>A list containing all fetched pages</returns>
public Task<IList<T>> PaginateAll<T, TNext>(
IPaginatable<T, TNext> firstPage,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = null
IPaginator? paginator = null,
CancellationToken cancellationToken = default
)
{
return (paginator ?? DefaultPaginator).PaginateAll(firstPage, mapper, _apiConnector);
return (paginator ?? DefaultPaginator).PaginateAll(firstPage, mapper, _apiConnector, cancellationToken);
}
private Task<T> FetchPage<T>(string? nextUrl)
@ -194,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.
@ -301,5 +303,6 @@ namespace SpotifyAPI.Web
yield return item;
}
}
#endif
}
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -21,9 +21,9 @@ namespace SpotifyAPI.Web
var body = new JObject();
var type = GetType();
if (!_bodyParamsCache.IsEmpty && _bodyParamsCache.ContainsKey(type))
if (!_bodyParamsCache.IsEmpty && _bodyParamsCache.TryGetValue(type, out var bodyParamsCached))
{
foreach (var (info, attribute) in _bodyParamsCache[type])
foreach (var (info, attribute) in bodyParamsCached)
{
AddBodyParam(body, info, attribute);
}
@ -70,9 +70,9 @@ namespace SpotifyAPI.Web
var queryParams = new Dictionary<string, string>();
var type = GetType();
if (!_queryParamsCache.IsEmpty && _queryParamsCache.ContainsKey(type))
if (!_queryParamsCache.IsEmpty && _queryParamsCache.TryGetValue(type, out var queryParamsCached))
{
foreach (var (info, attribute) in _queryParamsCache[type])
foreach (var (info, attribute) in queryParamsCached)
{
AddQueryParam(queryParams, info, attribute);
}

View File

@ -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>
@ -24,6 +24,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<NoWarn>1591</NoWarn>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">

View File

@ -63,8 +63,12 @@ namespace SpotifyAPI.Web
private static byte[] ComputeSHA256(string value)
{
#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));
#endif
}
}
}

View File

@ -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));