Using the Orbit API is easy:
- Get the latest version from NuGet (use the badge above)
- Create a new class that inherits
OrbitClient
and fill someprotected
values out:
public class DragonFruitOrbitClient : OrbitClient
{
//only set this if you are using API v1 features, otherwise it's useless
protected override string LegacyApiKey => "abcdefg";
//as with above, but instead ONLY in the case you'll be making session token requests for API v2
protected override uint ClientId => 12221;
protected override string ClientSecret => "abcdefg";
protected override OsuSessionTokenBase GetSessionToken()
{
//in here you need to write a method for getting an osu! access token that is **still valid**. This is called if there is no token in a private field or the exising token is expired
//for a server you might want to use this.Perform(new OsuSessionCredentialRequest())
//for a client you might want to contact your server with the user's refresh token and request a new access key.
//in any scenario, you should **write the result to a file and check it first**, Orbit converts the "expires_in" to a datetime, so you can store it in a file
}
}
- Create a new instance of your class (you should only need one for the lifetime of the app):
public static class Clients
{
public static readonly DragonFruitOrbitClient Client = new DragonFruitOrbitClient();
}
var user = Clients.Client.GetCurrentUser();
public void ConfigureServices(IServiceCollection services)
{
//configure mvc, razor, auth, etc.
services.AddSingleton<DragonFruitOrbitClient>();
}
You need to access this inside something else that is dependency-injected, like a controller or service
public class UserController : Controller
{
private readonly DragonFruitOrbitClient _client;
public UserController(DragonFruitOrbitClient client)
{
_client = client;
}
[HttpGet]
public IActionResult Index()
{
_client.GetUser("PaPaCurry");
}
}