Portal2Boards.Net

Build Status Build Version Release Version NuGet Version

Retrieve Portal 2 challenge mode data from the speedrunning community board.portal2.sr. Client includes automatic caching system and exception event for logging purposes.

Examples

Credits

Documentation

Namespaces

Namespace Description
Portal2Boards Client for fetching changelog, chamber, profile, aggregated data, demo content, wall of shame and donators.
Portal2Boards.API.Models API models converted from raw json.
Portal2Boards.Extensions Useful extension methods.

Client

Usage

using Portal2Boards;

using (var client = new Portal2BoardsClient("MyApplication/1.0"))
{
    // Do stuff
}

Caching

// Everything will be handled automatically
// This is default
_client.AutoCache = true;

// Reset to default time (5 minutes)
_client.CacheResetTime = 0;

// Stop caching
_client.AutoCache = false;

// Reset timer manually
await _client.ResetCacheTimer();

// Clear cache manually
await _client.ClearCache();

Logging

// Logs client-side exceptions
_client.Log += LogPortal2Boards;

Task LogPortal2Boards(object sender, LogMessage msg)
{
    // Log stuff
}

Changelog

Query

// Default
var changelog = await _client.GetChangelogAsync();

// Get all wrs within 24h
changelog = await _client.GetChangelogAsync("?maxDaysAgo=1&wr=1");

Advanced

var changelog = await _client.GetChangelogAsync(q =>
{
  // Names will be escaped automatically
  q.ProfileName = "Portal Rex";
  q.WorldRecord = true;
});

// With builder
changelog = await _client.GetChangelogAsync(() =>
  new ChangelogQueryBuilder()
    .WithWorldRecord(true)
    .WithDemo(true)
    .Build()
);

Chamber

// By map id (ulong)
var chamber = await _client.GetChamberAsync(id);

// With extensions
using Portal2Boards.Net.Extensions;
var map = await Portal2Map.Search("Smooth Jazz");
chamber = await _client.GetChamberAsync(map);

Profile

// By name (spaces will be removed automatically)
var profile = await _client.GetProfileAsync("Portal Rex");

// By steam id (ulong)
profile = await _client.GetProfileAsync(id);

Aggregated

// Overall
var aggregated = await _client.GetAggregatedAsync();

// Mode
aggregated = await _client.GetAggregatedAsync(AggregatedMode.SinglePlayer);

// Chapter
aggregated = await _client.GetAggregatedAsync(ChapterType.ThePartWhereHeKillsYou);

Demo Content

// Use changelog id (ulong)
var bytes = await _client.GetDemoContentAsync(id);

Wall of Shame

var wos = await _client.GetWallOfShameAsync();

foreach (SteamUser user in wos)
{
  Console.WriteLine($"{user.Name}");
}

Donators

var donators = await _client.GetAggregatedAsync();

foreach (Donator donator in donators)
{
  Console.Write($"{donator.Player.Name}: ");
  Console.WriteLine($"€{donator.DonationAmount:N2}");
}

Relations

relations.png

Entity interfaces can be casted to its actual type which exposes methods for fetching another entity or updating itself.

Profile pro = await _client.GetProfileAsync(id);
Changelog clog = await pro.GetChangelogAsync();

Changelog, Chamber, Profile and Aggregated implement the IUpdatable interface for easy access to the root client.

Profile pro = await _client.GetProfileAsync(id);
await pro.UpdateAsync(true); // true forces cache update

Note: WallOfShame and DemoContent do not have its own entity type.

Extensions

_ = Portal2Map.Search("Portal Gun");

// Converts to 3.9f
Console.WriteLine(390u.AsTime());

// Prints "1:00.00"
Console.WriteLine(6000u.AsTimeToString());

// Prints in "yyyy-MM-dd HH:mm:ss" format
Console.WriteLine(DateTime.Now.DateTimeToString());