mtg

package module
v0.0.0-...-3aaea97 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2019 License: MIT Imports: 10 Imported by: 1

README

Magic: The Gathering SDK

Build Status Coverage Status Go Report Card MIT License

This is the Magic: The Gathering SDK Go implementation. It is a wrapper around the MTG API of magicthegathering.io.

Installation

Just run

go get github.com/MagicTheGathering/mtg-sdk-go

Docs

See GoDoc

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// CardName is the column for the name property.
	// For split, double-faced and flip cards, just the name of one side of the card. Basically each ‘sub-card’ has its own record.
	CardName = cardColumn("name")
	// CardLayout is the column for the layout property.
	// The card layout. Possible values: normal, split, flip, double-faced, token, plane, scheme, phenomenon, leveler, vanguard
	CardLayout = cardColumn("layout")
	// CardCMC is the column for the cmc property.
	// Converted mana cost. Always a number.
	CardCMC = cardColumn("cmc")
	// CardColors is the column for the colors property.
	// The card colors. Usually this is derived from the casting cost, but some cards are special (like the back of dual sided cards and Ghostfire).
	CardColors = cardColumn("colors")
	// CardColorIdentity is the column for the color identity property.
	// The card colors by color code. [“Red”, “Blue”] becomes [“R”, “U”]
	CardColorIdentity = cardColumn("colorIdentity")
	// CardType is the column for the type property.
	// The card type. This is the type you would see on the card if printed today. Note: The dash is a UTF8 'long dash’ as per the MTG rules
	CardType = cardColumn("type")
	// CardSupertypes is the column for the supertypes property.
	// The supertypes of the card. These appear to the far left of the card type. Example values: Basic, Legendary, Snow, World, Ongoing
	CardSupertypes = cardColumn("supertypes")
	// CardTypes is the column for the types property.
	// The types of the card. These appear to the left of the dash in a card type. Example values: Instant, Sorcery, Artifact, Creature, Enchantment, Land, Planeswalker
	CardTypes = cardColumn("types")
	// CardSubtypes is the column for the subtypes property.
	// The subtypes of the card. These appear to the right of the dash in a card type. Usually each word is its own subtype. Example values: Trap, Arcane, Equipment, Aura, Human, Rat, Squirrel, etc.
	CardSubtypes = cardColumn("subtypes")
	// CardRarity is the column for the rarity property.
	// The rarity of the card. Examples: Common, Uncommon, Rare, Mythic Rare, Special, Basic Land
	CardRarity = cardColumn("rarity")
	// CardSet is the column for the set property.
	// The set the card belongs to (set code).
	CardSet = cardColumn("set")
	// CardSetName is the column for the setName property.
	// The set the card belongs to.
	CardSetName = cardColumn("setName")
	// CardText is the column for the text property.
	// The oracle text of the card. May contain mana symbols and other symbols.
	CardText = cardColumn("text")
	// CardFlavor is the column for the flavor property.
	// The flavor text of the card.
	CardFlavor = cardColumn("flavor")
	// CardArtist is the column for the artist property.
	// The artist of the card. This may not match what is on the card as MTGJSON corrects many card misprints.
	CardArtist = cardColumn("artist")
	// CardNumber is the column for the number property.
	// The card number. This is printed at the bottom-center of the card in small text. This is a string, not an integer, because some cards have letters in their numbers.
	CardNumber = cardColumn("number")
	// CardPower is the column for the power property.
	// The power of the card. This is only present for creatures. This is a string, not an integer, because some cards have powers like: “1+*”
	CardPower = cardColumn("power")
	// CardToughness is the column for the toughness property.
	// The toughness of the card. This is only present for creatures. This is a string, not an integer, because some cards have toughness like: “1+*”
	CardToughness = cardColumn("toughness")
	// CardLoyalty is the column for the loyalty property.
	// The loyalty of the card. This is only present for planeswalkers.
	CardLoyalty = cardColumn("loyalty")
	// CardForeignName is the column for the foreign name property.
	// The name of a card in a foreign language it was printed in
	CardForeignName = cardColumn("foreignName")
	// CardLanguage is the column for the language property.
	// The language the card is printed in. Use this parameter when searching by foreignName
	CardLanguage = cardColumn("language")
	// CardGameFormat is the column for the game format property.
	// The game format, such as Commander, Standard, Legacy, etc. (when used, legality defaults to Legal unless supplied)
	CardGameFormat = cardColumn("gameFormat")
	// CardLegality is the column for the legality property.
	// The legality of the card for a given format, such as Legal, Banned or Restricted.
	CardLegality = cardColumn("legality")
)
View Source
var (
	// SetName is the name of the set
	SetName = setColumn("name")
	// SetBlock is the block the set is in
	SetBlock = setColumn("block")
)

