aj-r / RiotNet

A .NET/C# client for the Riot Games API
MIT License
23 stars 10 forks source link

RiotNet

NuGet build

A .NET/C# client for the Riot Games API.

It has the following features:

RiotNet is NOT endorsed by Riot Games and doesn't reflect the views or opinions of Riot Games or anyone officially involved in producing or managing League of Legends.

Versions

This library uses semantic versioning, so version numbers are not correlated with version numbers of the Riot API.

Basic Usage

IRiotClient client = new RiotClient(new RiotClientSettings
{
    ApiKey = "00000000-0000-0000-0000-000000000000" // Replace this with your API key, of course.
});
Summoner summoner = await client.GetSummonerBySummonerNameAsync("<name>", PlatformId.NA1).ConfigureAwait(false);

Changing the default settings

You can change the default settings that are applied to new RiotClient instances, so you don't need to pass the settings every time.

RiotClient.DefaultPlatformId = PlatformId.EUW1;
RiotClient.DefaultSettings = () => new RiotClientSettings
{
    ApiKey = "00000000-0000-0000-0000-000000000000" // Replace this with your API key, of course.
};
IRiotClient client = new RiotClient(); // Now you don't need to pass the settings or platform ID parameters.

Rate limiting

RiotNet will automatically handle rate limiting for you, so you don't need to worry about building your own rate limiting system. RiotNet handles rate limiting in two ways:

Proactive Rate Limiting

Reactive Rate Limiting (header-based)

If you go over your rate limit, and the client receives a rate limit error from the server, it will read the Retry-After header, and wait for that amount of time before retrying the request.

Interim Keys for the Tournament API

If you are using the Tournament API, you will probably get an interim key during development. The interim key uses slightly different routes, so you need to set UseTournamentStub to true in the settings:

RiotClient.DefaultSettings = () => new RiotClientSettings
{
    ApiKey = "00000000-0000-0000-0000-000000000000", // Replace this with your API key, of course.
    UseTournamentStub = true,
};

Just don't forget to set it to false once you go into production!

Error Handling

You can customize how the RiotClient handles errors from the server. By default, it will retry the request up to 3 times if there is a server error or rate limit error. If the error still occurs on the third try, it will throw an exception.

You can change that behaviour by using the following settings:

More examples

See the tests for more extensive examples.

Contributions

Dependencies