-
Notifications
You must be signed in to change notification settings - Fork 1
/
person.go
92 lines (88 loc) · 2.93 KB
/
person.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
// Copyright 2016 The tmdb Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package tmdb
import (
"encoding/json"
"errors"
"fmt"
"net/url"
)
// Person type represents The Movie's Database Person
type Person struct {
Adult bool `json:"adult"`
AlsoKnownAs []interface{} `json:"also_known_as"`
Biography string `json:"biography"`
Birthday string `json:"birthday"`
Deathday string `json:"deathday"`
Homepage string `json:"homepage"`
ID int `json:"id"`
ImdbID string `json:"imdb_id"`
MovieCredits struct {
Cast []struct {
Adult bool `json:"adult"`
Character string `json:"character"`
CreditID string `json:"credit_id"`
ID int `json:"id"`
OriginalTitle string `json:"original_title"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string `json:"title"`
} `json:"cast"`
Crew []struct {
Adult bool `json:"adult"`
CreditID string `json:"credit_id"`
Department string `json:"department"`
ID int `json:"id"`
Job string `json:"job"`
OriginalTitle string `json:"original_title"`
PosterPath string `json:"poster_path"`
ReleaseDate string `json:"release_date"`
Title string `json:"title"`
} `json:"crew"`
} `json:"movie_credits"`
Name string `json:"name"`
PlaceOfBirth string `json:"place_of_birth"`
Popularity float64 `json:"popularity"`
ProfilePath string `json:"profile_path"`
TvCredits struct {
Cast []struct {
Character string `json:"character"`
CreditID string `json:"credit_id"`
EpisodeCount int `json:"episode_count"`
FirstAirDate string `json:"first_air_date"`
ID int `json:"id"`
Name string `json:"name"`
OriginalName string `json:"original_name"`
PosterPath string `json:"poster_path"`
} `json:"cast"`
Crew []struct {
CreditID string `json:"credit_id"`
Department string `json:"department"`
EpisodeCount int `json:"episode_count"`
FirstAirDate string `json:"first_air_date"`
ID int `json:"id"`
Job string `json:"job"`
Name string `json:"name"`
OriginalName string `json:"original_name"`
PosterPath string `json:"poster_path"`
} `json:"crew"`
} `json:"tv_credits"`
}
// GetPerson ...
func (tmdb *TMDB) GetPerson(id string) (result Person, err error) {
s := fmt.Sprintf("%sperson/%s?api_key=%s&append_to_response=movie_credits,tv_credits", tmdb.BaseURL, id, tmdb.APIKey)
u, err := url.Parse(s)
if err != nil {
return result, err
}
body, resp, err := tmdb.FetchContent(u)
if err != nil {
return result, err
}
if resp.StatusCode != 200 {
return result, errors.New(resp.Status)
}
err = json.Unmarshal(body, &result)
return result, err
}