Functions

func GetFormats

func GetFormats() ([]string, error)

GetFormats fetches a list of all known game formats

func GetSubTypes

func GetSubTypes() ([]string, error)

GetSubTypes fetches a list of all card subtypes

func GetSuperTypes

func GetSuperTypes() ([]string, error)

GetSuperTypes fetches a list of all card supertypes

func GetTypes

func GetTypes() ([]string, error)

GetTypes fetches a list of all card types

Types

type BoosterContent

type BoosterContent []string

BoosterContent represent one or more types of cards within a booster

func (*BoosterContent) String

func (bc *BoosterContent) String() string

String returns the string representation of the BoosterContent

func (*BoosterContent) UnmarshalJSON

func (bc *BoosterContent) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Card

type Card struct {
	// The card name. For split, double-faced and flip cards, just the name of one side of the card. Basically each ‘sub-card’ has its own record.
	Name string `json:"name"`
	// Only used for split, flip and dual cards. Will contain all the names on this card, front or back.
	Names []string `json:"names"`
	// The mana cost of this card. Consists of one or more mana symbols. (use cmc and colors to query)
	ManaCost string `json:"manaCost"`
	// Converted mana cost. Always a number.
	CMC float64 `json:"cmc"`
	// The card colors. Usually this is derived from the casting cost, but some cards are special (like the back of dual sided cards and Ghostfire).
	Colors []string `json:"colors"`
	// The card colors by color code. [“Red”, “Blue”] becomes [“R”, “U”]
	ColorIdentity []string `json:"colorIdentity"`
	// The card type. This is the type you would see on the card if printed today. Note: The dash is a UTF8 'long dash’ as per the MTG rules
	Type string `json:"type"`
	// The types of the card. These appear to the left of the dash in a card type. Example values: Instant, Sorcery, Artifact, Creature, Enchantment, Land, Planeswalker
	Types []string `json:"types"`
	// The supertypes of the card. These appear to the far left of the card type. Example values: Basic, Legendary, Snow, World, Ongoing
	Supertypes []string `json:"supertypes"`
	// The subtypes of the card. These appear to the right of the dash in a card type. Usually each word is its own subtype. Example values: Trap, Arcane, Equipment, Aura, Human, Rat, Squirrel, etc.
	Subtypes []string `json:"subtypes"`
	// The rarity of the card. Examples: Common, Uncommon, Rare, Mythic Rare, Special, Basic Land
	Rarity string `json:"rarity"`
	// The set the card belongs to (set code).
	Set SetCode `json:"set"`
	// The set the card belongs to.
	SetName string `json:"setName"`
	// The oracle text of the card. May contain mana symbols and other symbols.
	Text string `json:"text"`
	// The flavor text of the card.
	Flavor string `json:"flavor"`
	// The artist of the card. This may not match what is on the card as MTGJSON corrects many card misprints.
	Artist string `json:"artist"`
	// The card number. This is printed at the bottom-center of the card in small text. This is a string, not an integer, because some cards have letters in their numbers.
	Number string `json:"number"`
	// The power of the card. This is only present for creatures. This is a string, not an integer, because some cards have powers like: “1+*”
	Power string `json:"power"`
	// The toughness of the card. This is only present for creatures. This is a string, not an integer, because some cards have toughness like: “1+*”
	Toughness string `json:"toughness"`
	// The loyalty of the card. This is only present for planeswalkers.
	Loyalty string `json:"loyalty"`
	// The card layout. Possible values: normal, split, flip, double-faced, token, plane, scheme, phenomenon, leveler, vanguard
	Layout string `json:"layout"`
	// The multiverseid of the card on Wizard’s Gatherer web page. Cards from sets that do not exist on Gatherer will NOT have a multiverseid. Sets not on Gatherer are: ATH, ITP, DKM, RQS, DPA and all sets with a 4 letter code that starts with a lowercase 'p’.
	MultiverseId MultiverseId `json:"multiverseid"`
	// If a card has alternate art (for example, 4 different Forests, or the 2 Brothers Yamazaki) then each other variation’s multiverseid will be listed here, NOT including the current card’s multiverseid.
	Variations []string `json:"variations"`
	// The image url for a card. Only exists if the card has a multiverse id.
	ImageUrl string `json:"imageUrl"`
	// The watermark on the card. Note: Split cards don’t currently have this field set, despite having a watermark on each side of the split card.
	Watermark string `json:"watermark"`
	// If the border for this specific card is DIFFERENT than the border specified in the top level set JSON, then it will be specified here. (Example: Unglued has silver borders, except for the lands which are black bordered)
	Border string `json:"border"`
	// If this card was a timeshifted card in the set.
	Timeshifted bool `json:"timeshifted"`
	// Maximum hand size modifier. Only exists for Vanguard cards.
	Hand int `json:"hand"`
	// Starting life total modifier. Only exists for Vanguard cards.
	Life int `json:"life"`
	// Set to true if this card is reserved by Wizards Official Reprint Policy
	Reserved bool `json:"reserved"`
	// The date this card was released. This is only set for promo cards. The date may not be accurate to an exact day and month, thus only a partial date may be set (YYYY-MM-DD or YYYY-MM or YYYY). Some promo cards do not have a known release date.
	ReleaseDate Date `json:"releaseDate"`
	// Set to true if this card was only released as part of a core box set. These are technically part of the core sets and are tournament legal despite not being available in boosters.
	Starter bool `json:"starter"`
	// The rulings for the card.
	Rulings []*Ruling `json:"rulings"`
	// Foreign language names for the card, if this card in this set was printed in another language. An array of objects, each object having 'language’, 'name’ and 'multiverseid’ keys. Not available for all sets.
	ForeignNames []ForeignCardName `json:"foreignNames"`
	// The sets that this card was printed in, expressed as an array of set codes.
	Printings []SetCode `json:"printings"`
	// The original text on the card at the time it was printed. This field is not available for promo cards.
	OriginalText string `json:"originalText"`
	// The original type on the card at the time it was printed. This field is not available for promo cards.
	OriginalType string `json:"originalType"`
	// A unique id for this card. It is made up by doing an SHA1 hash of setCode + cardName + cardImageName
	Id CardId `json:"id"`
	// For promo cards, this is where this card was originally obtained. For box sets that are theme decks, this is which theme deck the card is from.
	Source string `json:"source"`
	// Which formats this card is legal, restricted or banned in. An array of objects, each object having 'format’ and 'legality’.
	Legalities []Legality `json:"legalities"`
}

