forked from zmb3/spotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.go
79 lines (66 loc) · 2.24 KB
/
category.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
package spotify
import (
"context"
"fmt"
)
// Category is used by Spotify to tag items in. For example, on the Spotify
// player's "Browse" tab.
type Category struct {
// A link to the Web API endpoint returning full details of the category
Endpoint string `json:"href"`
// The category icon, in various sizes
Icons []Image `json:"icons"`
// The Spotify category ID. This isn't a base-62 Spotify ID, its just
// a short string that describes and identifies the category (ie "party").
ID string `json:"id"`
// The name of the category
Name string `json:"name"`
}
// GetCategory gets a single category used to tag items in Spotify.
//
// Supported options: Country, Locale
func (c *Client) GetCategory(ctx context.Context, id string, opts ...RequestOption) (Category, error) {
cat := Category{}
spotifyURL := fmt.Sprintf("%sbrowse/categories/%s", c.baseURL, id)
if params := processOptions(opts...).urlParams.Encode(); params != "" {
spotifyURL += "?" + params
}
err := c.get(ctx, spotifyURL, &cat)
if err != nil {
return cat, err
}
return cat, err
}
// GetCategoryPlaylists gets a list of Spotify playlists tagged with a particular category.
// Supported options: Country, Limit, Offset
func (c *Client) GetCategoryPlaylists(ctx context.Context, catID string, opts ...RequestOption) (*SimplePlaylistPage, error) {
spotifyURL := fmt.Sprintf("%sbrowse/categories/%s/playlists", c.baseURL, catID)
if params := processOptions(opts...).urlParams.Encode(); params != "" {
spotifyURL += "?" + params
}
wrapper := struct {
Playlists SimplePlaylistPage `json:"playlists"`
}{}
err := c.get(ctx, spotifyURL, &wrapper)
if err != nil {
return nil, err
}
return &wrapper.Playlists, nil
}
// GetCategories gets a list of categories used to tag items in Spotify
//
// Supported options: Country, Locale, Limit, Offset
func (c *Client) GetCategories(ctx context.Context, opts ...RequestOption) (*CategoryPage, error) {
spotifyURL := c.baseURL + "browse/categories"
if query := processOptions(opts...).urlParams.Encode(); query != "" {
spotifyURL += "?" + query
}
wrapper := struct {
Categories CategoryPage `json:"categories"`
}{}
err := c.get(ctx, spotifyURL, &wrapper)
if err != nil {
return nil, err
}
return &wrapper.Categories, nil
}