-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcatalog_artists.go
executable file
·75 lines (63 loc) · 2.22 KB
/
catalog_artists.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 applemusic
import (
"context"
"fmt"
)
// ArtistAttributes represents the attributes of the resource.
type ArtistAttributes struct {
GenreNames []string `json:"genreNames"`
EditorialNotes *EditorialNotes `json:"editorialNotes,omitempty"`
Name string `json:"name"`
URL string `json:"url"`
}
// ArtistRelationships represents a to-one or to-many relationship from one resource object to others.
type ArtistRelationships struct {
Albums Albums `json:"albums"`
Genres *Genres `json:"genres,omitempty"`
MusicVideos *MusicVideos `json:"music-videos,omitempty"`
Playlists *Playlists `json:"playlists,omitempty"`
}
// Artist represents an artist of an album.
type Artist struct {
Id string `json:"id"`
Type string `json:"type"`
Href string `json:"href"`
Attributes ArtistAttributes `json:"attributes"`
Relationships ArtistRelationships `json:"relationships"`
}
// Artists represents a list of artists.
type Artists struct {
Data []Artist `json:"data"`
Href string `json:"href,omitempty"`
Next string `json:"next,omitempty"`
}
func (s *CatalogService) getArtists(ctx context.Context, u string) (*Artists, *Response, error) {
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
artists := &Artists{}
resp, err := s.client.Do(ctx, req, artists)
if err != nil {
return nil, resp, err
}
return artists, resp, nil
}
// GetArtist fetches a artist using its identifier.
func (s *CatalogService) GetArtist(ctx context.Context, storefront, id string, opt *Options) (*Artists, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/artists/%s", storefront, id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
return s.getArtists(ctx, u)
}
// GetArtistsByIds fetches one or more artists using their identifiers.
func (s *CatalogService) GetArtistsByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Artists, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/artists", storefront)
u, err := addOptions(u, makeIdsOptions(ids, opt))
if err != nil {
return nil, nil, err
}
return s.getArtists(ctx, u)
}