|
1 | | -## Patreon Client Api |
| 1 | +## Patreon Api |
| 2 | +[](https://www.nuget.org/packages/Patreon.Api) |
| 3 | +[](https://github.com/LykosAI/Patreon.Api/actions/workflows/build.yml) |
| 4 | + |
2 | 5 |
|
3 | | -- A .NET client for Patreon OAuth v2.0 API, using [Refit](https://github.com/reactiveui/refit) |
| 6 | +A minimal .NET Client for [Patreon API v2](https://docs.patreon.com/) using Refit and Polly. Supports automatic refresh of expired access tokens. |
4 | 7 |
|
| 8 | +## Usage |
| 9 | +### Setup with Dependency Injection |
| 10 | +```csharp |
| 11 | +using Patreon.Api.Extensions; |
| 12 | + |
| 13 | +var services = new ServiceCollection(); |
| 14 | + |
| 15 | +services.AddPatreonApi(options => |
| 16 | +{ |
| 17 | + options.ClientId = "your-client-id"; |
| 18 | + options.ClientSecret = "your-client-secret"; |
| 19 | +}); |
| 20 | +``` |
| 21 | + |
| 22 | +### Inject the IPatreonApi Polly Client to use |
| 23 | +```csharp |
| 24 | +using Patreon.Api; |
| 25 | + |
| 26 | +public class MyService(IPatreonApi patreonApi) |
| 27 | +{ |
| 28 | + public async Task GetTiers() |
| 29 | + { |
| 30 | + AuthorizationTokens tokens = new() |
| 31 | + { |
| 32 | + AccessToken = "your-user-access-token", |
| 33 | + RefreshToken = "your-user-refresh-token" |
| 34 | + }; |
| 35 | + |
| 36 | + PatreonIdentityResponse response = await patreonApi.GetIdentity( |
| 37 | + include: "memberships.campaign,memberships.currently_entitled_tiers" |
| 38 | + authorization: tokens |
| 39 | + ); |
| 40 | + |
| 41 | + // If automatic token refresh occured, the `tokens` object will have updated properties with the new tokens |
| 42 | + // - tokens.AccessToken |
| 43 | + // - tokens.AccessTokenExpiration |
| 44 | + // - tokens.RefreshToken |
| 45 | + |
| 46 | + IReadOnlyList<string>? tiers = response.GetTierIds("your-campaign-id"); |
| 47 | + } |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +## Contributing |
| 52 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
| 53 | + |
| 54 | +## License |
| 55 | +This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details. |
| 56 | + |
| 57 | +## Disclaimers |
| 58 | +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. |
0 commit comments