fatton139 / DotnetOsrsApiWrapper

A .NET Wrapper for the OSRS highscores API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DotnetOsrsApiWrapper

A .NET Wrapper for the OSRS highscores API.

Installation

https://www.nuget.org/packages/DotnetOsrsApiWrapper

Updates

Updating the package is rather simple, you just need to add the new skill (if one ever comes out) and/or Activity (boss/minigame) in the correct order it appears from the API. The order can be found here https://runescape.wiki/w/Application_programming_interface#Hiscores_Lite_2 . You just need to add the new field to the PlayerInfo class in the appropiate spot and the package will take care of the rest.

Eg adding a new bosses called Zulrah2 and Zul that appears after and before zulrah respectively in the API list is as simple as editing PlayerInfo to be

public Activity Zul { get; set; } = InitialActivityState;
public Activity Zulrah { get; set; } = InitialActivityState;
public Activity Zulrah2 { get; set; } = InitialActivityState;

Usage

The API processing code has now been moved to PlayerInfoService. You will need to pass in an instance of HttpClient to call out to the OSRS Hiscores API. The calls are Async, so you will need to await the call to use the result.

var service = new PlayerInfoService(new HttpClient());
// Single Username
PlayerInfo playerInfo = await service.GetPlayerInfoAsync("Worstjibs");
// Multiple Usernames
IEnumerable<PlayerInfo> playerInfoList = await service.GetPlayerInfoAsync(new[] { "Worstjibs", "Assasindie" });

If you are using IServiceCollection DI Container, you can inject a Scoped instance of PlayerInfoService to your container using this extension method.

public void ConfigureServices(IServiceCollection services) {
     services.AddOsrsWrapper();
}

Then inject the wrapper into your registered services using the IPlayerInfoService interface, allowing for cleaner unit testing.

You can also control whether an exception is thrown from the service when there is a property mismatch between PlayerInfo and the OSRS API. This is particularly useful when Jagex releases a new activity and you don't want to compromise data integrity until this package is updated. By default, this is set to true.

// Enable exception throwing on property mismatch. The service will fail until PlayerInfo is updated with the new Skill/Activity.

// Using DI
public void ConfigureServices(IServiceCollection services) {
     services.AddOsrsWrapper(true);
}
// Using Constructor
var service = new PlayerInfoService(new HttpClient(), true);


// Disable exception throwing on property mismatch. The service will return a PlayerInfo object, but the Skills/Activities will be out of order/incorrect. You may compromise data integrity by disabling this, but no exceptions will be thrown.

// Using DI
public void ConfigureServices(IServiceCollection services) {
     services.AddOsrsWrapper(true);
}
// Using Constructor
var service = new PlayerInfoService(new HttpClient(), true);

A good approach would be to use this in tandem with IConfiguration, so that if required, the service can continue without code change by simply toggling a property in appsettings.json from true to false.

Once you retrieve a PlayerInfo result from the service, you can access Hiscore information from the object.

// Retrieve a specific Skill's Level.
public int SlayerLevel = Player.Slayer.Level;
// Retrieve a specific Skill's Rank
public int FletchingRank = Player.Fletching.Rank;
// Retrieve a specific Skill's Experience
public int Hitpoints = Player.Hitpoints.Experience;

Retrieve info about Player's Minigame stats.

// Retrieve a specific Minigames Rank
public int LMSRank = Player.LastManStanding.Rank;
// Retrieve a specific Minigames Score
public int MasterClueCompletions = Player.MasterClueScrolls.Score;

Retrieve all values of a Player in string format.

Console.WriteLine(Player.GetAllValuesToString());
/* outputs : 
Player Name : Assasindie
Overall : Rank : 64962, Level : 2010, Experience : 170238009,
Attack : Rank : 75590, Level : 99, Experience : 14061346,
Defence : Rank : 38037, Level : 99, Experience : 15706736,
Strength : Rank : 59169, Level : 99, Experience : 16523738,
Hitpoints : Rank : 36005, Level : 99, Experience : 28327649,
Ranged : Rank : 46751, Level : 99, Experience : 21773617,
Prayer : Rank : 89261, Level : 84, Experience : 2989692,
Magic : Rank : 49841, Level : 99, Experience : 14699752,
Cooking : Rank : 202197, Level : 89, Experience : 4847633,
Woodcutting : Rank : 97462, Level : 88, Experience : 4525861,
Fletching : Rank : 304461, Level : 80, Experience : 1987306,
Fishing : Rank : 132872, Level : 85, Experience : 3484752,
Firemaking : Rank : 168640, Level : 86, Experience : 3678548,
Crafting : Rank : 109435, Level : 82, Experience : 2564159,
Smithing : Rank : 74662, Level : 85, Experience : 3265164,
Mining : Rank : 126816, Level : 80, Experience : 2005829,
Herblore : Rank : 85437, Level : 85, Experience : 3268295,
Agility : Rank : 95737, Level : 80, Experience : 2001215,
Thieving : Rank : 98240, Level : 81, Experience : 2240683,
Slayer : Rank : 19801, Level : 99, Experience : 14833524,
Farming : Rank : 158825, Level : 82, Experience : 2437750,
Runecrafting : Rank : 71460, Level : 77, Experience : 1558992,
Hunter : Rank : 217113, Level : 71, Experience : 846896,
Construction : Rank : 129107, Level : 82, Experience : 2608872,
BountyHunterRogues : Rank : -1, Score : -1,
BountyHunter : Rank : -1, Score : -1,
LastManStanding : Rank : 14819, Score : 503,
TotalCluesScrolls : Rank : 11530, Score : 756,
BeginnerClueScrolls : Rank : -1, Score : -1,
EasyClueScrolls : Rank : 288644, Score : 7,
MediumClueScrolls : Rank : 7993, Score : 420,
HardClueScrolls : Rank : 22995, Score : 248,
EliteClueScrolls : Rank : 37188, Score : 31,
MasterClueScrolls : Rank : 7456, Score : 50,
*/

IEnumerable for Minigames

foreach(Activity activity in Player.Minigames())
{
     Console.WriteLine(activity.Rank);
     Console.WriteLine(activity.Name);
}

IEnumerable for Skills

foreach(Skill skill in Player.Skills())
{
     Console.WriteLine(skill.Level);
     Console.WriteLine(skill.Name);
}

About

A .NET Wrapper for the OSRS highscores API


Languages

Language:C# 100.0%