Documentation
¶
Overview ¶
Package scryfall is the library behind the scryfall command line: the HTTP client, request shaping, and the typed data models for the Scryfall MTG card API.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite (Scryfall asks for 50-100ms between requests), and retries the transient failures (429 and 5xx) that any public API throws under load.
Index ¶
- Constants
- type Card
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetCardByName(ctx context.Context, name string) (*Card, error)
- func (c *Client) GetRandomCard(ctx context.Context) (*Card, error)
- func (c *Client) ListSets(ctx context.Context, limit int) ([]Set, error)
- func (c *Client) SearchCards(ctx context.Context, query string, limit int) ([]Card, error)
- type Domain
- type Prices
- type Set
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "scryfall-cli/dev (+https://github.com/tamnd/scryfall-cli)"
DefaultUserAgent identifies the client to Scryfall. Scryfall's docs ask for a real, honest User-Agent so they can contact you if something goes wrong.
const Host = "api.scryfall.com"
Host is the API host this client talks to, and the host the URI driver in domain.go claims.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Card ¶
type Card struct {
ID string `kit:"id" json:"id"`
Name string `json:"name"`
ManaCost string `json:"mana_cost"`
CMC float64 `json:"cmc"`
TypeLine string `json:"type_line"`
OracleText string `json:"oracle_text"`
Power string `json:"power"`
Toughness string `json:"toughness"`
Colors []string `json:"colors"`
SetCode string `json:"set"`
SetName string `json:"set_name"`
Rarity string `json:"rarity"`
Prices Prices `json:"prices"`
ScryfallURL string `json:"scryfall_uri"`
ReleasedAt string `json:"released_at"`
}
Card is a single Magic: The Gathering card as returned by the Scryfall API.
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the Scryfall API over HTTPS.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 100ms minimum gap between requests (Scryfall allows ~10 req/sec), and five retries on transient errors.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.
func (*Client) GetCardByName ¶
GetCardByName fetches a single card by fuzzy name match via /cards/named.
func (*Client) GetRandomCard ¶
GetRandomCard fetches a random card from /cards/random.
type Domain ¶
type Domain struct{}
Domain is the Scryfall driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (type, id), so `ant resolve` and `ant url` touch no network. A 36-character UUID (with dashes) is a "card-id"; anything that looks like a scryfall.com URL is a "card-id" too; otherwise it is a "card" (name lookup).
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.