- Notifications
You must be signed in to change notification settings - Fork143
C# wrapper for the Riot Games API
License
BenFradet/RiotSharp
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
C# Wrapper for theRiot Games API
- 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 DataDragon (Static API)
Install RiotSharp through NuGet:
PM> Install-Package RiotSharp
or
Clone the repo (https://github.com/BenFradet/RiotSharp.git) ordownload the zip file.
Build the RiotSharp project and add the library to your own application.
You can build your own NuGet package of the latest version with the following command:
dotnet pack /p:Configuration=Release
Execute it from the Visual Studio developer command prompt from inside the RiotSharp project folder.Then copy theRiotSharp.*.nupkg
file from thebin
folder into your local NuGet feed.Create local NuGet feed
In order to use the API you need an API key which you can gethere.
Entry point to the API if you do not own a production API key:
varapi=RiotApi.GetDevelopmentInstance("YOUR_API_KEY");
If you do own a production API key you can specify your own rate limits:
varapi=RiotApi.GetInstance("YOUR_API_KEY",yourRateLimitPer10s,yourRateLimitPer10m);
To get basic data of a summoner:
try{varsummoner=api.Summoner.GetSummonerByNameAsync(Region.Euw,"SUMMONER_NAME").Result;varname=summoner.Name;varlevel=summoner.Level;varaccountId=summoner.AccountId;}catch(RiotSharpExceptionex){// Handle the exception however you want.}
Each class represents an API:
- Account
- Champion
- League
- Match
- Spectator
- Status
- Summoner
- ChampionMastery
- StaticData
- ThirdParty
You can find a list of all the available operations inRiotApi in the documentationor test some queries on theRiot Developer Portal
You first have to apply for a tournament API keyhere.
Entry point for the tournament API:
vartournamentApi=TournamentRiotApi.GetInstance("TOURNAMENT_API_KEY");
Next up, create a provider.The url will receive callbacks with match results.
varprovider=tournamentApi.CreateProvider(Region.Euw,url);
And create a tournament:
vartournament=tournamentApi.CreateTournament(provider.Id,"TOURNAMENT_NAME");
Now you can create tournament codes (which you can use to join games):
vartournamentCode=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'sguidelines on this topic.
To create a Tournament object for an existing tournament, use the following syntax:
vartournament=newTournament{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 theCreateTournamentCode
method directly from the API as shown previously.
You can find a list of all the available operations inTournamentRiotApi in the documentation.
You can retrieve static information about the game thanks to the static API (Data Dragon), there is no rate limiting on this API and RiotSharpcaches as much data as possible to make as few calls as possible.
DataDragon API is hidden in Main API.
varsomeData=api.DataDragon.SomeEndpoint.SomeMethod();
For example, you can retrieve data about all champions:
varallVersion=api.DataDragon.Versions.GetAllAsync().Result;varlatestVersion=allVersion[0];// Example of version: "10.23.1"varchampions=api.DataDragon.Champions.GetAllAsync(latestVersion).Result.Champions.Values;foreach(varchampioninchampions){Console.WriteLine(champion.Name);Console.WriteLine(champion.Lore);}
Additionally, you can use the regular API and static API to, for example, retrieve champion masteries for the summoner:
List<ChampionMastery>championMasteries;try{championMasteries=api.ChampionMastery.GetChampionMasteriesAsync(summoner.Region,summoner.Id).Result;}catch(RiotSharpExceptionex){// Handle the exception however you want.return;}foreach(varchampionMasteryinchampionMasteries){varid=championMastery.ChampionId;varname=api.DataDragon.Champions.GetAllAsync(latestVersion).Result.Champions.Values.Single(x=>x.Id==id).Name;// using System.Linq;varlevel=championMastery.ChampionLevel;varpoints=championMastery.ChampionPoints;Console.WriteLine($" • **Level{level}{name}**{points} Points");}
For a full description check theRiotSharpTest project.
Simply send a pull request! Theup-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 theApp.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.
This wrapper usesJson.NET.
This wrapper is under theMIT license.
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