pekka-royaleapi-client - Pekka.RoyaleApi.Client 3.0.0-pre12
P.E.K.K.A is a client library targeting .NET Standard 2.0 and .NET 4.6.1 that provides an easy way to interact with the unofficial public API for Clash Royale (https://royaleapi.com/)
PM> Install-Package Pekka.RoyaleApi.Client -Version 3.0.0-pre12 -Source https://www.myget.org/F/pekka-royaleapi-client/api/v3/index.json
> nuget.exe install Pekka.RoyaleApi.Client -Version 3.0.0-pre12 -Source https://www.myget.org/F/pekka-royaleapi-client/api/v3/index.json
> dotnet add package Pekka.RoyaleApi.Client --version 3.0.0-pre12 --source https://www.myget.org/F/pekka-royaleapi-client/api/v3/index.json
source https://www.myget.org/F/pekka-royaleapi-client/api/v3/index.json
nuget Pekka.RoyaleApi.Client ~> 3.0.0-pre12
Copy to clipboard
> choco install Pekka.RoyaleApi.Client --version 3.0.0-pre12 --source https://www.myget.org/F/pekka-royaleapi-client/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "pekka-royaleapi-client" -SourceLocation "https://www.myget.org/F/pekka-royaleapi-client/api/v2"
Install-Module -Name "Pekka.RoyaleApi.Client" -RequiredVersion "3.0.0-pre12" -Repository "pekka-royaleapi-client" -AllowPreRelease
Copy to clipboard
P.E.K.K.A - Clash Royale API (official) and Royale API (unofficial) Client Library for .NET
P.E.K.K.A is a client library (C# wrapper) targeting .NET Standard 2.0 and .NET 4.6.1 that provides an easy way to interact with both official Clash Royale API and unofficial public API Royale API
All API requests must be accompanied by a developer key. You need to register then create a key for Clash Royale API (official) on Clash Royale API Website. You can learn how to obtain and manage your developer key for Royale API (unofficial) on Royale API Website.
Stable | Nightly | |
---|---|---|
Clash Royale API Client | ||
Royale API Client |
Supported Platforms
- .NET 4.6.1 (Desktop / Server)
- .NET Standard 2.0
Features
- Dependency injection friendly (can also be used standalone, see below)
- Supports async and sync (via extension method, see below) calls.
Continuous integration
Table of Contents
Installation
Logo | Stable | Nightly | |
---|---|---|---|
P.E.K.K.A Clash Royale API (official) | |||
P.E.K.K.A Royale API (unofficial) |
Following commands can be used to install both Pekka.ClashRoyaleApi.Client and Pekka.RoyaleApi.Client, run the following command in the Package Manager Console
Install-Package Pekka.ClashRoyaleApi.Client
Install-Package Pekka.RoyaleApi.Client
Or use dotnet cli
dotnet Pekka.ClashRoyaleApi.Client
dotnet Pekka.RoyaleApi.Client
Usage
The usage of both Pekka.ClashRoyaleApi.Client and Pekka.RoyaleApi.Client libraries are similar. And both can be used with any DI library, or it can be used standalone.
Standalone Initialization
If you do not want to use any DI framework, you have to instantiate ClashRoyaleApiStandalone
or RoyaleApiStandalone
as follows.
RoyaleApiStandalone Usage
ApiOptions apiOptions = new ApiOptions("<your token>", "https://api.royaleapi.com/");
var apiClientContext = RoyaleApiStandalone.Create(apiOptions);
IPlayerClient playerClient = apiClientContext.PlayerClient;
IClanClient clanClient = apiClientContext.ClanClient;
IVersionClient clanClient = apiClientContext.VersionClient;
ClashRoyaleApiStandalone Usage
ApiOptions apiOptions = new ApiOptions("<your token>", "https://api.clashroyale.com/v1/");
var apiClientContext = ClashRoyaleApiStandalone.Create(apiOptions);
IPlayerClient playerClient = apiClientContext.PlayerClient;
IClanClient clanClient = apiClientContext.ClanClient;
ITournamentClient tournamentClient = apiClientContext.TournamentClient;
ICardClient cardClient = apiClientContext.CardClient;
ILocationClient locationClient = apiClientContext.LocationClient;
apiClientContext
contains all necessary clients.
Microsoft.Extensions.DependencyInjection Initialization
First, you need to install Microsoft.Extensions.DependencyInjection
and Microsoft.Extensions.Http
NuGet package as follows
dotnet add package Microsoft.Extensions.DependencyInjection
dotnet add package Microsoft.Extensions.Http
By installing Microsoft.Extensions.Http
you will be able to use HttpClientFactory
.In the words of the ASP.NET Team it is “an opinionated factory for creating HttpClient instances” and is a new feature comes with the release of ASP.NET Core 2.1.
If you don't want to use HttpClientFactory
, you must register HttpClient
yourself with the container.
Clash Royale Api
Register necessary dependencies to ServiceCollection
as follows
ApiOptions apiOptions = new ApiOptions("<your token>", "https://api.clashroyale.com/v1/");
var services = new ServiceCollection();
services.AddSingleton(apiOptions);
services.AddHttpClient<IRestApiClient, RestApiClient>((provider, client) =>
{
var options = provider.GetRequiredService<ApiOptions>();
client.BaseAddress = new Uri(options.BaseUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", options.BearerToken);
});
services.AddTransient<IPlayerClient, PlayerClient>();
services.AddTransient<IClanClient, ClanClient>();
services.AddTransient<ITournamentClient, TournamentClient>();
services.AddTransient<ICardClient, CardClient>();
services.AddTransient<ILocationClient, LocationClient>();
services.AddTransient<IGlobalTournamentClient, GlobalTournamentClient>();
ServiceProvider buildServiceProvider = services.BuildServiceProvider();
var playerClient = buildServiceProvider.GetRequiredService<IPlayerClient>();
var clanClient = buildServiceProvider.GetRequiredService<IClanClient>();
var tournamentClient = buildServiceProvider.GetRequiredService<ITournamentClient>();
var cardClient = buildServiceProvider.GetRequiredService<ICardClient>();
var locationClient = buildServiceProvider.GetRequiredService<ILocationClient>();
var globalTournamentClient = buildServiceProvider.GetRequiredService<IGlobalTournamentClient>();
See sandbox project for more examples.
Royale Api
Register necessary dependencies to ServiceCollection
as follows
ApiOptions apiOptions = new ApiOptions("<your token>", "https://api.royaleapi.com/");
var services = new ServiceCollection();
services.AddSingleton(apiOptions);
services.AddHttpClient<IRestApiClient, RestApiClient>((provider, client) =>
{
var options = provider.GetRequiredService<ApiOptions>();
client.BaseAddress = new Uri(options.BaseUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", options.BearerToken);
});
services.AddTransient<IPlayerClient, PlayerClient>();
services.AddTransient<IClanClient, ClanClient>();
services.AddTransient<IVersionClient, VersionClient>();
services.AddTransient<IConstantClient, ConstantClient>();
var buildServiceProvider = services.BuildServiceProvider();
var playerClient = buildServiceProvider.GetRequiredService<IPlayerClient>();
var clanClient = buildServiceProvider.GetRequiredService<IClanClient>();
var versionClient = buildServiceProvider.GetRequiredService<IVersionClient>();
var constantClient = buildServiceProvider.GetRequiredService<IConstantClient>();
var restApiClient = buildServiceProvider.GetRequiredService<IRestApiClient>();
See sandbox project for more examples.
Call Endpoints
There are two ways to call an endpoint. The only difference is the return types. The methods that end with ResponseAsync returns ApiResponse<TModel>
which contains model itself, HTTP status codes, error message and response headers.
ApiResponse<Player> playerResponse = await playerClient.GetPlayerResponseAsync(playerTag);
if(playerResponse.Error)
{
HttpStatusCode statusCode = playerResponse.HttpStatusCode;
string errorMessage = playerResponse.Message;
IDictionary<string, string> headers = playerResponse.Headers;
string urlPath = playerResponse.UrlPath;
// Handle http error
}
Player player = playerResponse.Model;
The methods that end with Async returns model itself without additional HTTP response information. But in the case of HTTP error, you need to handle exceptions.
Player player = await playerClient.GetPlayerAsync(playerTag);
Synchronous Wrapper
For synchronous calls, Task extension method RunSync
can be used.
var player = playerClient.GetPlayerResponseAsync(playerTag).RunSync();
But there is a possibility that this extension method can't cover all cases. See Stackoverflow article
License
Licensed under MIT, see LICENSE for the full text.
-
.NETFramework 4.6.1
- Newtonsoft.Json (>= 11.0.1 && < 13.0.0)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 11.0.1 && < 13.0.0)
- .NETFramework 4.6.1: 4.6.1.0
- .NETStandard 2.0: 2.0.0.0
OwnersDeniz İrgin |
AuthorsDeniz İrgin |
Project URLhttps://github.com/Blind-Striker/clash-royale-client-dotnet |
LicenseMIT |
Tagsclashroyale, clash-royale-api, clash-royale, client-library, dotnet-core, dotnet, unofficial |
Info7 total downloads |
0 downloads for version 3.0.0-pre12 |
Download (141.9 KB) |
Found on the current feed only |
Package history
Version | Size | Last updated | Downloads | Mirrored? | |||
---|---|---|---|---|---|---|---|
3.0.1-pre1 | 141.9 KB | Wed, 09 Oct 2019 10:34:50 GMT | 1 | ||||
3.0.0-pre5 | 142.1 KB | Fri, 13 Sep 2019 13:09:34 GMT | 1 | ||||
3.0.0-pre3 | 142.09 KB | Fri, 13 Sep 2019 11:08:33 GMT | 0 | ||||
3.0.0-pre16 | 141.89 KB | Wed, 09 Oct 2019 08:06:55 GMT | 0 | ||||
3.0.0-pre15 | 141.9 KB | Wed, 09 Oct 2019 06:53:24 GMT | 1 | ||||
3.0.0-pre13 | 141.89 KB | Tue, 08 Oct 2019 19:43:28 GMT | 1 | ||||
3.0.0-pre12 | 141.9 KB | Tue, 08 Oct 2019 19:30:02 GMT | 0 | ||||
3.0.0-pre11 | 141.9 KB | Tue, 08 Oct 2019 15:49:27 GMT | 1 | ||||
3.0.0-pre10 | 141.89 KB | Tue, 08 Oct 2019 15:46:44 GMT | 1 | ||||
1.0.2.1 | 141.18 KB | Thu, 12 Sep 2019 19:34:00 GMT | 1 |