Skip to content

mtfriesen/RiotSharp

 
 

Repository files navigation

RiotSharp

Join the chat at https://gitter.im/BenFradet/RiotSharp NuGet version Build status Stories in Ready

C# Wrapper for the Riot Games API

Documentation can be found here.

Features

  • No need to worry about the 10 requests per 10s or the 500 requests per 10m rate limits, they are already implemented in the wrapper
  • LINQ support
  • Synchronous and asynchronous API
  • Caching for the Static API

Installation

Install RiotSharp through NuGet:

PM> Install-Package RiotSharp

or

  1. Clone the repo (https://github.com/BenFradet/RiotSharp.git) or download the zip file.

  2. Build the RiotSharp project and add the library to your own application.

Usage

Main API

In order to use the api you need an api key which you can get here.

Entry point to the api if you do not own a production API key:

var api = RiotApi.GetDevelopmentInstance("YOUR_API_KEY");

If you do own a production API key you can specify your own rate limits:

var api = RiotApi.GetInstance("YOUR_API_KEY",
  yourRateLimitPer10s, yourRateLimitPer10m);

To get a summoner:

try
{
  var summoner = api.GetSummonerByName(Region.euw, "StopOFlop");
}
catch (RiotSharpException ex)
{
  // Handle the exception however you want.
}

You can find a list of all the available operations in RiotApi in the documentation.

Tournament API

You first have to apply for a tournament API key here.

Entry point for the tournament API:

var tournamentApi = TournamentRiotApi.GetInstance("TOURNAMENT_API_KEY");

Next up, create a provider. The url will receive callbacks with match results.

var provider = tournamentApi.CreateProvider(Region.euw, url);

And create a tournament:

var tournament = tournamentApi.CreateTournament(provider.Id, "TOURNAMENT_NAME");

Now you can create tournament codes (which you can use to join games):

var tournamentCode = tournamentApi.CreateTournamentCode(tournament.Id,
    teamSize, allowedSummonerIds, TournamentSpectatorType.All,
    TournamentPickType.TournamentDraft, TournamentMapType.SummonnersRift,
    string.Empty);

The tournament code can now be entered in the client to join a game with the specified settings. Please note that you should save the provider and tournament IDs if you wish to create more tournament codes later on. You should not create a separate provider and tournament ID for every tournament code. Make sure to read Riot's guidelines on this topic.

To create a Tournament object for an existing tournament, use the following syntax:

var tournament = new Tournament { Id = id };

You can then create codes in two ways:

tournament.CreateTournamentCode(teamSize, allowedSummonerIds,
    TournamentSpectatorType.All, TournamentPickType.TournamentDraft,
    TournamentMapType.SummonnersRift, string.Empty);

or, alternatively, if you do not wish to create a separate Tournament object, you can call the CreateTournamentCode method directly from the API as shown previously.

You can find a list of all the available operations in TournamentRiotApi in the documentation.

Static API

You can retrieve static information about the game thanks to the static API, there is no rate limiting on this API and RiotSharp caches as much data as possible to make as few calls as possible.

First, as with the others APIs you need to obtain an instance of the API:

var staticApi = StaticRiotApi.GetInstance("API_KEY");

Then, you can, for example, retrieve data about champions:

var champions = staticApi.GetChampions(Region.euw, ChampionData.all).Champions.Values;
foreach (var champion in champions)
{
    Console.WriteLine(champ.Name);
    Console.WriteLine(champ.Lore);
}

Additionally, you can use the regular api and static api to, for example, retrieve champion masteries for the summoner:

try
{
    var championMasteries =  api.GetChampionMasteries(RiotSharp.Misc.Region.na, summoner.Id);
}
catch (RiotSharpException ex)
{
  // Handle the exception however you want.
}

foreach (var championMastery in championMasteries)
{
    var id = championMastery.ChampionId;
    var name = staticApi.GetChampion(RiotSharp.Misc.Region.euw, id).Name;
    var level = championMastery.ChampionLevel;
    var points = championMastery.ChampionPoints;

    Console.WriteLine($" •  **Level {level} {name}** {points} Points");
}

You can find a list of all the available operations in StaticRiotApi in the Documentation.

Status API

You can also retrieve information available on status.leagueoflegends.com with the Status API. This API is not constrained to the rate limiting and you do not have to supply an API key.

var statusApi = StatusRiotApi.GetInstance();
var shardStatuses = statusApi.GetShardStatus(Region.euw);
foreach (var service in shardStatuses.Services)
{
    Console.WriteLine(service.Name);
    foreach (var incident in service.Incidents)
    {
        incident.Updates.ForEach(u => Console.WriteLine("  " + u.Content));
    }
}

You can find a list of all the available operations in StatusRiotApi in the documentation.

For a full description check the RiotSharpExample or RiotSharpTest projects.

Contribution

Simply send a pull request! The up-for-grabs label is a great place to start.

When adding new features, please provide the related unit tests within the pull request. To run the unit tests you need to modify the App.config file and fill out the appropriate values so the tests can run.

Moreover, the documentation is far from perfect so every bit of help is more than welcome.

Libraries used

This wrapper uses Json.NET.

License

This wrapper is under the MIT license.

Disclaimer

RiotSharp isn't 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. League of Legends and Riot Games are trademarks or registered trademarks of Riot Games, Inc. League of Legends © Riot Games, Inc.

About

C# wrapper for the Riot Games API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%