TheMathemagicians/sevenkeys/scryfall/set.go

66 lines
1.6 KiB
Go
Raw Normal View History

2024-04-23 16:52:48 +00:00
package scryfall
import (
"encoding/json"
"errors"
"io"
"net/http"
)
type Set struct {
Object string `json:"object"`
Id string `json:"id"` // Use UUID package?
Code string `json:"code"`
MtgoCode string `json:"mtgo_code"`
ArenaCode string `json:"arena_code"`
TcgplayerId int `json:"tcgplayer_id"`
Name string `json:"name"`
SetType string `json:"set_type"`
ReleasedAt string `json:"released_at"`
BlockCode string `json:"block_code"`
Block string `json:"block"`
ParentSetCode string `json:"parent_set_code"`
CardCount int `json:"card_count"`
PrintedSize int `json:"printed_size"`
Digital bool `json:"digital"`
FoilOnly bool `json:"foil_only"`
NonfoilOnly bool `json:"nonfoil_only"`
ScryfallUri string `json:"scryfall_uri"`
Uri string `json:"uri"`
IconSvgUri string `json:"icon_svg_uri"`
SearchUri string `json:"search_uri"`
}
type SetList struct {
Object string `json:"object"`
HasMore bool `json:"has_more"`
Data []Set `json:"data"`
}
var SETS_API string = "https://api.scryfall.com/sets"
func GetSets() (SetList, error) {
response, err := http.Get(SETS_API)
if err != nil {
return SetList{}, err
}
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
setsBytes, err := io.ReadAll(response.Body)
if err != nil {
return SetList{}, err
}
var setList SetList
err = json.Unmarshal(setsBytes, &setList)
if err != nil {
return SetList{}, err
}
return setList, nil
}
return SetList{}, errors.New("scryfall: failed to get all sets")
}