SpeedrunDotComAPI 1.0.0

dotnet add package SpeedrunDotComAPI --version 1.0.0
                    
NuGet\Install-Package SpeedrunDotComAPI -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpeedrunDotComAPI" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SpeedrunDotComAPI" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SpeedrunDotComAPI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SpeedrunDotComAPI --version 1.0.0
                    
#r "nuget: SpeedrunDotComAPI, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SpeedrunDotComAPI@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SpeedrunDotComAPI&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SpeedrunDotComAPI&version=1.0.0
                    
Install as a Cake Tool

SpeedrunDotComAPI

SpeedrunDotComAPI is a .NET wrapper for the speedrun.com API.

The other C# wrapper made by the LiveSplit team is quite old and made for .NET Framework. I also just personally think this wrapper is quite a bit cleaner and more modern in general.

This API binding is around 95% complete. The things that are omitted are either things that I don't think could be implemented cleanly or which I felt would never be used by any sane human being (the /guests endpoint, for instance). If the unimplemented behavior is desirable to you, feel free to submit a pull request (or just yell at me).

How to Use

Import the project and create a new instance of SRCApiClient. If you have an SRC API token, you can pass it into the constructor here.

using SpeedrunDotComAPI;

...

SRCApiClient src = new SRCApiClient(cfg.SpeedrunToken);

This client has sub-clients for the main API endpoints such as GameApiClient, RunApiClient, etc, which then have functions for accessing the API. There also exists RawDataQuery which just takes in a query after the main /api/v1/ endpoint and returns dynamic, if you really need to use it.

CategoryModel[] sm64Categories = await src.Games.GetSingleGameCategories("sm64");
CategoryModel seventyStar = sm64Categories.First(c => c.Name == "70 Star");
LeaderboardModel[] leaderboards = await src.Categories.GetSingleCategoryRecords(seventyStar.Id); // Returns a list of leaderboards because of categories with ILs.
RunPlaceModel worldRecord = leaderboards[0].Runs.First(r => r.Place == 1);

Returned data from these functions is in the form of pure data struct Models and have no helper functions for navigating them. This may change in the future for things that make sense but right now this wrapper is attempting to be very simple.

For the small-scape sub-APIs like platforms, regions, engines, etc, these are contained in MetadataApiClient as it was easiest to deduplicate them that way.

Methods that deal with API calls directly do not do any internal exception handling. It's expected of the user to handle HttpRequestException if you are capable of passing in an invalid ID to one of these functions. Methods like GetAllGames just return an empty list for bad filter options, so you don't need to handle it there. JsonException is not expected to be thrown, so this should be reported here as a bug if it does happen.

ProfileApiClient and NotificationsApiClient both require a proper API key passed into the initial client in order to function.

Filter and Embed Options

API methods that query over large sets of elements can have filter options passed into them, in accordance with the SRC API. For paginated resources, you can change the Max elements returned or the page Offset. All filter options can be ordered by certain values (see the SRC API for what these are, sorry see issue #1), and have the order direction changed.

GameModel[] filtered = await src.Games.GetAllGames(new() { Name = "super mario", _Bulk = true });

API methods that can have resources embedded (e.g. embedding the category resources into a game resource) can specify which resources to embed.

GameModel sm64 = await src.Games.GetSingleGame("sm64", new() { Categories = true, Genres = true });

Contact

Contact me at mirrorcult#9528 on Discord if you have questions or concerns, or just create a GitHub issue.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 459 4/23/2022