forked from cyruzin/golang-tmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
357 lines (334 loc) · 8.65 KB
/
account.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package tmdb
import (
"fmt"
"net/http"
)
// AccountDetails type is a struct for details JSON response.
type AccountDetails struct {
Avatar struct {
Gravatar struct {
Hash string `json:"hash"`
} `json:"gravatar"`
TMDB struct {
AvatarPath string `json:"avatar_path"`
} `json:"tmdb"`
} `json:"avatar"`
ID int64 `json:"id"`
Iso639_1 string `json:"iso_639_1"`
Iso3166_1 string `json:"iso_3166_1"`
Name string `json:"name"`
IncludeAdult bool `json:"include_adult"`
Username string `json:"username"`
}
// GetAccountDetails get your account details.
//
// https://developers.themoviedb.org/3/account/get-account-details
func (c *Client) GetAccountDetails() (*AccountDetails, error) {
tmdbURL := fmt.Sprintf(
"%s/account?api_key=%s&session_id=%s",
baseURL,
c.apiKey,
c.sessionID,
)
details := AccountDetails{}
if err := c.get(tmdbURL, &details); err != nil {
return nil, err
}
return &details, nil
}
// AccountCreatedLists type is a struct for created lists JSON response.
type AccountCreatedLists struct {
Page int64 `json:"page"`
*AccountCreatedListsResults
TotalPages int64 `json:"total_pages"`
TotalResults int64 `json:"total_results"`
}
// GetCreatedLists get all of the lists created by an account.
// Will invlude private lists if you are the owner.
//
// https://developers.themoviedb.org/3/account/get-created-lists
func (c *Client) GetCreatedLists(
id int,
urlOptions map[string]string,
) (*AccountCreatedLists, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/lists?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
createdLists := AccountCreatedLists{}
if err := c.get(tmdbURL, &createdLists); err != nil {
return nil, err
}
return &createdLists, nil
}
// AccountFavoriteMovies type is a struct for favorite movies JSON response.
type AccountFavoriteMovies struct {
Page int64 `json:"page"`
*AccountFavoriteMoviesResults
TotalPages int64 `json:"total_pages"`
TotalResults int64 `json:"total_results"`
}
// GetFavoriteMovies get the list of your favorite movies.
//
// https://developers.themoviedb.org/3/account/get-favorite-movies
func (c *Client) GetFavoriteMovies(
id int,
urlOptions map[string]string,
) (*AccountFavoriteMovies, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/favorite/movies?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
favoriteMovies := AccountFavoriteMovies{}
if err := c.get(tmdbURL, &favoriteMovies); err != nil {
return nil, err
}
return &favoriteMovies, nil
}
// AccountFavoriteTVShows type is a struct for favorite tv shows JSON response.
type AccountFavoriteTVShows struct {
Page int64 `json:"page"`
*AccountFavoriteTVShowsResults
TotalPages int64 `json:"total_pages"`
TotalResults int64 `json:"total_results"`
}
// GetFavoriteTVShows get the list of your favorite TV shows.
//
// https://developers.themoviedb.org/3/account/get-favorite-tv-shows
func (c *Client) GetFavoriteTVShows(
id int,
urlOptions map[string]string,
) (*AccountFavoriteTVShows, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/favorite/tv?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
favoriteTVShows := AccountFavoriteTVShows{}
if err := c.get(tmdbURL, &favoriteTVShows); err != nil {
return nil, err
}
return &favoriteTVShows, nil
}
// AccountFavorite type is a struct for movies or TV shows
// favorite JSON request.
type AccountFavorite struct {
MediaType string `json:"media_type"`
MediaID int64 `json:"media_id"`
Favorite bool `json:"favorite"`
}
// MarkAsFavorite this method allows you to mark a movie
// or TV show as a favorite item.
//
// https://developers.themoviedb.org/3/account/mark-as-favorite
func (c *Client) MarkAsFavorite(
id int,
title *AccountFavorite,
) (*Response, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d/favorite?api_key=%s&session_id=%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
)
markAsFavorite := Response{}
if err := c.request(
tmdbURL,
title,
http.MethodPost,
&markAsFavorite,
); err != nil {
return nil, err
}
return &markAsFavorite, nil
}
// AccountRatedMovies type is a struct for rated movies JSON response.
type AccountRatedMovies struct {
*AccountFavoriteMovies
}
// GetRatedMovies get a list of all the movies you have rated.
//
// https://developers.themoviedb.org/3/account/get-rated-movies
func (c *Client) GetRatedMovies(
id int,
urlOptions map[string]string,
) (*AccountRatedMovies, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/rated/movies?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
ratedMovies := AccountRatedMovies{}
if err := c.get(tmdbURL, &ratedMovies); err != nil {
return nil, err
}
return &ratedMovies, nil
}
// AccountRatedTVShows type is a struct for rated TV shows JSON response.
type AccountRatedTVShows struct {
*AccountFavoriteTVShows
}
// GetRatedTVShows get a list of all the TV shows you have rated.
//
// https://developers.themoviedb.org/3/account/get-rated-tv-shows
func (c *Client) GetRatedTVShows(
id int,
urlOptions map[string]string,
) (*AccountRatedTVShows, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/rated/tv?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
ratedTVShows := AccountRatedTVShows{}
if err := c.get(tmdbURL, &ratedTVShows); err != nil {
return nil, err
}
return &ratedTVShows, nil
}
// AccountRatedTVEpisodes type is a struct for rated TV episodes JSON response.
type AccountRatedTVEpisodes struct {
Page int64 `json:"page"`
*AccountRatedTVEpisodesResults
TotalPages int64 `json:"total_pages"`
TotalResults int64 `json:"total_results"`
}
// GetRatedTVEpisodes get a list of all the TV episodes you have rated.
//
// https://developers.themoviedb.org/3/account/get-rated-tv-episodes
func (c *Client) GetRatedTVEpisodes(
id int,
urlOptions map[string]string,
) (*AccountRatedTVEpisodes, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/rated/tv/episodes?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
ratedTVEpisodes := AccountRatedTVEpisodes{}
if err := c.get(tmdbURL, &ratedTVEpisodes); err != nil {
return nil, err
}
return &ratedTVEpisodes, nil
}
// AccountMovieWatchlist type is a struct for movie watchlist JSON response.
type AccountMovieWatchlist struct {
*AccountFavoriteMovies
}
// GetMovieWatchlist get a list of all the movies you have added to your watchlist.
//
// https://developers.themoviedb.org/3/account/get-movie-watchlist
func (c *Client) GetMovieWatchlist(
id int,
urlOptions map[string]string,
) (*AccountMovieWatchlist, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/watchlist/movies?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
movieWatchlist := AccountMovieWatchlist{}
if err := c.get(tmdbURL, &movieWatchlist); err != nil {
return nil, err
}
return &movieWatchlist, nil
}
// AccountTVShowsWatchlist type is a struct for tv shows watchlist JSON response.
type AccountTVShowsWatchlist struct {
*AccountFavoriteTVShows
}
// GetTVShowsWatchlist get a list of all the TV shows you have added to your watchlist.
//
// https://developers.themoviedb.org/3/account/get-tv-show-watchlist
func (c *Client) GetTVShowsWatchlist(
id int,
urlOptions map[string]string,
) (*AccountTVShowsWatchlist, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/watchlist/tv?api_key=%s&session_id=%s%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
options,
)
tvShowsWatchlist := AccountTVShowsWatchlist{}
if err := c.get(tmdbURL, &tvShowsWatchlist); err != nil {
return nil, err
}
return &tvShowsWatchlist, nil
}
// AccountWatchlist type is a struct for movies or TV shows
// watchlist JSON request.
type AccountWatchlist struct {
MediaType string `json:"media_type"`
MediaID int64 `json:"media_id"`
Watchlist bool `json:"watchlist"`
}
// AddToWatchlist add a movie or TV show to your watchlist.
//
// https://developers.themoviedb.org/3/account/add-to-watchlist
func (c *Client) AddToWatchlist(
id int,
title *AccountWatchlist,
) (*Response, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d/watchlist?api_key=%s&session_id=%s",
baseURL,
accountURL,
id,
c.apiKey,
c.sessionID,
)
addToWatchlist := Response{}
if err := c.request(
tmdbURL,
title,
http.MethodPost,
&addToWatchlist,
); err != nil {
return nil, err
}
return &addToWatchlist, nil
}