From 00aefe541629a6771088d4bd45335548bbea2b37 Mon Sep 17 00:00:00 2001 From: Steven Santos Erenst Date: Sun, 15 Dec 2024 03:19:55 -0800 Subject: [PATCH] Add support for additional bulk data APIs Looks like these were added since I last looked at the documentation. Scryfall rarely lists their changes in their API changelog so its hard to keep track of when things are added... --- CHANGELOG.md | 3 +++ bulk.go | 32 ++++++++++++++++++++++++++++---- scryfall.go | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1308d1e..1dee3bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.7.0 +* Add support for APIs to get bulk data by ID or type + ## 0.6.1 * Set Accept header to application/json diff --git a/bulk.go b/bulk.go index f6667fe..692e482 100644 --- a/bulk.go +++ b/bulk.go @@ -1,6 +1,9 @@ package scryfall -import "context" +import ( + "context" + "fmt" +) // BulkData is a Scryfall bulk data item. type BulkData struct { @@ -37,9 +40,6 @@ type BulkData struct { } // ListBulkData returns a list of all bulk data items on Scryfall. -// -// Note: Card objects in bulk data do not contain prices, and will omit the -// USD, EUR, Tix, and purchase URIs properties. func (c *Client) ListBulkData(ctx context.Context) ([]BulkData, error) { bulkDataItems := []BulkData{} err := c.listGet(ctx, "bulk-data", &bulkDataItems) @@ -49,3 +49,27 @@ func (c *Client) ListBulkData(ctx context.Context) ([]BulkData, error) { return bulkDataItems, nil } + +// GetBulkDataByID gets a bulk data item by ID. +func (c *Client) GetBulkDataByID(ctx context.Context, id string) (BulkData, error) { + bulkDataURL := fmt.Sprintf("bulk-data/%s", id) + bulkData := BulkData{} + err := c.get(ctx, bulkDataURL, &bulkData) + if err != nil { + return BulkData{}, err + } + + return bulkData, nil +} + +// GetBulkDataByType gets a bulk data item by type. +func (c *Client) GetBulkDataByType(ctx context.Context, typ string) (BulkData, error) { + bulkDataURL := fmt.Sprintf("bulk-data/%s", typ) + bulkData := BulkData{} + err := c.get(ctx, bulkDataURL, &bulkData) + if err != nil { + return BulkData{}, err + } + + return bulkData, nil +} diff --git a/scryfall.go b/scryfall.go index b1de962..c6d64d6 100644 --- a/scryfall.go +++ b/scryfall.go @@ -16,7 +16,7 @@ import ( ) const ( - Version = "0.6.1" + Version = "0.7.0" defaultBaseURL = "https://api.scryfall.com" defaultUserAgent = "go-scryfall/" + Version