Skip to content

Commit

Permalink
Merge pull request #44 from MagicTheGathering/MTG-41
Browse files Browse the repository at this point in the history
Mtg 41
  • Loading branch information
jregnier authored Nov 29, 2020
2 parents 29eebf7 + a9b12df commit 33f4352
Show file tree
Hide file tree
Showing 52 changed files with 1,180 additions and 1,258 deletions.
81 changes: 34 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ PM> Install-Package MtgApiManager.Lib
## Rate Limit
The MTG API has a [rate limit](https://docs.magicthegathering.io/#documentationrate_limits) 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.
## Usage
Creating a new service provider used to fetch the different services available.
```cs
IMtgServiceProvider serviceProvider = new MtgServiceProvider();
```
The result of all service calls resturns a generic **Exception Monad** containing the results of the call.
```cs
CardService service = new CardService();
Exceptional<List<Card>> result = service.All();
CardService service = serviceProvider.GetCardService();
Exceptional<List<ICard>> result = service.AllAsync();
if (result.IsSuccess)
{
var value = result.Value;
Expand All @@ -30,84 +34,67 @@ else
var exception = result.Exception;
}
```
Each service call also has an equivalent asynchronous call.
#### Find a card by id
```cs
CardService service = new CardService();
var result = service.Find("f2eb06047a3a8e515bff62b55f29468fcde6332a");
var asyncResult = await service.FindAsync("f2eb06047a3a8e515bff62b55f29468fcde6332a");
CardService service = serviceProvider.GetCardService();
var result = await service.FindAsync("f2eb06047a3a8e515bff62b55f29468fcde6332a");
```
#### Find a card by multiverse id
```cs
CardService service = new CardService();
var result = service.Find(123);
var asyncResult = await service.FindAsync(123);
CardService service = serviceProvider.GetCardService();
var result = await service.FindAsync(123);
```
#### Filter Cards via query parameters
```cs
CardService service = new CardService();
var result = service.Where(x => x.Set, "ktk")
.Where(x => x.SubTypes, "warrior,human")
.All()
var asyncResult = await service.Where(x => x.Set, "ktk")
.Where(x => x.SubTypes, "warrior,human")
.AllAsync()
CardService service = serviceProvider.GetCardService();
var result = await service.Where(x => x.Set, "ktk")
.Where(x => x.SubTypes, "warrior,human")
.AllAsync()
```
#### Find all cards (limited by default page size)
```cs
CardService service = new CardService();
var result = service.All()
var asyncResult = await service.AllAsync()
CardService service = serviceProvider.GetCardService();
var result = await service.AllAsync()
```
#### Get all cards with pagination
```cs
CardService service = new CardService();
var result = service.Where(x => x.Page, 5)
.Where(x => x.PageSize, 250)
.All()
var asyncResult = await service.Where(x => x.Page, 5)
.Where(x => x.PageSize, 250)
.AllAsync()
CardService service = serviceProvider.GetCardService();
var result = await service.Where(x => x.Page, 5)
.Where(x => x.PageSize, 250)
.AllAsync()
```
#### Get all card types
```cs
CardService service = new CardService();
var result = service.GetCardTypes();
var asyncResult = await service.GetCardTypesAsync();
CardService service = serviceProvider.GetCardService();
var result = await service.GetCardTypesAsync();
```
#### Get all card supertypes
```cs
CardService service = new CardService();
var result = service.GetCardSuperTypes();
var asyncResult = await service.GetCardSuperTypesAsync();
CardService service = serviceProvider.GetCardService();
var result = await service.GetCardSuperTypesAsync();
```
#### Get all card subtypes
```cs
CardService service = new CardService();
var result = service.GetCardSubTypes();
var asyncResult = await service.GetCardSubTypesAsync();
CardService service = serviceProvider.GetCardService();
var result = await service.GetCardSubTypesAsync();
```
#### Find a set by code
```cs
SetService service = new SetService();
var result = service.Find("ktk");
var asyncResult = await service.FindAsync("ktk");
SetService service = serviceProvider.GetSetService();
var result = await service.FindAsync("ktk");
```
#### Filter sets via query parameters
```cs
SetService service = new SetService();
var result = service.Where(x => x.Name, "khans").All()
var asyncResult = await service.Where(x => x.Name, "khans").AllAsync()
SetService service = serviceProvider.GetSetService();
var result = await service.Where(x => x.Name, "khans").AllAsync()
```
#### Get all Sets
```cs
SetService service = new SetService();
var result = service.All()
var asyncResult = await service.AllAsync()
SetService service = serviceProvider.GetSetService();
var result = await service.AllAsync()
```
#### Generate booster
```cs
SetService service = new SetService();
var result = service.GenerateBooster("ktk")
var asyncResult = await service.GenerateBoosterAsync("ktk")
SetService service = serviceProvider.GetSetService();
var result = await service.GenerateBoosterAsync("ktk")
```
3 changes: 0 additions & 3 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[*.cs]

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = none

# S1075: URIs should not be hardcoded
dotnet_diagnostic.S1075.severity = none
2 changes: 1 addition & 1 deletion src/MtgApiManager.Lib.Test/Model/CardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void MapCardTest()
Watermark = "watermark"
};

Card model = _modelMapper.MapCard(dto);
var model = _modelMapper.MapCard(dto);

Assert.Equal(dto.Artist, model.Artist);
Assert.Equal(dto.Border, model.Border);
Expand Down
Loading

0 comments on commit 33f4352

Please sign in to comment.