forked from minchao/go-apple-music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalog_genres.go
executable file
·74 lines (61 loc) · 1.91 KB
/
catalog_genres.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
package applemusic
import (
"context"
"fmt"
)
// GenreAttributes represents the attributes of the resource.
type GenreAttributes struct {
Name string `json:"name"`
}
// Genre represents a genre for resources.
type Genre struct {
Id string `json:"id"`
Type string `json:"type"`
Href string `json:"href"`
Attributes GenreAttributes `json:"attributes"`
}
// Genres represents a list of genres.
type Genres struct {
Data []Genre `json:"data"`
Href string `json:"href,omitempty"`
Next string `json:"next,omitempty"`
}
func (s *CatalogService) getGenres(ctx context.Context, u string) (*Genres, *Response, error) {
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
genres := &Genres{}
resp, err := s.client.Do(ctx, req, genres)
if err != nil {
return nil, resp, err
}
return genres, resp, nil
}
// GetGenre fetches a genre using its identifier.
func (s *CatalogService) GetGenre(ctx context.Context, storefront, id string, opt *Options) (*Genres, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/genres/%s", storefront, id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
return s.getGenres(ctx, u)
}
// GetGenresByIds fetches one or more genres.
func (s *CatalogService) GetGenresByIds(ctx context.Context, storefront string, ids []string, opt *Options) (*Genres, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/genres", storefront)
u, err := addOptions(u, makeIdsOptions(ids, opt))
if err != nil {
return nil, nil, err
}
return s.getGenres(ctx, u)
}
// GetAllGenres fetches all genres for the current top charts.
func (s *CatalogService) GetAllGenres(ctx context.Context, storefront string, opt *PageOptions) (*Genres, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/genres", storefront)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
return s.getGenres(ctx, u)
}