-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabels.go
More file actions
78 lines (65 loc) · 2.02 KB
/
labels.go
File metadata and controls
78 lines (65 loc) · 2.02 KB
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
76
77
78
package discogs
import (
"context"
"fmt"
"net/http"
)
type Label struct {
ID int `json:"id"`
Name string `json:"name"`
ResourceURL string `json:"resource_url"`
URI string `json:"uri"`
ReleasesURL string `json:"releases_url"`
Images []*Image `json:"images"`
ContactInfo string `json:"contact_info"`
Profile string `json:"profile"`
DataQuality string `json:"data_quality"`
URLs []string `json:"urls"`
SubLabels []*SubLabel `json:"sublabels"`
}
type SubLabel struct {
ID int `json:"id"`
Name string `json:"name"`
ResourceURL string `json:"resource_url"`
}
type LabelReleaseList struct {
Pagination *Pagination `json:"pagination"`
Releases []*LabelRelease `json:"releases"`
}
type LabelRelease struct {
Artist string `json:"artist"`
CatNo string `json:"catno"`
Format string `json:"format"`
ID int `json:"id"`
ResourceURL string `json:"resource_url"`
Status string `json:"status"`
Thumb string `json:"thumb"`
Title string `json:"title"`
Year int `json:"year"`
}
// GetLabel is a function for getting a single record label
func (c *Client) GetLabel(ctx context.Context, ID int) (*Label, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/labels/%d", c.baseURL, ID), nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
res := Label{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}
// GetLabelReleases is a function for getting the releases of a single record label
func (c *Client) GetLabelReleases(ctx context.Context, labelID, page, per int) (*LabelReleaseList, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/labels/%d/releases?page=%d&per_page=%d", c.baseURL, labelID, page, per), nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
res := LabelReleaseList{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}