-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuser.go
185 lines (167 loc) · 5.75 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package gopiano
import (
"bytes"
"encoding/json"
"github.com/cellofellow/gopiano/requests"
"github.com/cellofellow/gopiano/responses"
)
// Client.UserCanSubscribe returns whehter a user is subscribed or can subscribe
// to the premium Pandora One service.
// Calls API method "user.canSubscribe"
func (c *Client) UserCanSubscribe() (*responses.UserCanSubscribe, error) {
requestData := requests.UserCanSubscribe{
UserAuthToken: c.userAuthToken,
SyncTime: c.GetSyncTime(),
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return nil, err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp responses.UserCanSubscribe
err = c.BlowfishCall("http://", "user.canSubscribe", requestDataReader, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// Client.UserCreateUser creates a new Pandora user.
// Argument username must be in the form of an email address. gender must be either "male" or "female".
// countryCode must be "US".
// Calls API method "user.createUser"
func (c *Client) UserCreateUser(username, password, gender, countryCode string, zipCode, birthYear int, emailOptin bool) (*responses.UserCreateUser, error) {
requestData := requests.UserCreateUser{
PartnerAuthToken: c.partnerAuthToken,
AccountType: "registered",
RegisteredType: "user",
Username: username,
Password: password,
Gender: gender,
ZipCode: zipCode,
CountryCode: countryCode,
BirthYear: birthYear,
EmailOptin: emailOptin,
SyncTime: c.GetSyncTime(),
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return nil, err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp responses.UserCreateUser
err = c.BlowfishCall("https://", "user.createUser", requestDataReader, &resp)
if err != nil {
return nil, err
}
// Set user data onto client for later use.
c.userAuthToken = resp.Result.UserAuthToken
c.userID = resp.Result.UserID
return &resp, nil
}
// Client.UserEmailPassword resends registration email, maybe?
// Calls API method "user.emaillPassword"
func (c *Client) UserEmailPassword(username string) error {
requestData := requests.UserEmailPassword{
Username: username,
PartnerAuthToken: c.partnerAuthToken,
SyncTime: c.GetSyncTime(),
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp interface{}
return c.BlowfishCall("https://", "user.emailPassword", requestDataReader, &resp)
}
// Client.UserGetBookmarks returns the users bookmarked artists and songs.
// Also see BookmarkAddArtistBookmark and BookmarkAddSongBookmark.
// Calls API method "user.getBookmarks"
func (c *Client) UserGetBookmarks() (*responses.UserGetBookmarks, error) {
requestData := requests.UserGetBookmarks{
UserAuthToken: c.userAuthToken,
SyncTime: c.GetSyncTime(),
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return nil, err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp responses.UserGetBookmarks
err = c.BlowfishCall("http://", "user.getBookmarks", requestDataReader, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// Client.UserGetStationList gets the list of a users stations.
// Call API method "user.getStationList"
func (c *Client) UserGetStationList(includeStationArtURL bool) (*responses.UserGetStationList, error) {
requestData := requests.UserGetStationList{
UserAuthToken: c.userAuthToken,
SyncTime: c.GetSyncTime(),
IncludeStationArtURL: includeStationArtURL,
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return nil, err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp responses.UserGetStationList
err = c.BlowfishCall("http://", "user.getStationList", requestDataReader, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// Client.UserGetStationList returns the checksum of the user's station list.
// Call API method "user.getStationListChecksum"
func (c *Client) UserGetStationListChecksum() (*responses.UserGetStationListChecksum, error) {
requestData := requests.UserGetStationListChecksum{
UserAuthToken: c.userAuthToken,
SyncTime: c.GetSyncTime(),
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return nil, err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp responses.UserGetStationListChecksum
err = c.BlowfishCall("http://", "user.getStationListChecksum", requestDataReader, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// Client.UserSetQuickMix selects the stations that should be in the special QuickMix station.
// Call API method "user.setQuickMix"
func (c *Client) UserSetQuickMix(stationIDs []string) error {
requestData := requests.UserSetQuickMix{
QuickMixStationIDs: stationIDs,
UserAuthToken: c.userAuthToken,
SyncTime: c.GetSyncTime(),
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp interface{}
return c.BlowfishCall("https://", "user.setQuickMix", requestDataReader, &resp)
}
// Client.UserSleepSong marks a song to be not played again for 1 month.
// Calls API method "user.sleepSong"
func (c *Client) UserSleepSong(trackToken string) error {
requestData := requests.UserSleepSong{
TrackToken: trackToken,
UserAuthToken: c.userAuthToken,
SyncTime: c.GetSyncTime(),
}
requestDataEncoded, err := json.Marshal(requestData)
if err != nil {
return err
}
requestDataReader := bytes.NewReader(requestDataEncoded)
var resp interface{}
return c.BlowfishCall("https://", "user.sleepSong", requestDataReader, &resp)
}