Card stores information about one single card.

func (*Card) String

func (c *Card) String() string

String returns the string representation of the card. Containing the cardname and the id

type CardId

type CardId string

CardId which can be used to fetch the card by its id

func (CardId) Fetch

func (id CardId) Fetch() (*Card, error)

Fetch returns the card represented by the CardId

type Date

type Date time.Time

Date which can be unmarshalled from json

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. The Date is expected to be either YYYY, YYYY-MM or YYYY-MM-DD

type ForeignCardName

type ForeignCardName struct {
	// Name is the name of the card in the given language
	Name string `json:"name"`
	// Language of the ForeignCardName
	Language string `json:"language"`
	// MultiverseId of the ForeignCardName (might be 0)
	MultiverseId uint `json:"multiverseid"`
}

ForeignCardName represents the name of the card in an other language

type Id

type Id interface {
	Fetch() (*Card, error)
}

Id interface for different card id types such as MultiverseId or CardId

Example (Fetch)
fetchCardID := func(cID mtg.Id) {
	// cID could either be a CardId or a MultiverseId
	card, err := cID.Fetch()
	if err != nil {
		log.Panic(err)
	}
	log.Println(card)
}

log.Println("Fetching one Card with a given multiverseId")
fetchCardID(mtg.MultiverseId(73947))

log.Println("Fetching one Card with a given cardId")
fetchCardID(mtg.CardId("9d91ef4896ab4c1a5611d4d06971fc8026dd2f3f"))
Output:

type Legality

type Legality struct {
	// Format, such as Commander, Standard, Legacy, etc.
	Format string `json:"format"`
	// Legality for the given format such as Legal, Banned or Restricted.
	Legality string `json:"legality"`
}

Legality stores information about legality notices for a specific format.

type MultiverseId

type MultiverseId uint32

MultiverseId which can be used to fetch the card by its id

func (MultiverseId) Fetch

func (mID MultiverseId) Fetch() (*Card, error)

Fetch returns the card represented by the MutliverseId

type Query

type Query interface {
	// Where filters the given column by the given value
	Where(column cardColumn, qry string) Query
	// Sorts the query results by the given column
	OrderBy(column cardColumn) Query

	// Creates a copy of this query
	Copy() Query

	// Fetches all cards matching the current query
	All() ([]*Card, error)

	// Fetches the given page of cards.
	Page(pageNum int) (cards []*Card, totalCardCount int, err error)
	// Fetches one page of cards with a given page size
	PageS(pageNum int, pageSize int) (cards []*Card, totalCardCount int, err error)
	// Fetches some random cards
	Random(count int) ([]*Card, error)
}

Query interface can be used to query multiple cards by their properties

Example (All)
log.Println("Fetching all cards with CMC >= 16")
cards, err := mtg.NewQuery().Where(mtg.CardCMC, "gte16").All()
if err != nil {
	log.Panic(err)
}
for _, card := range cards {
	log.Println(card)
}
Output:

