Fixed SCG prices

This commit is contained in:
Artyom Belousov 2020-09-22 10:22:26 +03:00
parent 631213a412
commit 3919b21318
8 changed files with 51 additions and 199 deletions

36
cardsinfo/prices.go Normal file
View file

@ -0,0 +1,36 @@
package cardsinfo
import (
"context"
scryfall "github.com/BlueMonday/go-scryfall"
"github.com/pkg/errors"
)
func GetPrices(name string) ([]CardPrice, error) {
client, err := scryfall.NewClient()
if err != nil {
return nil, errors.Wrap(err, "Cannot fetch prices")
}
ctx := context.Background()
opts := scryfall.SearchCardsOptions{
}
resp, err := client.SearchCards(ctx, name, opts)
var prices []CardPrice
for _, card := range resp.Cards {
foilString := ""
if card.Foil {
foilString = "(Foil)"
}
edition := card.Set + foilString
cardPrice := CardPrice {
Edition: edition,
Price: card.Prices.USD,
Name: card.Name,
Link: card.PurchaseURIs.TCGPlayer,
}
prices = append(prices, cardPrice)
}
return prices, nil
}