Celerium.TCGdex
Celerium.TCGdex

CI GitHub_Pages

PoshGallery_Version PoshGallery_Platforms PoshGallery_Downloads codeSize

Contributors Forks Stargazers Issues

GitHub_License


Logo

PowerShell Gallery · Report Bug · Request Feature


Buy me a coffee

Whether you use this project, have learned something from it, or just like it, please consider supporting it by buying me a coffee, so I can dedicate more time on open-source projects like this :)

Buy Me A Coffee

About The Project

The Celerium.TCGdex PowerShell wrapper offers a way to read data from the public TCGdex REST API (v2), a multilingual Pokemon Trading Card Game (TCG) database of cards, sets, series, & card attributes. This module serves to abstract away the details of interacting with TCGdex’s API endpoints in such a way that is consistent with PowerShell nomenclature. This gives system administrators and PowerShell developers a convenient and familiar way of using the TCGdex API to create scripts, reports, and integrations.

  • :book: Celerium.TCGdex project documentation can be found on Github Pages
  • :book: TCGdex’s REST API documentation can be found on tcgdex.dev & the OpenAPI spec is published in the tcgdex/cards-database repository

A function is generated for every endpoint in the TCGdex OpenAPI spec (TCGdex-2.json) and every endpoint is tracked in the endpoints.csv file.

The TCGdex API is read-only & does not use an API key. Every function is a Get-TCGdex* function that sends a GET request.

In order to maintain PowerShell best practices, only approved verbs are used and PowerShell’s verb-noun nomenclature is respected. Each noun is prefixed with TCGdex in an attempt to prevent naming problems.

For example, one might access the /cards/{cardId} endpoint by running the following PowerShell command:

Get-TCGdexCard -CardId 'swsh3-136'
  • Every function covers a list endpoint & its single item endpoint with parameter sets. Get-TCGdexSet lists the sets & Get-TCGdexSet -SetId 'swsh3' gets one set. Get-TCGdexCard also gets a card by its set & local ID (-SetId 'swsh3' -LocalId '136')
  • Every function has a -Language parameter, see Languages
  • Paged endpoints have -Page & -ItemsPerPage parameters and an -AllResults switch that requests every page for you (100 items per page unless -ItemsPerPage is used)
  • Endpoints that support filtering have a -Filters hashtable parameter, every key is sent as a TCGdex filter such as @{ name = 'eq:Pikachu'; hp = 'gte:100' }. Results can be sorted with -SortField & -SortOrder
  • Responses are cached in memory for one hour, use -NoCache to send a new request or Clear-TCGdexCache to clear the cache

(back to top)

Install

This module can be installed directly from the PowerShell Gallery with the following command:

Install-Module -Name Celerium.TCGdex
  • :information_source: This module supports Windows PowerShell 5.1 and PowerShell 7+ on Windows, Linux, & macOS. Every change is tested on all of them by the CI workflow.
  • :information_source: If PowerShellGet is unavailable, you can manually download the main branch and place the latest version of Celerium.TCGdex from the build folder into the (default) C:\Program Files\WindowsPowerShell\Modules folder.

Celerium.TCGdex project documentation can be found on Github Pages

  • A full list of functions can be retrieved by running Get-Command -Module Celerium.TCGdex.
  • Help info and a list of parameters can be found by running Get-Help <command name>, such as:
Get-Help Get-TCGdexCard
Get-Help Get-TCGdexCard -Full

(back to top)

Initial Setup

The TCGdex API is public, no account or API key is needed. The module is ready to use right after it is imported:

Import-Module -Name Celerium.TCGdex
Get-TCGdexCard -CardId 'swsh3-136'
  1. [optional] Run Add-TCGdexBaseURI
    • By default, TCGdex’s https://api.tcgdex.net/v2 uri is used
    • If you have your own API gateway or proxy, you can use Add-TCGdexBaseURI -BaseURI https://myapi.gateway.example.org/v2, only https is supported
  2. [optional] Run Add-TCGdexLanguage -Language fr
    • By default the data is returned in English (en), see Languages
  3. [optional] Run Export-TCGdexModuleSettings
    • This will create a config file at %UserProfile%\Celerium.TCGdex that holds the base uri & language.
    • Next time you run Import-Module -Name Celerium.TCGdex, this configuration file will automatically be loaded.

Environment variables (recommended for CI\CD) are loaded when the module is imported and take precedence over the configuration file:

