blob: 5bb1beca6789713620c37ab3c7c1e6d3e86ef433 (
plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
package goanilist
import (
"encoding/json"
"strconv"
)
type APIError interface {
Get() *FlexibleError
}
type FlexibleError struct {
RawError *json.RawMessage `json:"error"`
Error string
ErrorMessage string `json:"error_message"`
}
type complexError struct {
Error string `json:"error"`
ErrorDescription string `json:"error_description"`
Status int `json:"status"`
Messages []string `json:"messages"`
}
func (e *FlexibleError) ParseRawError() {
if e.RawError == nil {
return
}
ce := complexError{}
err := json.Unmarshal(*e.RawError, &ce)
if err == nil {
if ce.Error != "" {
e.Error = ce.Error
e.ErrorMessage = ce.ErrorDescription
} else {
e.Error = strconv.Itoa(ce.Status)
e.ErrorMessage = ""
for k, v := range ce.Messages {
if k > 0 {
e.ErrorMessage += "\n"
}
e.ErrorMessage += v
}
}
} else {
e.Error = string(*e.RawError)
}
}
func (e *FlexibleError) Get() *FlexibleError {
return e
}
type AccessTokenResult struct {
FlexibleError
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
Expires int64 `json:"expires"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
}
type UserResult struct {
FlexibleError
ID int `json:"id"`
DisplayName string `json:"display_name"`
}
type FavouritesResult struct {
FlexibleError
Characters CharacterResultCollection `json:"character"`
}
type CharacterResultCollection []CharacterResult
func (c CharacterResultCollection) Len() int {
return len(c)
}
func (c CharacterResultCollection) Less(i, j int) bool {
return c[i].Order < c[j].Order
}
func (c CharacterResultCollection) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
type CharacterResult struct {
FlexibleError
ID int `json:"id"`
GivenName string `json:"name_first"`
FamilyName string `json:"name_last"`
JapaneseName string `json:"name_japanese"`
AlternativeName string `json:"name_alt"`
Info string `json:"info"`
Role string `json:"role"`
ImageURL string `json:"image_url_lge"`
ThumbURL string `json:"image_url_med"`
Order int `json:"order"`
}
type CharacterPageResult struct {
FlexibleError
CharacterResult
Anime []AnimeResult `json:"anime"`
Manga []MangaResult `json:"manga"`
}
type SeriesResult struct {
FlexibleError
ID int `json:"id"`
SeriesType string `json:"series_type"`
Type string `json:"type"`
TitleRomaji string `json:"title_romaji"`
TitleEnglish string `json:"title_english"`
TitleJapanese string `json:"title_japanese"`
Synonyms []string `json:"synonyms"`
Description string `json:"description"`
StartDate int64 `json:"start_date_fuzzy"`
EndDate int64 `json:"end_date_fuzzy"`
Season int `json:"season"`
Genres []string `json:"genres"`
Adult bool `json:"adult"`
AverageScore float32 `json:"average_score"`
Popularity int `json:"popularity"`
Favourite bool `json:"favourite"`
ImageURL string `json:"image_url_lge"`
ThumbSmallURL string `json:"image_url_sml"`
ThumbBigURL string `json:"image_url_med"`
BannerURL string `json:"image_url_banner"`
UpdatedAt int64 `json:"updated_at"`
}
type AnimeResult struct {
FlexibleError
SeriesResult
TotalEpisodes int `json:"total_episodes"`
EpisodeDuration int `json:"duration"`
AiringStatus string `json:"airing_status"`
YoutubeID string `json:"youtube_id"`
Hashtag string `json:"hashtag"`
Source string `json:"source"`
}
type MangaResult struct {
FlexibleError
SeriesResult
TotalChapters int `json:"total_chapters"`
TotalVolumes int `json:"total_volumes"`
PublishingStatus string `json:"publishing_status"`
}
|