MagicTheGathering / mtg-sdk-go

Magic: The Gathering SDK - Go
MIT License
25 stars 16 forks source link

Can't unmarshal #5

Open lexfrei opened 5 years ago

lexfrei commented 5 years ago

Seems like something goes wrong.

My code:

package main

import (
    "fmt"
    "os"

    mtg "github.com/MagicTheGathering/mtg-sdk-go"
)

func main() {
    cards, err := mtg.NewQuery().Where(mtg.CardLanguage, "Russian").All()
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    fmt.Println(len(cards))
}

My error:

lex@desktop MINGW64 ~/go/src/github.com/lexfrei/goscgp (master)
$ go run requester/maim.go
json: cannot unmarshal string into Go struct field Card.hand of type int
exit status 1
rahvin74 commented 5 years ago

I'm having this same issue. My assumption is that the json API has changed.

Reid-E commented 5 years ago

This error in particular is because of the addition of the hand property of Vanguard cards which modify starting hand and life totals. The SDK needs to be updated to reflect this change, among others. Paulo Luculano fixed a few of these in January, but there is still more to do.

If you're not interested in Vanguard cards, or silver-border cards (which will also definitely create problems), you could use the gameFormat API parameter, and limit your search to Vintage legal cards. Since Vintage allows all non-silver-border cards, for example https://api.magicthegathering.io/v1/cards?gameFormat=Vintage&types=Vanguard returns an empty list, and https://api.magicthegathering.io/v1/cards?gameFormat=Vintage&set=UGL returns a list of basic lands.

Also, I think the language parameter only functions if you use a non-English card name, I don't think it actually filters beyond that, though I may be wrong.