README.md

mtg

Travis build
status AppVeyor build
status Codecov test
coverage

Minimalistic client to access the Magic: The Gathering API.

Installation

You can install from GitHub with:

# install.packages("devtools")
devtools::install_github("tyluRp/mtg")

Examples

Use mtg to access all available endpoints:

library(mtg)

mtg("formats")
#> ✔ Request: https://api.magicthegathering.io/v1/formats
#> ✔ Status: 200
#> ✔ Content-Type: application/json; charset=utf-8
#> $formats
#>       [,1]       
#>  [1,] "1v1"      
#>  [2,] "Brawl"    
#>  [3,] "Commander"
#>  [4,] "Duel"     
#>  [5,] "Frontier" 
#>  [6,] "Future"   
#>  [7,] "Legacy"   
#>  [8,] "Modern"   
#>  [9,] "Pauper"   
#> [10,] "Penny"    
#> [11,] "Standard" 
#> [12,] "Vintage"

str(mtg("cards"), max.level = 2)
#> ✔ Request: https://api.magicthegathering.io/v1/cards
#> ✔ Status: 200
#> ✔ Content-Type: application/json; charset=utf-8
#> List of 1
#>  $ cards:'data.frame':   100 obs. of  30 variables:
#>   ..$ name         :List of 100
#>   ..$ manaCost     :List of 100
#>   ..$ cmc          :List of 100
#>   ..$ colors       :List of 100
#>   ..$ colorIdentity:List of 100
#>   ..$ type         :List of 100
#>   ..$ supertypes   :List of 100
#>   ..$ types        :List of 100
#>   ..$ subtypes     :List of 100
#>   ..$ rarity       :List of 100
#>   ..$ set          :List of 100
#>   ..$ setName      :List of 100
#>   ..$ text         :List of 100
#>   ..$ artist       :List of 100
#>   ..$ number       :List of 100
#>   ..$ power        :List of 100
#>   ..$ toughness    :List of 100
#>   ..$ layout       :List of 100
#>   ..$ multiverseid :List of 100
#>   ..$ imageUrl     :List of 100
#>   ..$ variations   :List of 100
#>   ..$ rulings      :List of 100
#>   ..$ foreignNames :List of 100
#>   ..$ printings    :List of 100
#>   ..$ originalText :List of 100
#>   ..$ originalType :List of 100
#>   ..$ legalities   :List of 100
#>   ..$ id           :List of 100
#>   ..$ flavor       :List of 100
#>   ..$ names        :List of 100

Additionally, we can print the response as JSON thanks to the jsonlite package:

mtg("formats", json = TRUE)
#> ✔ Request: https://api.magicthegathering.io/v1/formats
#> ✔ Status: 200
#> ✔ Content-Type: application/json; charset=utf-8
#> {
#>   "formats": [
#>     ["1v1"],
#>     ["Brawl"],
#>     ["Commander"],
#>     ["Duel"],
#>     ["Frontier"],
#>     ["Future"],
#>     ["Legacy"],
#>     ["Modern"],
#>     ["Pauper"],
#>     ["Penny"],
#>     ["Standard"],
#>     ["Vintage"]
#>   ]
#> }

Response information can be suppressed with quiet = TRUE:

mtg("formats", quiet = TRUE)
#> $formats
#>       [,1]       
#>  [1,] "1v1"      
#>  [2,] "Brawl"    
#>  [3,] "Commander"
#>  [4,] "Duel"     
#>  [5,] "Frontier" 
#>  [6,] "Future"   
#>  [7,] "Legacy"   
#>  [8,] "Modern"   
#>  [9,] "Pauper"   
#> [10,] "Penny"    
#> [11,] "Standard" 
#> [12,] "Vintage"

Acknowledgements



tyluRp/mtg documentation built on May 5, 2019, 11:08 p.m.