Skip to content

Client library (C# wrapper) written in .NET 8.0 that provides an easy way to interact with the official Clash Royale API directly or through proxy

License

Notifications You must be signed in to change notification settings

rodrigopiccelli/MageCorp.ClashRoyaleApi.Client

Repository files navigation

MageCorp.ClashRoyaleApi.Client

Client library (C# wrapper) written in .NET (7.0/8.0) that provides an easy way to interact with the official Clash Royale API directly or through proxy

Stable
Clash Royale API Client NuGet

Supported Platforms

  • .Net 7.0; .Net 8.0

Features

  • Dependency injection ready (can also be used standalone, see below)
  • Supports async calls.

Table of Contents

  1. Installation
  2. Usage
  3. License

Installation

Logo Stable
Clash Royale API Client NuGet

Following commands can be used to install MageCorp.ClashRoyaleApi.Client, run the following command in the Package Manager Console

NuGet\Install-Package MageCorp.ClashRoyaleApi.Client

Or use dotnet cli

dotnet add package MageCorp.ClashRoyaleApi.Client

Usage

Standalone Initialization

If you do not want to use any DI framework, you have to instantiate ClashRoyaleApiClient as follows.

ClashRoyaleApiClient Standalone Usage

ApiOptions apiOptions = new("<your token>");
var clashRoyaleApiClient = ClashRoyaleApiClient.Create(apiOptions);
var playersService = clashRoyaleApiClient.PlayersService;
var clansService = clashRoyaleApiClient.ClansService;

clashRoyaleApiClient contains all necessary clients.

Microsoft.Extensions.DependencyInjection Initialization

First, you need to install Microsoft.Extensions.DependencyInjection NuGet package as follows

dotnet add package Microsoft.Extensions.DependencyInjection

Clash Royale Api

Register necessary dependencies to ServiceCollection as follows

var serviceProvider = new ServiceCollection()
    .AddClashRoyaleApiClient("<yor token>")
    .BuildServiceProvider();

Or

var serviceProvider = new ServiceCollection()
    .AddClashRoyaleApiClient(new ApiOptions("<your token>"))
    .BuildServiceProvider();

Getting services:

var cardsService = serviceProvider.GetRequiredService<ICardsService>();
var challengesService = serviceProvider.GetRequiredService<IChallengesService>();
var clansService = serviceProvider.GetRequiredService<IClansService>();
var globalTournamentsService = serviceProvider.GetRequiredService<IGlobalTournamentsService>();
var locationsService = serviceProvider.GetRequiredService<ILocationsService>();
var playersService = serviceProvider.GetRequiredService<IPlayersService>();
var tournamentsService = serviceProvider.GetRequiredService<ITournamentsService>();

Using Configuration

There is an extension that supports Microsoft.Extensions.Configuration to store the ApiOptions configuration as follows

{
  "ApiOptions": {
    "BearerToken": "<your token>",
    "ApiAddress": "https://api.clashroyale.com",
    "ApiVerstion": "v1",
    "UseProxy": false,
    "ProxyAddress": "https://proxy.royaleapi.dev"
  }
}
string basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
var configuration = new ConfigurationBuilder()
    .SetBasePath(basePath)
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables()
    .Build();
    
var serviceProvider = new ServiceCollection()
    .AddClashRoyaleApiClient(provider => {
        //you can use provider to get any required service needed to initialize your ApiOptions
        return configuration.GetApiOptionsSection("<sectionName>"); //if you don't specify the sectionName it will be "ApiOptions" by default
    })
    .BuildServiceProvider();

License

Licensed under MIT, see LICENSE for the full text.

About

Client library (C# wrapper) written in .NET 8.0 that provides an easy way to interact with the official Clash Royale API directly or through proxy

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages