This is the Magic: The Gathering SDK C# .NET implementation. It is a wrapper around the MTG API of magicthegathering.io.
MtgApiManager is available on the [NuGet Gallery]
Use the following command in the Package Manager Console.
PM> Install-Package MtgApiManager.Lib
The MTG API has a rate limit in order to maintain a reponsive experience for the user. This SDK has a rate limit manager which manages the rates for you. Based on the total requests per hour the rate limit manager attempts to spead out the calls over the hour in 10 second chuncks. For example if the number of requests is limited to 5000 per hour, the number of requests per 10 seconds is 13 (5000 / (3600 / 10)) after rounding down, therefore if you make 13 requests out to the web service in 8 seconds when you attempt to make the 14th request the SDK will wait 2 seconds before trying to call the API.
Creating a new service provider used to fetch the different services available.
IMtgServiceProvider serviceProvider = new MtgServiceProvider();
The result of all service calls resturns a generic IOperationResult containing the results of the call. It's also important to note that the active query that was added with the Where method will be cleared after a query is performed with the AllAsync method.
ICardService service = serviceProvider.GetCardService();
IOperationResult<List<ICard>> result = service.AllAsync();
if (result.IsSuccess)
{
var value = result.Value;
}
else
{
var exception = result.Exception;
}
ICardService service = serviceProvider.GetCardService();
var result = await service.FindAsync("f2eb06047a3a8e515bff62b55f29468fcde6332a");
ICardService service = serviceProvider.GetCardService();
var result = await service.FindAsync(123);
ICardService service = serviceProvider.GetCardService();
var result = await service.Where(x => x.Set, "ktk")
.Where(x => x.SubTypes, "warrior,human")
.AllAsync()
ICardService service = serviceProvider.GetCardService();
var result = await service.AllAsync()
ICardService service = serviceProvider.GetCardService();
var result = await service.Where(x => x.Page, 5)
.Where(x => x.PageSize, 250)
.AllAsync()
ICardService service = serviceProvider.GetCardService();
var result = await service.GetCardTypesAsync();
ICardService service = serviceProvider.GetCardService();
var result = await service.GetCardSuperTypesAsync();
ICardService service = serviceProvider.GetCardService();
var result = await service.GetCardSubTypesAsync();
ICardService service = serviceProvider.GetCardService();
var result = await service.GetFormatsAsync();
ISetService service = serviceProvider.GetSetService();
var result = await service.FindAsync("ktk");
ISetService service = serviceProvider.GetSetService();
var result = await service.Where(x => x.Name, "khans").AllAsync()
ISetService service = serviceProvider.GetSetService();
var result = await service.AllAsync()
ISetService service = serviceProvider.GetSetService();
var result = await service.GenerateBoosterAsync("ktk")