-
Notifications
You must be signed in to change notification settings - Fork 19
/
catalog_albums.go
executable file
·84 lines (72 loc) · 2.76 KB
/
catalog_albums.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
76
77
78
79
80
81
82
83
84
package applemusic
import (
"context"
"fmt"
)
// AlbumAttributes represents the attributes of the resource.
type AlbumAttributes struct {
ArtistName string `json:"artistName"`
Artwork Artwork `json:"artwork"`
ContentRating string `json:"contentRating,omitempty"`
Copyright string `json:"copyright"`
EditorialNotes *EditorialNotes `json:"editorialNotes,omitempty"`
GenreNames []string `json:"genreNames"`
IsComplete bool `json:"isComplete"`
IsSingle bool `json:"isSingle"`
Name string `json:"name"`
RecordLabel string `json:"recordLabel"`
ReleaseDate string `json:"releaseDate"`
PlayParams *PlayParameters `json:"playParams,omitempty"`
TrackCount int64 `json:"trackCount"`
URL string `json:"url"`
}
// AlbumRelationships represents a to-one or to-many relationship from one resource object to others.
type AlbumRelationships struct {
Artists Artists `json:"artists"` // Default inclusion: Identifiers only
Genres *Genres `json:"genres,omitempty"` // Default inclusion: None
Tracks Tracks `json:"tracks"` // The songs and music videos on the album. Default inclusion: Objects
}
// Album represents an album.
type Album struct {
Id string `json:"id"`
Type string `json:"type"`
Href string `json:"href"`
Attributes AlbumAttributes `json:"attributes"`
Relationships AlbumRelationships `json:"relationships"`
}
// Albums represents a list of albums.
type Albums struct {
Data []Album `json:"data"`
Href string `json:"href,omitempty"`
Next string `json:"next,omitempty"`
}
func (s *CatalogService) getAlbums(ctx context.Context, u string) (*Albums, *Response, error) {
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
albums := &Albums{}
resp, err := s.client.Do(ctx, req, albums)
if err != nil {
return nil, resp, err
}
return albums, resp, nil
}
// GetAlbum fetches an album using its identifier.
func (s *CatalogService) GetAlbum(ctx context.Context, storefront, id string, opt *Options) (*Albums, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/albums/%s", storefront, id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
return s.getAlbums(ctx, u)
}
// GetAlbumsByIds fetches one or more albums using their identifiers.
func (s *CatalogService) GetAlbumsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Albums, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/albums", storefront)
u, err := addOptions(u, makeIdsOptions(ids, opt))
if err != nil {
return nil, nil, err
}
return s.getAlbums(ctx, u)
}