-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpeople.go
131 lines (117 loc) · 2.91 KB
/
people.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
package jikan
import (
"fmt"
"net/url"
"time"
)
// PeopleBase struct
type PeopleBase struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
WebsiteUrl string `json:"website_url"`
Images struct {
Jpg struct {
ImageUrl string `json:"image_url"`
} `json:"jpg"`
} `json:"images"`
Name string `json:"name"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
AlternateNames []string `json:"alternate_names"`
Birthday time.Time `json:"birthday"`
Favorites int `json:"favorites"`
About string `json:"about"`
}
// PersonById struct
type PersonById struct {
Data PeopleBase `json:"data"`
}
// GetPersonById returns person by id
func GetPersonById(id int) (*PersonById, error) {
res := &PersonById{}
err := urlToStruct(fmt.Sprintf("/people/%d", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// PersonAnime struct
type PersonAnime struct {
Data []struct {
Position string `json:"position"`
Anime EntryTitle3 `json:"anime"`
} `json:"data"`
}
// GetPersonAnime returns person anime
func GetPersonAnime(id int) (*PersonAnime, error) {
res := &PersonAnime{}
err := urlToStruct(fmt.Sprintf("/people/%d/anime", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// PersonVoices struct
type PersonVoices struct {
Data []struct {
Role string `json:"role"`
Anime EntryTitle3 `json:"anime"`
Character EntryName2 `json:"character"`
} `json:"data"`
}
// GetPersonVoices returns person voices
func GetPersonVoices(id int) (*PersonVoices, error) {
res := &PersonVoices{}
err := urlToStruct(fmt.Sprintf("/people/%d/voices", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// PersonManga struct
type PersonManga struct {
Data []struct {
Position string `json:"position"`
Manga EntryTitle3 `json:"manga"`
} `json:"data"`
}
// GetPersonManga returns person manga
func GetPersonManga(id int) (*PersonManga, error) {
res := &PersonManga{}
err := urlToStruct(fmt.Sprintf("/people/%d/manga", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// PersonPictures struct
type PersonPictures struct {
Data []struct {
Jpg struct {
ImageUrl string `json:"image_url"`
} `json:"jpg"`
} `json:"data"`
}
// GetPersonPictures returns person pictures
func GetPersonPictures(id int) (*PersonPictures, error) {
res := &PersonPictures{}
err := urlToStruct(fmt.Sprintf("/people/%d/pictures", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// PeopleSearch struct
type PeopleSearch struct {
Data []PeopleBase `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetPeopleSearch returns people search
func GetPeopleSearch(query url.Values) (*PeopleSearch, error) {
res := &PeopleSearch{}
err := urlToStruct(fmt.Sprintf("/people?%s", query.Encode()), res)
if err != nil {
return nil, err
}
return res, nil
}