-
Notifications
You must be signed in to change notification settings - Fork 1
/
AnimeList.go
95 lines (87 loc) · 1.5 KB
/
AnimeList.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
package anilist
// AnimeList ...
type AnimeList struct {
Lists []struct {
Name string `json:"name"`
Entries []*AnimeListItem `json:"entries"`
} `json:"lists"`
User struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"user"`
}
// GetAnimeList ...
func GetAnimeList(userID int) (*AnimeList, error) {
type Variables struct {
ID int `json:"id"`
ListType string `json:"listType"`
}
body := struct {
Query string `json:"query"`
Variables Variables `json:"variables"`
}{
Query: `
query ($id: Int!, $listType: MediaType) {
MediaListCollection (userId: $id, type: $listType) {
lists {
name
entries {
... mediaListEntry
}
}
user {
id
name
}
}
}
fragment mediaListEntry on MediaList {
id
score
scoreRaw: score (format: POINT_100)
progress
repeat
private
notes
status
startedAt {
year
month
day
}
completedAt {
year
month
day
}
updatedAt
createdAt
media {
id
idMal
title {
romaji
english
native
}
episodes
}
}
`,
Variables: Variables{
ID: userID,
ListType: "ANIME",
},
}
// Query response
response := new(struct {
Data struct {
MediaListCollection *AnimeList `json:"MediaListCollection"`
} `json:"data"`
})
err := Query(body, &response)
if err != nil {
return nil, err
}
return response.Data.MediaListCollection, nil
}