$env:TCGDEX_BASE_URI = 'https://api.tcgdex.net/v2'   # Optional
$env:TCGDEX_LANGUAGE = 'fr'                          # Optional
Import-Module -Name Celerium.TCGdex

Languages

TCGdex returns its data in the language that is part of the request uri (https://api.tcgdex.net/v2/<language>/cards). The module adds the language to every request:

# Languages supported by TCGdex
Get-TCGdexAvailableLanguages

# Language of every request (default: en)
Add-TCGdexLanguage -Language 'ja'
Get-TCGdexLanguage

# Language of one request
Get-TCGdexCard -CardId 'swsh3-136' -Language 'fr'

(back to top)

Usage

Calling an API endpoint is as simple as running its Get-TCGdex* function.

# Get the first page of cards & every card
Get-TCGdexCard -ItemsPerPage 25
Get-TCGdexCard -AllResults

# Get a card by its global ID or by its set & local ID
Get-TCGdexCard -CardId 'swsh3-136'
Get-TCGdexCard -SetId 'swsh3' -LocalId '136'

# Filter & sort the cards
Get-TCGdexCard -Filters @{ name = 'eq:Pikachu'; hp = 'gte:60' } -SortField 'name' -SortOrder 'ASC'

# An array value matches any of the values (name=eq:Furret|Pikachu)
Get-TCGdexCard -Filters @{ name = 'eq:Furret', 'Pikachu' }

# Sets & series
Get-TCGdexSet
Get-TCGdexSet -SetId 'swsh3'
Get-TCGdexSeries -SeriesId 'swsh'

# Card attributes & the cards that have an attribute
Get-TCGdexRarity
Get-TCGdexRarity -Rarity 'Rare' -Filters @{ name = 'Pikachu' }
Get-TCGdexIllustrator -Illustrator 'Ken Sugimori'
  • The full list of endpoints & their functions is tracked in the endpoints.csv file and on Github Pages.
  • Example scripts can be found in the examples folder of this repository.

Supported functions

The module has 16 public functions in 4 categories that cover all 33 endpoints in the spec. Every function is a read-only Get- function.

Category EndpointUri Method Function
Cards /cards GET Get-TCGdexCard
Cards /cards/{cardId} GET Get-TCGdexCard (ById)
Cards /sets/{set}/{cardLocalId} GET Get-TCGdexCard (BySet)
Sets /sets GET Get-TCGdexSet
Sets /sets/{set} GET Get-TCGdexSet (ById)
Series /series GET Get-TCGdexSeries
Series /series/{serie} GET Get-TCGdexSeries (ById)
Filters /categories & /categories/{category} GET Get-TCGdexCategory
Filters /dex-ids & /dex-ids/{dexId} GET Get-TCGdexDexId
Filters /energy-types & /energy-types/{energy-type} GET Get-TCGdexEnergyType
Filters /hp & /hp/{hp} GET Get-TCGdexHP
Filters /illustrators & /illustrators/{illustrator} GET Get-TCGdexIllustrator
Filters /rarities & /rarities/{rarity} GET Get-TCGdexRarity
Filters /regulation-marks & /regulation-marks/{regulation-mark} GET Get-TCGdexRegulationMark
Filters /retreats & /retreats/{retreat} GET Get-TCGdexRetreat
Filters /stages & /stages/{stage} GET Get-TCGdexStage
Filters /suffixes & /suffixes/{suffix} GET Get-TCGdexSuffix
Filters /trainer-types & /trainer-types/{trainer-type} GET Get-TCGdexTrainerType
Filters /types & /types/{type} GET Get-TCGdexType
Filters /variants & /variants/{variant} GET Get-TCGdexVariant

The single item endpoints of the Filters category (such as /rarities/{rarity}) return the name of the attribute & the cards that have it.

Upgrading from 1.x

Version 2.0.0 generates every function from the OpenAPI spec, which changes some behavior:

  • The base uri no longer contains the language. Get-TCGdexBaseURI returns https://api.tcgdex.net/v2, use Get-TCGdexBaseURI -AndLanguage for https://api.tcgdex.net/v2/en. A 1.x style base uri such as https://api.tcgdex.net/v2/fr still works, the language is moved to the module language
  • The language is set with Add-TCGdexLanguage (Set-TCGdexLanguage is an alias, it was exported but missing in 1.x) or the new -Language parameter of every function
  • The default base uri & language are now set when the module is imported, 1.x needed Add-TCGdexBaseURI before the first request
  • The ID parameters use the names of the API, such as -CardId, -SetId, -SeriesId, -Rarity, or -EnergyType. -Id still works as an alias, Get-TCGdexCard -SetId -LocalId is unchanged
  • An ID can no longer be piped as a string ('swsh3-136' | Get-TCGdexCard), pipe an object with the property instead ([PSCustomObject]@{ CardId = 'swsh3-136' } | Get-TCGdexCard)
  • -AllPages is now -AllResults (-AllPages still works as an alias)
  • -Filters, -SortField, -SortOrder, -Page, & -ItemsPerPage are only available on the endpoints that support them in the spec. The list endpoints of the Filters category (such as Get-TCGdexType) do not have -Filters, their single item endpoints do
  • -Page & -ItemsPerPage are [int64] values
  • Get-TCGdexResource -Resource <path> -Id <id> was removed. Get-TCGdexResource is an alias of Invoke-TCGdexRequest, such as Get-TCGdexResource -Resource 'sets/swsh3'
  • Invoke-TCGdexRequest now takes the API names of the query parameters in -UriFilter (-Filters is an alias), such as @{ name = 'eq:Pikachu'; 'pagination:page' = 2 }. The -SortField, -SortOrder, -Page, & -ItemsPerPage parameters were removed from it
  • The response cache variable is now $TCGdexModuleResponseCache (was $TCGdex_ResponseCache)
  • The module settings parameters are now -TCGdexConfigPath & -TCGdexConfigFile (the 1.x -ConfigPath & -ConfigFile names still work as aliases). The configuration file stores the language instead of the user agent
  • The OpenAPI spec moved from Celerium.TCGdex/TCGdex.yaml to docs/TCGdex-2.json. build/Test-TCGdexOpenApiSpec.ps1 & build/Update-TCGdexOpenApiSpec.ps1 were replaced by build/Compare-TCGdexSpec.ps1 & build/Get-TCGdexSpec.ps1

Development

The module is built from the files in this repository with the scripts in the build folder. The same steps are run by the GitHub Actions workflows in .github/workflows.

Script Description
Install-Prerequisites.ps1 Installs the latest ModuleBuilder, Pester, Microsoft.PowerShell.PlatyPS, PSScriptAnalyzer, & powershell-yaml
New-PublicFunctions.ps1 (PowerShell 7+) Regenerates every public function, the manifest entries, & docs/endpoints.csv from the spec
Get-TCGdexSpec.ps1 (PowerShell 7+) Downloads the online spec (YAML) & saves it as docs/TCGdex-<version>.json
Compare-TCGdexSpec.ps1 Compares the newest local spec in docs with the online spec & optionally updates it
Invoke-ModuleBuild.ps1 Builds the module & the spec into build/Celerium.TCGdex/<version>
Invoke-PesterTests.ps1 Runs the Pester tests against the source or built module
Invoke-HelpContent.ps1 Regenerates the GitHub pages documentation in docs with Microsoft.PowerShell.PlatyPS
Publish-CeleriumModule.ps1 Publishes the built module to the PowerShell Gallery

The scripts never delete files. Public functions that are no longer generated are moved to build/Archive/<date>.

./build/Install-Prerequisites.ps1
./build/Invoke-ModuleBuild.ps1 -Version 2.0.0
./build/Invoke-PesterTests.ps1 -Version 2.0.0 -BuildTarget built

To support a newer version of the API, run ./build/Compare-TCGdexSpec.ps1 to see what changed in the online spec compared with the newest spec in docs. Run ./build/Get-TCGdexSpec.ps1 to download the online spec as docs/TCGdex-<version>.json (a different file with the same name is first copied to build/Archive), then run ./build/New-PublicFunctions.ps1. The function & parameter names are defined in the $FunctionNameMap & $ParameterNameMap tables of New-PublicFunctions.ps1.

Live tests make a small number of real, read-only GET requests to the public API. They are excluded unless the TCGDEX_LIVE environment variable is set to 1 (or TCGDEX_BASE_URI is set) and the Live tag is included:

$env:TCGDEX_LIVE = '1'
./build/Invoke-PesterTests.ps1 -Version 2.0.0 -IncludeTag Live -ExcludeTag Online

(back to top)


Contributing

Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag “enhancement”. Don’t forget to give the project a star! Thanks again!

See the CONTRIBUTING guide for more information about contributing.

(back to top)

License

Distributed under the MIT license. See LICENSE for more information.

GitHub_License

(back to top)


Table of contents