Skip to content

Commit

Permalink
Merged from devlop
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymarvels committed Mar 3, 2023
2 parents 6e1a383 + 9a975ae commit c5d82a6
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 7 deletions.
18 changes: 18 additions & 0 deletions PokemonTcgSdk.Standard.Tests/FilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Features.FilterBuilder.Pokemon;
using Features.FilterBuilder.Set;
using Infrastructure.HttpClients.CommonModels;
using NUnit.Framework;

public class FilterTests
Expand Down Expand Up @@ -133,6 +134,23 @@ public void PokemonFilter_MultipleFilters()
.AddAttackCostRange("2", "4", false)
.AddEvolvesFrom("Pikachu");

// assert
Assert.That(filterBuilder, Is.EqualTo(dicObj));
}

[Test]
public void PokemonFilter_HasMultipleAncientTraits()
{
// assemble
var dicObj = new Dictionary<string, string>
{
{"ancientTrait.name", Global.AncientTrait.Traits}
};

// act
var filterBuilder = PokemonFilterBuilder.CreatePokemonFilter().HasAncientTrait().HasAncientTrait().HasAncientTrait();


// assert
Assert.That(filterBuilder, Is.EqualTo(dicObj));
}
Expand Down
20 changes: 20 additions & 0 deletions PokemonTcgSdk.Standard.Tests/PokemonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,26 @@ public async Task GetPokemon_ApiResourcePageAsync_AncientTrait()
Assert.That(page.PageSize, Is.EqualTo("10").NoClip);
}

[Test]
public async Task GetPokemon_ApiResourcePageAsync_HasAncientTrait()
{
// assemble
var httpclient = new HttpClient();
var pokeClient = new PokemonApiClient(httpclient);

var filter = PokemonFilterBuilder.CreatePokemonFilter().HasAncientTrait();


// act
var page = await pokeClient.GetApiResourceAsync<PokemonCard>(10, 1, filter);

// assert
Assert.That(page.Results.Select(x => x.AncientTrait), Is.Not.Null);

Assert.That(page.Page, Is.EqualTo("1").NoClip);
Assert.That(page.PageSize, Is.EqualTo("10").NoClip);
}

[Test]
public async Task GetPokemon_ApiResourcePageAsync_TcgPrices1stEdition()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace PokemonTcgSdk.Standard.Features.FilterBuilder.Pokemon;

using System.Linq;
using Infrastructure.HttpClients.Cards;
using Infrastructure.HttpClients.CommonModels;

public static class PokemonFilter
{
Expand Down Expand Up @@ -139,6 +141,22 @@ public static PokemonFilterCollection<string, string> AddRarity(this PokemonFilt
return AddOrUpdate(dictionary, nameof(PokemonCard.Rarity).ToLower(), value);
}

/// <summary>
/// Extension method. Will add query to make sure returned card has an Ancient Trait.
/// </summary>
/// <param name="dictionary"></param>
public static PokemonFilterCollection<string, string> HasAncientTrait(this PokemonFilterCollection<string, string> dictionary)
{
if (dictionary.Any(x => x.Key == "ancientTrait.name"))
{
return dictionary;
}

var value = $"{Global.AncientTrait.Traits}";

return AddOrUpdate(dictionary, "ancientTrait.name", value);
}


private static PokemonFilterCollection<string, string> AddOrUpdate(PokemonFilterCollection<string, string> dictionary, string key, string value)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace PokemonTcgSdk.Standard.Infrastructure.HttpClients.CommonModels;

using System.Collections.Generic;

public static class Global
{
public static class AncientTrait
{
public static string Recovery = "α Recovery";
public static string Growth = "α Growth";
public static string Barrage = "Ω Barrage";
public static string Barrier = "Ω Barrier";
public static string Plus = "Δ Plus";
public static string Evolution = "Δ Evolution";
public static string Wild = "Δ Wild";
public static string Stop = "θ Stop";
public static string Double = "θ Double";
public static string Max = "θ Max";
public static string Traits = $"{Recovery},{Growth},{Barrage},{Barrier},{Plus},{Evolution},{Wild},{Stop},{Double},{Max}";
}
}
2 changes: 1 addition & 1 deletion PokemonTcgSdk.Standard/PokemonTcgSdk.Standard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Authors>[email protected]</Authors>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Copyright>MIT</Copyright>
<Version>2.2.0</Version>
<Version>2.4.0</Version>
<PackageProjectUrl>https://github.com/PokemonTCG/pokemon-tcg-sdk-csharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/PokemonTCG/pokemon-tcg-sdk-csharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PokemonApiClient pokeClient = new PokemonApiClient(client);
// gets all cards regardless of type
var card = await pokeClient.GetApiResourceAsync<Card>();

// with pagination
// with pagination. take on the api is limited to a max of 250
var card = await pokeClient.GetApiResourceAsync<Card>(take: 10, skip: 2);

// Pokemon Cards
Expand Down Expand Up @@ -73,6 +73,44 @@ var filter = PokemonFilterBuilder.CreatePokemonFilter()
.AddName("Pikachu")
.AddSetName("Base");
```
Most of the filter extensions are prefixed with Add
```c#
// Pokemon
AddId()
AddName()
AddSubTypes()
AddHpRange()
AddTypes()
AddEvolvesFrom()
AddEvolvesTo()
AddAttackCostRange()
AddSetName()
AddSetSeries()
AddRarity()

// Sets
AddId()
AddName()
AddSeries()
AddPtcgoCode()

// Trainer
AddId()
AddName()
AddSetName()
AddSetSeries()

// Energy
AddId()
AddName()
AddSubTypes()
AddSetName()
AddSetSeries()
```
There is also a custom extension to bring only Pokemon cards that have an ancient trait
```c#
var filter = PokemonFilterBuilder.CreatePokemonFilter().HasAncientTrait();
```
If the filter extensions don't cover off everything you can build up your own
```c#
var filter = PokemonFilterBuilder.CreatePokemonFilter()
Expand Down Expand Up @@ -110,7 +148,7 @@ var cards = await pokeClient.GetApiResourceAsync<PokemonCard>(filter);
var cards = await pokeClient.GetApiResourceAsync<PokemonCard>(10, 2, filter);
```
## String Method Definitions
As these lists as small and of type List<string> these will return all.
As these lists are small and of type ```List<string>``` these will return all.
##### SubType
```c#
var types = await pokeClient.GetStringResourceAsync<SubTypes>();
Expand Down Expand Up @@ -147,7 +185,7 @@ var fromCache = darkrai.FromCache;

To clear the cache of data:
```c#
// clear all caches for both resources and pages
// clear all caches for all resources
pokeClient.ClearCache();
```
Additional overloads are provided to allow for clearing the individual caches for resources, as well as by type of cache.
Expand Down Expand Up @@ -306,6 +344,8 @@ Prices ReverseHolofoil
Prices Normal
Prices The1StEditionHolofoil
Prices UnlimitedHolofoil
Prices The1StEdition
Prices Unlimited
```
###### Prices
```c#
Expand Down Expand Up @@ -361,6 +401,3 @@ Images Images
* 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```

#### Mentions
- Caching and some api handling used/inspired from [PokeApiNet](https://github.com/mtrdp642/PokeApiNet) under the MIT license

0 comments on commit c5d82a6

Please sign in to comment.