/
list.go
76 lines (71 loc) · 2.2 KB
/
list.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
package tmdb
import "fmt"
// ListDetails type is a struct for details JSON response.
type ListDetails struct {
CreatedBy string `json:"created_by"`
Description string `json:"description"`
FavoriteCount int64 `json:"favorite_count"`
ID string `json:"id"`
Items []struct {
VoteAverage float32 `json:"vote_average"`
VoteCount int64 `json:"vote_count"`
ID int64 `json:"id"`
Video bool `json:"video"`
MediaType string `json:"media_type"`
Title string `json:"title"`
Popularity float32 `json:"popularity"`
PosterPath string `json:"poster_path"`
OriginalLanguage string `json:"original_language"`
OriginalTitle string `json:"original_title"`
GenreIDs []int64 `json:"genre_ids"`
BackdropPath string `json:"backdrop_path"`
Adult bool `json:"adult"`
Overview string `json:"overview"`
ReleaseDate string `json:"release_date"`
} `json:"items"`
ItemCount int64 `json:"item_count"`
Iso639_1 string `json:"iso_639_1"`
Name string `json:"name"`
PosterPath string `json:"poster_path"`
}
// ListItemStatus type is a struct for item status JSON response.
type ListItemStatus struct {
ID string `json:"id"`
ItemPresent bool `json:"item_present"`
}
// GetListDetails get the details of a list.
//
// https://developers.themoviedb.org/3/lists/get-list-details
func (c *Client) GetListDetails(
id string, o map[string]string,
) (*ListDetails, error) {
options := c.fmtOptions(o)
tmdbURL := fmt.Sprintf(
"%s%s%s?api_key=%s%s",
baseURL, listURL, id, c.apiKey, options,
)
t := ListDetails{}
err := c.get(tmdbURL, &t)
if err != nil {
return nil, err
}
return &t, nil
}
// GetListItemStatus check if a movie has already been added to the list.
//
// https://developers.themoviedb.org/3/lists/check-item-status
func (c *Client) GetListItemStatus(
id string, o map[string]string,
) (*ListItemStatus, error) {
options := c.fmtOptions(o)
tmdbURL := fmt.Sprintf(
"%s%s%s/item_status?api_key=%s%s",
baseURL, listURL, id, c.apiKey, options,
)
t := ListItemStatus{}
err := c.get(tmdbURL, &t)
if err != nil {
return nil, err
}
return &t, nil
}