-
Notifications
You must be signed in to change notification settings - Fork 11
/
bulk.go
75 lines (58 loc) · 2 KB
/
bulk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package scryfall
import (
"context"
"fmt"
)
// BulkData is a Scryfall bulk data item.
type BulkData struct {
// ID is a unique ID for this bulk item.
ID string `json:"id"`
// Type is a computer-readable string for the kind of bulk item.
Type string `json:"type"`
// UpdatedAt is the time when this file was last updated.
UpdatedAt Timestamp `json:"updated_at"`
// Name is a human-readable name for this file.
Name string `json:"name"`
// URI is a link to this bulk object on Scryfall's API.
URI string `json:"uri"`
// Description is a human-readable name for this file.
Description string `json:"description"`
// CompressedSize is the compressed size of this file in integer bytes.
CompressedSize int `json:"compressed_size"`
// DownloadURI is the URL that hosts this bulk file.
DownloadURI string `json:"download_uri"`
// ContentType is the MIME type of this file.
ContentType string `json:"content_type"`
// ContentEncoding is the Content-Encoding encoding that will be used
// to transmit this file when you download it.
ContentEncoding string `json:"content_encoding"`
}
// ListBulkData returns a list of all bulk data items on Scryfall.
func (c *Client) ListBulkData(ctx context.Context) ([]BulkData, error) {
bulkDataItems := []BulkData{}
err := c.listGet(ctx, "bulk-data", &bulkDataItems)
if err != nil {
return nil, err
}
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
}