Example (Page)
log.Println("fetch first page (100 cards in total)")

cards, totalCards, err := mtg.NewQuery().Where(mtg.CardColors, "green|red").Page(1)
if err != nil {
	log.Panic(err)
}

log.Println("There are", totalCards, "green or red cards")
for _, card := range cards {
	log.Println(card)
}
Output:

Example (PageS)
log.Println("Fetch Page 2 with a page size of 5")

cards, totalCards, err := mtg.NewQuery().Where(mtg.CardColors, "white").PageS(2, 5)
if err != nil {
	log.Panic(err)
}

log.Println("There are", totalCards, "white cards")
for _, card := range cards {
	log.Println(card)
}
Output:

Example (Random)
// Fetch 2 random red rare cards
cards, err := mtg.NewQuery().Where(mtg.CardRarity, "rare").Where(mtg.CardColors, "red").Random(2)
if err != nil {
	log.Panic(err)
}
for _, c := range cards {
	log.Println(c)
}
Output:

func NewQuery

func NewQuery() Query

NewQuery creates a new Query to fetch cards

type Ruling

type Ruling struct {
	// Date the information was released.
	Date Date `json:"date"`
	// Text of the ruling hint.
	Text string `json:"text"`
}

Ruling contains additional rule information about the card.

type ServerError

type ServerError struct {
	// Status code given by the server
	Status string `json:"status"`
	// Message given by the server
	Message string `json:"error"`
}

ServerError is an error implementation for server messages.

func (ServerError) Error

func (se ServerError) Error() string

Error implements the error interface

type Set

type Set struct {
	// The code name of the set
	SetCode `json:"code"`

	// The name of the set
	Name string `json:"name"`
	// The block the set is in
	Block string `json:"block"`
	// The code that Gatherer uses for the set. Only present if different than ‘code’
	GathererCode string `json:"gathererCode"`
	// An old style code used by some Magic software. Only present if different than 'gathererCode’ and 'code’
	OldCode string `json:"oldCode"`
	// The code that magiccards.info uses for the set. Only present if magiccards.info has this set
	MagicCardsInfoCode string `json:"magicCardsInfoCode"`
	// When the set was released (YYYY-MM-DD). For promo sets, the date the first card was released.
	ReleaseDate string `json:"releaseDate"`
	// The type of border on the cards, either “white”, “black” or “silver”
	Border string `json:"border"`
	// Type of set. One of: “core”, “expansion”, “reprint”, “box”, “un”, “from the vault”, “premium deck”, “duel deck”, “starter”, “commander”, “planechase”, “archenemy”, “promo”, “vanguard”, “masters”
	Expansion string `json:"expansion"`
	// Present and set to true if the set was only released online
	OnlineOnly bool `json:"onlineOnly"`
	// Booster contents for this set
	Booster []BoosterContent `json:"booster"`
}

Set stores information about a mtg-set

func (*Set) String

func (s *Set) String() string

String returns the string representation for the Set

type SetCode

type SetCode string

SetCode representing one specific Set of cards

Example (Fetch)
set, err := mtg.SetCode("KTK").Fetch()
if err != nil {
	log.Panic(err)
}
log.Println(set)
Output:

Example (GenerateBooster)
cards, err := mtg.SetCode("KTK").GenerateBooster()
if err != nil {
	log.Panic(err)
}
for _, c := range cards {
	log.Println(c)
}
Output:

func (SetCode) Fetch

func (sc SetCode) Fetch() (*Set, error)

Fetch returns the Set of the given SetCode.

func (SetCode) GenerateBooster

func (sc SetCode) GenerateBooster() ([]*Card, error)

GenerateBooster returns a slice of cards which contains cards like a booster of the given set.

type SetQuery

type SetQuery interface {
	// Where filters the given column by the given value
	Where(col setColumn, qry string) SetQuery

	// Copy creates a copy of the SetQuery.
	Copy() SetQuery
	// All returns alls Sets which match the query
	All() ([]*Set, error)
	// Page returns the Sets of the given page and the total count of sets which match the query.
	// The default PageSize is 500. See also PageS
	Page(pageNum int) (sets []*Set, totalSetCount int, err error)
	// PageS returns the Sets of the given page and page size. It also returns the total count of sets
	// which match the query.
	PageS(pageNum int, pageSize int) (sets []*Set, totalSetCount int, err error)
}

SetQuery is in Interface to query sets

Example (All)
sets, err := mtg.NewSetQuery().Where(mtg.SetName, "khans").All()
if err != nil {
	log.Panic(err)
}

for _, set := range sets {
	log.Println(set)
}
Output:

func NewSetQuery

func NewSetQuery() SetQuery

NewSetQuery returns a new SetQuery

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL