A .Net wrapper for the Yu-Gi-Ho API at ygoprodeck.com/api-guide/.
Targets .Net Standard 2.0+.
Please check ygoprodeck.com/api-guide/ for information around rate limits, images and downloading of data.
// instantiate client
YugihoApiClient yugClient = new YugihoApiClient();
Internally, YugihoApiClient
uses an instance of the HttpClient
class. As such, instances of YugihoApiClient
are meant to be instantiated once and re-used throughout the life of an application.
There are additional YugihoApiClient
constructors that support your own httpclients as well as HttpMessageHandler
. This is especially useful when used in projects where IHttpClientFactory is used to create and configure HttpClient instances with different policies.
// your httpclient (factory, named clients, typed clients, generated clients)
var client = _httpClientFactory.CreateClient();
// instantiate client
YugihoApiClient yugClient = new YugihoApiClient(client);
// gets all cards regardless of type
var card = await yugClient.GetApiResourceAsync<Card>();
// with pagination
var card = await yugClient.GetApiResourceAsync<Card>(take: 10, skip: 2);
// Monster Cards
// There are multiple types for each monster type e.g. Effect Monster or Spirit Monster, as well as All Monsters, see below docs for all possible types
var card = await yugClient.GetApiResourceAsync<AllMonsters>();
var card = await yugClient.GetApiResourceAsync<AllMonsters>(take: 10, skip: 2);
var card = await yugClient.GetApiResourceAsync<EffectMonster>();
var card = await yugClient.GetApiResourceAsync<EffectMonster>(take: 10, skip: 2);
var card = await yugClient.GetApiResourceAsync<LinkMonster>();
var card = await yugClient.GetApiResourceAsync<LinkMonster>(take: 10, skip: 2);
// Skill Cards
var card = await yugClient.GetApiResourceAsync<SkillCard>();
var card = await yugClient.GetApiResourceAsync<SkillCard>(take: 10, skip: 2);
// Spell Cards
var card = await yugClient.GetApiResourceAsync<SpellCard>();
var card = await yugClient.GetApiResourceAsync<SpellCard>(take: 10, skip: 2);
// Token Cards
var card = await yugClient.GetApiResourceAsync<TokenCard>();
var card = await yugClient.GetApiResourceAsync<TokenCard>(take: 10, skip: 2);
// Trap Cards
var card = await yugClient.GetApiResourceAsync<TrapCard>();
var card = await yugClient.GetApiResourceAsync<TrapCard>(take: 10, skip: 2);
// Set Info
// This does require a parameter
var card = await yugClient.GetSetInfoResourceAsync<SetInfo>();
// Sets
//Set Info
var card = await yugClient.GetArrayResourceAsync<Sets>();
Most card types (Monster, Skill, Spell, Token, Trap) have some helpful filter extensions that cover off a lot of the usual filter needs. These can be stacked also. There are some very specific ones i.e. attack filters, and a generic catch all filter AddFilter
which allows you to pass in the nameof a model value
CardFilterBuilder.CreateCardFilter()
e.g
var filter = CardFilterBuilder.CreateCardFilter().AddName("3-Hump Lacooda");
Or
var filter = CardFilterBuilder.CreateCardFilter().AddFilter("3-Hump Lacooda", nameof(Monster.Name));
// Stacked filters
var filter = CardFilterBuilder.CreateCardFilter()
.AddName("3-Hump Lacooda")
.AddName("4-Starred Ladybug of Doom");
Please see offical documentation for more advance filters until these are added in as extension.
For example, if you don't want to use any extension methods you can create your own filter from scratch. Be aware that the key needs to match the json fields in the api return. Also for multiple matches (so OR filter) this is done by seperating with a comma, no spaces as the example of "name" shows below.
var filter = new Dictionary<string, string>
{
{"name", "3-Hump Lacooda,4-Starred Ladybug of Doom"},
{"race", "Beast"}
};
Once you have built up the filter you can pass it into your call method. Pagination is still supported
var filter = CardFilterBuilder.CreateCardFilter().AddName("3-Hump Lacooda");
var card = await yugClient.GetApiResourceAsync<AllMonsters>(filter);
// Pagination
var cards = await yugClient.GetApiResourceAsync<AllMonsters>(10, 2, filter);
AddLanguage()
AddId()
AddCardSet()
AddBanList()
AddLinkMarker()
AddLinkValue()
AddScaleValue()
AddAttack (accepts <, <=, >, >=)
AddDefence (accepts <, <=, >, >=)
AddLevel (accepts <, <=, >, >=)
As these lists as small and of type List these will return all.
var types = await yugClient.GetArrayResourceAsync<Archetypes>();
var sets = await yugClient.GetArrayResourceAsync<Sets>();
Set Info requires a parameter passed through
var dicObj = new Dictionary<string, string> {{"setcode", "SDY-046"}};
var setinfo = await yugClient.GetSetInfoResourceAsync<SetInfo>(dicObj);
Every resource response is automatically cached in memory, making all subsequent requests for the same resource (url matching) pull cached data. Example:
// this will fetch the data from the API
var filter = CardFilterBuilder.CreateCardFilter().AddName("3-Hump Lacooda");
var card = await yugClient.GetApiResourceAsync<AllMonsters>(filter);
// another call to the same resource will fetch from the cache
var filter = CardFilterBuilder.CreateCardFilter().AddName("3-Hump Lacooda");
var card = await yugClient.GetApiResourceAsync<AllMonsters>(filter);
This can be confirmed by:
var fromCache = card.FromCache;
To clear the cache of data:
// clear all caches for both resources and pages
yugClient.ClearCache();
Additional overloads are provided to allow for clearing the individual caches for resources, as well as by type of cache.
Card
TrapCard
TokenCard
SpellCard
Sets
SetInfo
Archetypes
AllMonsters
-----------
NormalMonster
NormalTunerMonster
EffectMonster
TunerMonster
FlipMonster
FlipEffectMonster
FlipTunerEffectMonster
SpiritMonster
UnionEffectMonster
GeminiMonster
PendulumEffectMonster
PendulumNormalMonster
PendulumTunerEffectMonster
RitualMonster
RitualEffectMonster
ToonMonster
FusionMonster
SynchroMonster
SynchroTunerMonster
SynchroPendulumEffectMonster
XYZMonster
XYZPendulumEffectMonster
LinkMonster
PendulumFlipEffectMonster
PendulumEffectFusionMonster
string Id
string Name
string Type
string Desc
string Race
string Archetype
List<SetInfo> CardSets
List<CardImage> CardImages
List<CardPrice> CardPrices
int? Atk
int? Def
int? Level
string Attribute
Banlist BanlistInfo
int? Scale
int? Linkval
List<string> Linkmarkers
string Id
string Name
string Type
string Desc
int Atk
string Race
string Attribute
string Archetype
int Linkval
List<string> Linkmarkers
List<SetInfo> CardSets
List<CardImage> CardImages
List<CardPrice> CardPrices
Banlist BanlistInfo
string Id
string Name
string Type
string Desc
string Race
List<SetInfo> CardSets
List<CardImage> CardImages
List<CardPrice> CardPrices
string Archetype
Banlist BanlistInfo
string Id
string Name
string Type
string Desc
int Atk
int Def
int Level
string Race
string Attribute
string Archetype
List<SetInfo> CardSets
List<CardImage> CardImages
List<CardPrice> CardPrices
string Id
string Name
string Type
string Desc
string Race
string Archetype
List<SetInfo> CardSets
List<CardImage> CardImages
List<CardPrice> CardPrices
Banlist BanlistInfo
string Id
string Name
string Type
string Desc
string Race
List<CardImage> CardImages
List<CardPrice> CardPrices
List<SetInfo> CardSets
string Archetype
string Id
string SetName
string SetCode
long NumOfCards
DateTime? TcgDate
string Id
string SetName
string SetCode
string SetRarity
string SetRarityCode
string SetPrice
long Id
Uri ImageUrl
Uri ImageUrlSmall
string CardmarketPrice
string TcgplayerPrice
string EbayPrice
string AmazonPrice
string CoolstuffincPrice
string BanOcg
string BanTcg
string BanGoat
-
- Open an issue
- Describe what the SDK is missing and what changes you'd like to see implemented
- Ask clarifying questions
- Fork it (click the Fork button at the top of the page)
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request to
develop
- Caching and some api handling used/inspired from PokeApiNet under the MIT license
- Inspired based off my other SDK PokemonTCG SDK under MIT license