forked from cyruzin/golang-tmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeywords.go
79 lines (74 loc) · 2.13 KB
/
keywords.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 tmdb
import "fmt"
// KeywordDetails type is a struct for keyword JSON response.
type KeywordDetails struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
// GetKeywordDetails get keyword details by id.
//
// https://developers.themoviedb.org/3/keywords/get-keyword-details
func (c *Client) GetKeywordDetails(
id int,
) (*KeywordDetails, error) {
tmdbURL := fmt.Sprintf(
"%s%s%d?api_key=%s",
baseURL,
keywordURL,
id,
c.apiKey,
)
keywordDetails := KeywordDetails{}
if err := c.get(tmdbURL, &keywordDetails); err != nil {
return nil, err
}
return &keywordDetails, nil
}
// KeywordMovies type is a struct for movies that belong to a keyword JSON response.
type KeywordMovies struct {
ID int64 `json:"id"`
Page int64 `json:"page"`
Results []struct {
Adult bool `json:"adult"`
BackdropPath string `json:"backdrop_path"`
GenreIDs []int64 `json:"genre_ids"`
ID int64 `json:"id"`
OriginalLanguage string `json:"original_language"`
OriginalTitle string `json:"original_title"`
Overview string `json:"overview"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string `json:"title"`
Video bool `json:"video"`
VoteAverage float32 `json:"vote_average"`
VoteCount int64 `json:"vote_count"`
Popularity float32 `json:"popularity"`
} `json:"results"`
TotalPages int64 `json:"total_pages"`
TotalResults int64 `json:"total_results"`
}
// GetKeywordMovies get the movies that belong to a keyword.
//
// We highly recommend using movie discover instead of this
// method as it is much more flexible.
//
// https://developers.themoviedb.org/3/keywords/get-movies-by-keyword
func (c *Client) GetKeywordMovies(
id int,
urlOptions map[string]string,
) (*KeywordMovies, error) {
options := c.fmtOptions(urlOptions)
tmdbURL := fmt.Sprintf(
"%s%s%d/movies?api_key=%s%s",
baseURL,
keywordURL,
id,
c.apiKey,
options,
)
keywordMovies := KeywordMovies{}
if err := c.get(tmdbURL, &keywordMovies); err != nil {
return nil, err
}
return &keywordMovies, nil
}