Tutorial: Making requests to DataDragon in RiotBlossom

DataDragon is Riot Games' static content delivery network that provides assets for their game titles. In short, it provides images and information for stuffies like League of Legends champions, runes, items, and more!

You will learn how to:

  • Fetch game versions
  • Fetch a champion meta info
  • Fetch a perk meta info
  • Fetch an item meta info
Note

The code examples for this tutorial builds upon the tutorials overview!

Prerequisites

Fetch game versions

DataDragon follows API versioning to ensure changes are made without disruption. Versions usually follow the format of a League of Legends patch e.g. 12.23. We will be calling this a game version.

To fetch the list of game versions, type and save the following code below:

var versions = await client.DataDragon.ListVersionsAsync();

The latest game version is the first on the list. Since this version is usually what developers need, RiotBlossom offers a convenience method that allows you to do this:

var version = await client.DataDragon.GetLatestVersionAsync();

// The above line is just a shorter way of doing this~
var versions = await client.DataDragon.ListVersionsAsync();
var version = versions.First();

Fetch a champion meta info

Now that we have our latest game version, we can now get champion information!

Gwen has the champion ID of 887. Let us try to find out more about her:

var champion = await client.DataDragon.GetChampionByIdAsync(version, 887);
Console.WriteLine(champion);

The following should be displayed within the console:

Champion {
  "Id": "Gwen",
  "Key": "887",
  "Name": "Gwen",
  "Title": "The Hallowed Seamstress",
  "Image": {
    "Full": "Gwen.png",
    "Sprite": "champion1.png",       
    "Group": "champion",
    "X": 432,
    "Y": 0,
    "W": 48,
    "H": 48
  },
  ...
}

It would be excellent to cache the champion hash map so that it is not requested each time we need to get champion information:

var championDictionary = await client.DataDragon.GetChampionDictionaryAsync(version);
var champion = championDictionary[887];

Fetch a perk meta info

League of Legends runes are also called perks.

DataDragon offers perks under a perk styles tree e.g. "Domination", "Inspiration", "Sorcery".

Since Summon Aery has a perk ID of 8214, we know that the perk style ID is 8200:

var version = await client.DataDragon.GetLatestVersionAsync();
var perkStyle = await client.DataDragon.GetPerkStyleByIdAsync(version, 8200);
var sorceryPerks = perkStyle.Slots.SelectMany(x => x.Runes)
    .ToDictionary(k => k.Id, v => v);
    
Console.WriteLine(sorceryPerks[8214]);

The following should be shown within your console:

PerkRune {
  "Id": 8214,
  "Key": "SummonAery",
  "Icon": "perk-images/Styles/Sorcery/SummonAery/SummonAery.png",
  "Name": "Summon Aery",
  "ShortDesc": "Your attacks and abilities send Aery to a target, damaging enemies or shielding allies.",
  "LongDesc": "Damaging enemy champions with basic attacks or abilities sends Aery to them, dealing 10 - 40 based on level (+<scaleAP>0.1 AP</scaleAP>) (+<scaleAD>0.15 bonus AD</scaleAD>).<br><br>Empower or protecting allies with abilities sends Aery to them, shielding them for 30 - 75 based on level (+<scaleAP>0.22 AP</scaleAP>) (+<scaleAD>0.35 bonus AD</scaleAD>).<br><br>Aery cannot be sent out again until she returns to you."
}

It would be helpful if we can cache a single aggregate dictionary that contains all the perks:

var version = await client.DataDragon.GetLatestVersionAsync();
var perkStyleDictionary = await client.DataDragon.GetPerkStyleDictionaryAsync(version);
var perkDictionary = perkStyleDictionary
    .Select(kvp => kvp.Value)
    .SelectMany(x => x.Slots)
    .SelectMany(x => x.Runes)
    .ToDictionary(k => k.Id, v => v);

var perk = perkDictionary[8214];

Fetch an item meta info

League of Legends shop items are simply called items.

Moonstone Renewer has an item ID of 6617. Let us try to do the following:

var version = await client.DataDragon.GetLatestVersionAsync();
var item = await client.DataDragon.GetItemByIdAsync(version, 6617);
Console.WriteLine(item);

The console should display the following infosies:

Item {
  "Name": "Moonstone Renewer",
  "Rune": {
    "IsRune": false,
    "Tier": 0,
    "Type": null
  },
  "Gold": {
    "Base": 750,
    "Total": 2500,
    "Sell": 1750,
    "Purchasable": true
  },
  ...
}

As always, caching is the totes better practice~*

var itemDictionary = await client.DataDragon.GetItemDictionaryAsync(version);
var item = itemDictionary[6617];

You have just learned how to fetch game versions, champion meta info, perk meta info, and item meta info for DataDragon in RiotBlossom!

Love ya!

love-ya