generated from oklookat/gostarter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
130 lines (112 loc) · 4.72 KB
/
user.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package deezus
import (
"context"
"net/http"
"net/url"
"github.com/oklookat/deezus/schema"
)
// https://developers.deezer.com/api/user
// https://developers.deezer.com/api/user#connections
// Get current user.
func (c *Client) UserMe(ctx context.Context) (*schema.UserMeResponse, error) {
resp := &schema.UserMeResponse{}
hResp, err := httpAny(ctx, c, nil, resp, nil, http.MethodGet, "user", "me")
if err != nil {
return nil, err
}
return resp, checkResponse(hResp, resp.ErrorInResponse)
}
// Return a list of user's favorite albums. Represented by an array of Album object.
func (c Client) UserMeAlbums(ctx context.Context, index, limit int) (*schema.Response[[]schema.SimpleAlbum], error) {
return getAnyResp[[]schema.SimpleAlbum](ctx, &c, getIndexLimit(index, limit), "user", "me", "albums")
}
// Return a list of user's favorite artists. Represented by an array of Artist object.
func (c Client) UserMeArtists(ctx context.Context, index, limit int) (*schema.Response[[]schema.SimpleArtist], error) {
return getAnyResp[[]schema.SimpleArtist](ctx, &c, getIndexLimit(index, limit), "user", "me", "artists")
}
// Return a list of user's public Playlist, represented by an array of Playlist object.
// Permission is needed to return private playlists
func (c Client) UserMePlaylists(ctx context.Context, index, limit int) (*schema.Response[[]schema.SimplePlaylist], error) {
return getAnyResp[[]schema.SimplePlaylist](ctx, &c, getIndexLimit(index, limit), "user", "me", "playlists")
}
// Return a list of user's favorite tracks. Represented by an array of Track object.
func (c Client) UserMeTracks(ctx context.Context, index, limit int) (*schema.Response[[]schema.SimpleTrack], error) {
return getAnyResp[[]schema.SimpleTrack](ctx, &c, getIndexLimit(index, limit), "user", "me", "tracks")
}
// Add album(s) to the user's library.
//
// If album(s) not found, no errors appear.
func (c *Client) AddAlbums(ctx context.Context, ids []schema.ID) (*schema.BoolResponse, error) {
body := url.Values{}
body.Set("album_ids", idsJoin(ids))
return postAny(ctx, c, body, "user", "me", "albums")
}
// Remove album from user library.
//
// If album not found, no errors appear.
func (c *Client) RemoveAlbum(ctx context.Context, id schema.ID) (*schema.BoolResponse, error) {
params := url.Values{}
params.Set("album_id", id.String())
return deleteAny(ctx, c, params, "user", "me", "albums")
}
// Add artist(s) to the user's library.
//
// If artist(s) not found, no errors appear.
func (c *Client) AddArtists(ctx context.Context, ids []schema.ID) (*schema.BoolResponse, error) {
body := url.Values{}
body.Set("artist_ids", idsJoin(ids))
return postAny(ctx, c, body, "user", "me", "artists")
}
// Remove album from user library.
//
// If album not found, no errors appear.
func (c *Client) RemoveArtist(ctx context.Context, id schema.ID) (*schema.BoolResponse, error) {
params := url.Values{}
params.Set("artist_id", id.String())
return deleteAny(ctx, c, params, "user", "me", "artists")
}
// Add track(s) to the user's library.
//
// If track(s) not found, no errors appear.
func (c *Client) AddTracks(ctx context.Context, ids []schema.ID) (*schema.BoolResponse, error) {
body := url.Values{}
body.Set("track_ids", idsJoin(ids))
return postAny(ctx, c, body, "user", "me", "tracks")
}
// Remove album from user library.
//
// If album not found, no errors appear.
func (c *Client) RemoveTrack(ctx context.Context, id schema.ID) (*schema.BoolResponse, error) {
params := url.Values{}
params.Set("track_id", id.String())
return deleteAny(ctx, c, params, "user", "me", "tracks")
}
// Create a playlist.
func (c *Client) CreatePlaylist(ctx context.Context, title string) (*schema.IDResponse, error) {
params := url.Values{}
params.Set("title", title)
data := &schema.IDResponse{}
resp, err := httpAny(ctx, c, params, data, nil, http.MethodPost, "user", "me", "playlists")
if err == nil {
err = checkResponse(resp, data.ErrorInResponse)
}
return data, err
}
// Add playlist(s) to the user's favorites.
func (c *Client) LikePlaylists(ctx context.Context, ids []schema.ID) (*schema.BoolResponse, error) {
params := url.Values{}
params.Set("playlist_ids", idsJoin(ids))
return postAnyParams(ctx, c, params, "user", "me", "playlists")
}
// Debug (schema.BoolResponse testing).
func (c *Client) likePlaylistsBad(ctx context.Context, ids []schema.ID) (*schema.BoolResponse, error) {
params := url.Values{}
//params.Set("playlist_ids", idsJoin(ids))
return postAnyParams(ctx, c, params, "user", "me", "playlists")
}
// Remove a playlist from the user's favorites.
func (c *Client) UnlikePlaylist(ctx context.Context, id schema.ID) (*schema.BoolResponse, error) {
params := url.Values{}
params.Set("playlist_id", id.String())
return deleteAny(ctx, c, params, "user", "me", "playlists")
}