tmdb - people.go
1 package tmdb
2
3 import (
4 "encoding/json"
5 "fmt"
6 "net/url"
7 )
8
9 // Person contains the information about a person.
10 type Person struct {
11 Birthday *string `json:"birthday"`
12 KnownForDepartment string `json:"known_for_department"`
13 Deathday *string `json:"deathday"`
14 ID int64 `json:"id"`
15 Name string `json:"name"`
16 AKA []string `json:"also_known_as"`
17 Gender int64 `json:"gender"`
18 Biography string `json:"biography"`
19 Popularity float64 `json:"popularity"`
20 PlaceOfBirth *string `json:"place_of_birth"`
21 ProfilePath *string `json:"profile_path"`
22 Adult bool `json:"adult"`
23 IMDBID string `json:"imdb_id"`
24 Homepage string `json:"homepage"`
25 }
26
27 // PersonDetails retreives the details of the specified person.
28 func (t *TMDB) PersonDetails(id int64, params ...option) (*Person, error) {
29 p := new(Person)
30
31 if err := t.get(p, fmt.Sprintf("/3/person/%d", id), url.Values{}, params...); err != nil {
32 return nil, err
33 }
34
35 return p, nil
36 }
37
38 // PersonChanges contains informaton about changes made to a person's profile.
39 type PersonChanges struct {
40 Changes []struct {
41 Key string `json:"key"`
42 Items []struct {
43 ID string `json:"id"`
44 Action string `json:"action"`
45 Time string `json:"time"`
46 OriginalValue json.RawMessage `json:"original_value"`
47 } `json:"items"`
48 } `json:"changes"`
49 }
50
51 // PersonChanges retreives the information about changes made to a person's profile.
52 func (t *TMDB) PersonChanges(id int64, params ...option) (*PersonChanges, error) {
53 p := new(PersonChanges)
54
55 if err := t.get(p, fmt.Sprintf("/3/person/%d/changes", id), url.Values{}, params...); err != nil {
56 return nil, err
57 }
58
59 return p, nil
60 }
61
62 // PersonMovieCredits retreives the movie credits for a person.
63 func (t *TMDB) PersonMovieCredits(id int64, params ...option) (*Credits, error) {
64 c := new(Credits)
65
66 if err := t.get(c, fmt.Sprintf("/3/person/%d/movie_credits", id), url.Values{}, params...); err != nil {
67 return nil, err
68 }
69
70 return c, nil
71 }
72
73 // PersonTVCredits retreives the movie credits for a person.
74 func (t *TMDB) PersonTVCredits(id int64, params ...option) (*Credits, error) {
75 c := new(Credits)
76
77 if err := t.get(c, fmt.Sprintf("/3/person/%d/tv_credits", id), url.Values{}, params...); err != nil {
78 return nil, err
79 }
80
81 return c, nil
82 }
83
84 // PersonCombinedCredits retreives the movie credits for a person.
85 func (t *TMDB) PersonCombinedCredits(id int64, params ...option) (*Credits, error) {
86 c := new(Credits)
87
88 if err := t.get(c, fmt.Sprintf("/3/person/%d/combined_credits", id), url.Values{}, params...); err != nil {
89 return nil, err
90 }
91
92 return c, nil
93 }
94
95 // PersonExternalIDs retreives the external IDs for a person.
96 func (t *TMDB) PersonExternalIDs(id int64, params ...option) (*ExternalIDs, error) {
97 e := new(ExternalIDs)
98
99 if err := t.get(e, fmt.Sprintf("/3/person/%d/external_ids", id), url.Values{}, params...); err != nil {
100 return nil, err
101 }
102
103 return e, nil
104 }
105
106 // PersonImages contains all of the images for a person.
107 type PersonImages struct {
108 ID int64 `json:"id"`
109 Profiles []Image `json:"profiles"`
110 }
111
112 // PersonImages retreives all of the images for a person.
113 func (t *TMDB) PersonImages(id int64) (*PersonImages, error) {
114 p := new(PersonImages)
115
116 if err := t.get(p, fmt.Sprintf("/3/person/%d/images", id), url.Values{}); err != nil {
117 return nil, err
118 }
119
120 return p, nil
121 }
122
123 // PersonTaggedImages contains a list of all tagged images for a person.
124 type PersonTaggedImages struct {
125 ID int64 `json:"id"`
126 Search
127 Results []struct {
128 Image
129 ID string `json:"id"`
130 ImageType string `json:"image_type"`
131 Media TVOrMovie `json:"media"`
132 MediaType string `json:"media_type"`
133 } `json:"results"`
134 }
135
136 // PersonTaggedImages retreives all of the tagged images for the specified person.
137 func (t *TMDB) PersonTaggedImages(id int64, params ...option) (*PersonTaggedImages, error) {
138 p := new(PersonTaggedImages)
139
140 if err := t.get(p, fmt.Sprintf("/3/person/%d/tagged_images", id), url.Values{}, params...); err != nil {
141 return nil, err
142 }
143
144 return p, nil
145 }
146
147 // PersonTranslations contains the translations that have been created for a person.
148 type PersonTranslations struct {
149 Translations []struct {
150 Language string `json:"iso_639_1"`
151 Country string `json:"iso_3166_1"`
152 Name string `json:"name"`
153 Data struct {
154 Biography string `json:"biography"`
155 } `json:"data"`
156 EnglishName string `json:"english_name"`
157 } `json:"translations"`
158 ID int64 `json:"id"`
159 }
160
161 // PersonTranslations retreives all of the translations that have been created for a person.
162 func (t *TMDB) PersonTranslations(id int64, params ...option) (*PersonTranslations, error) {
163 p := new(PersonTranslations)
164
165 if err := t.get(p, fmt.Sprintf("/3/person/%d/translations", id), url.Values{}, params...); err != nil {
166 return nil, err
167 }
168
169 return p, nil
170 }
171
172 // PersonLatest retreives the most recent person added to the database.
173 func (t *TMDB) PersonLatest(params ...option) (*Person, error) {
174 p := new(Person)
175
176 if err := t.get(p, "/3/person/latest", url.Values{}, params...); err != nil {
177 return nil, err
178 }
179
180 return p, nil
181 }
182
183 // PersonPopular retreives the most popular people in the database.
184 func (t *TMDB) PersonPopular(params ...option) (*SearchPeople, error) {
185 s := new(SearchPeople)
186
187 if err := t.get(s, "/3/person/popular", url.Values{}, params...); err != nil {
188 return nil, err
189 }
190
191 return s, nil
192 }
193