-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,58 @@ | ||
## Patreon Client Api | ||
## Patreon Api | ||
[![NuGet Version](https://img.shields.io/nuget/v/Patreon.Api)](https://www.nuget.org/packages/Patreon.Api) | ||
[![Build](https://github.com/LykosAI/Patreon.Api/actions/workflows/build.yml/badge.svg)](https://github.com/LykosAI/Patreon.Api/actions/workflows/build.yml) | ||
![GitHub License](https://img.shields.io/github/license/LykosAI/Patreon.Api) | ||
|
||
- A .NET client for Patreon OAuth v2.0 API, using [Refit](https://github.com/reactiveui/refit) | ||
A minimal .NET Client for [Patreon API v2](https://docs.patreon.com/) using Refit and Polly. Supports automatic refresh of expired access tokens. | ||
|
||
## Usage | ||
### Setup with Dependency Injection | ||
```csharp | ||
using Patreon.Api.Extensions; | ||
|
||
var services = new ServiceCollection(); | ||
|
||
services.AddPatreonApi(options => | ||
{ | ||
options.ClientId = "your-client-id"; | ||
options.ClientSecret = "your-client-secret"; | ||
}); | ||
``` | ||
|
||
### Inject the IPatreonApi Polly Client to use | ||
```csharp | ||
using Patreon.Api; | ||
|
||
public class MyService(IPatreonApi patreonApi) | ||
{ | ||
public async Task GetTiers() | ||
{ | ||
AuthorizationTokens tokens = new() | ||
{ | ||
AccessToken = "your-user-access-token", | ||
RefreshToken = "your-user-refresh-token" | ||
}; | ||
|
||
PatreonIdentityResponse response = await patreonApi.GetIdentity( | ||
include: "memberships.campaign,memberships.currently_entitled_tiers" | ||
authorization: tokens | ||
); | ||
|
||
// If automatic token refresh occured, the `tokens` object will have updated properties with the new tokens | ||
// - tokens.AccessToken | ||
// - tokens.AccessTokenExpiration | ||
// - tokens.RefreshToken | ||
IReadOnlyList<string>? tiers = response.GetTierIds("your-campaign-id"); | ||
} | ||
} | ||
``` | ||
|
||
## Contributing | ||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
|
||
## License | ||
This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details. | ||
|
||
## Disclaimers | ||
All trademarks, logos, and brand names are the property of their respective owners. All company, product and service names used in this document and licensed applications are for identification purposes only. Use of these names, trademarks, and brands does not imply endorsement. |