aboutsummaryrefslogtreecommitdiff
path: root/types.go
diff options
context:
space:
mode:
authorrtz12 <koenig@fagott.pw>2016-11-15 17:30:31 (UTC)
committerrtz12 <koenig@fagott.pw>2016-11-15 17:30:31 (UTC)
commit23ca4cd08d882cbde02ba20b3fa477ecf43be8e5 (patch)
tree23522b87b0a983695d64da37565776c19769691b /types.go
parentdc7b1324e6eab593f9af18be22516ad5cbd559ea (diff)
API für Anilist-Import erweitertHEADmaster
Diffstat (limited to 'types.go')
-rw-r--r--types.go119
1 files changed, 111 insertions, 8 deletions
diff --git a/types.go b/types.go
index e451806..5bb1bec 100644
--- a/types.go
+++ b/types.go
@@ -1,30 +1,49 @@
1package goanilist 1package goanilist
2 2
3import "encoding/json" 3import (
4 "encoding/json"
5 "strconv"
6)
4 7
5type APIError interface { 8type APIError interface {
6 Get() *FlexibleError 9 Get() *FlexibleError
7} 10}
8 11
9type FlexibleError struct { 12type FlexibleError struct {
10 RawError json.RawMessage `json:"error"` 13 RawError *json.RawMessage `json:"error"`
11 Error string 14 Error string
12 ErrorMessage string `json:"error_message"` 15 ErrorMessage string `json:"error_message"`
13} 16}
14 17
15type complexError struct { 18type complexError struct {
16 Error string `json:"error"` 19 Error string `json:"error"`
17 ErrorDescription string `json:"error_description"` 20 ErrorDescription string `json:"error_description"`
21 Status int `json:"status"`
22 Messages []string `json:"messages"`
18} 23}
19 24
20func (e *FlexibleError) ParseRawError() { 25func (e *FlexibleError) ParseRawError() {
26 if e.RawError == nil {
27 return
28 }
21 ce := complexError{} 29 ce := complexError{}
22 err := json.Unmarshal(e.RawError, &ce) 30 err := json.Unmarshal(*e.RawError, &ce)
23 if err == nil { 31 if err == nil {
24 e.Error = ce.Error 32 if ce.Error != "" {
25 e.ErrorMessage = ce.ErrorDescription 33 e.Error = ce.Error
34 e.ErrorMessage = ce.ErrorDescription
35 } else {
36 e.Error = strconv.Itoa(ce.Status)
37 e.ErrorMessage = ""
38 for k, v := range ce.Messages {
39 if k > 0 {
40 e.ErrorMessage += "\n"
41 }
42 e.ErrorMessage += v
43 }
44 }
26 } else { 45 } else {
27 e.Error = string(e.RawError) 46 e.Error = string(*e.RawError)
28 } 47 }
29} 48}
30 49
@@ -46,3 +65,87 @@ type UserResult struct {
46 ID int `json:"id"` 65 ID int `json:"id"`
47 DisplayName string `json:"display_name"` 66 DisplayName string `json:"display_name"`
48} 67}
68
69type FavouritesResult struct {
70 FlexibleError
71 Characters CharacterResultCollection `json:"character"`
72}
73
74type CharacterResultCollection []CharacterResult
75
76func (c CharacterResultCollection) Len() int {
77 return len(c)
78}
79
80func (c CharacterResultCollection) Less(i, j int) bool {
81 return c[i].Order < c[j].Order
82}
83
84func (c CharacterResultCollection) Swap(i, j int) {
85 c[i], c[j] = c[j], c[i]
86}
87
88type CharacterResult struct {
89 FlexibleError
90 ID int `json:"id"`
91 GivenName string `json:"name_first"`
92 FamilyName string `json:"name_last"`
93 JapaneseName string `json:"name_japanese"`
94 AlternativeName string `json:"name_alt"`
95 Info string `json:"info"`
96 Role string `json:"role"`
97 ImageURL string `json:"image_url_lge"`
98 ThumbURL string `json:"image_url_med"`
99 Order int `json:"order"`
100}
101
102type CharacterPageResult struct {
103 FlexibleError
104 CharacterResult
105 Anime []AnimeResult `json:"anime"`
106 Manga []MangaResult `json:"manga"`
107}
108
109type SeriesResult struct {
110 FlexibleError
111 ID int `json:"id"`
112 SeriesType string `json:"series_type"`
113 Type string `json:"type"`
114 TitleRomaji string `json:"title_romaji"`
115 TitleEnglish string `json:"title_english"`
116 TitleJapanese string `json:"title_japanese"`
117 Synonyms []string `json:"synonyms"`
118 Description string `json:"description"`
119 StartDate int64 `json:"start_date_fuzzy"`
120 EndDate int64 `json:"end_date_fuzzy"`
121 Season int `json:"season"`
122 Genres []string `json:"genres"`
123 Adult bool `json:"adult"`
124 AverageScore float32 `json:"average_score"`
125 Popularity int `json:"popularity"`
126 Favourite bool `json:"favourite"`
127 ImageURL string `json:"image_url_lge"`
128 ThumbSmallURL string `json:"image_url_sml"`
129 ThumbBigURL string `json:"image_url_med"`
130 BannerURL string `json:"image_url_banner"`
131 UpdatedAt int64 `json:"updated_at"`
132}
133
134type AnimeResult struct {
135 FlexibleError
136 SeriesResult
137 TotalEpisodes int `json:"total_episodes"`
138 EpisodeDuration int `json:"duration"`
139 AiringStatus string `json:"airing_status"`
140 YoutubeID string `json:"youtube_id"`
141 Hashtag string `json:"hashtag"`
142 Source string `json:"source"`
143}
144
145type MangaResult struct {
146 FlexibleError
147 SeriesResult
148 TotalChapters int `json:"total_chapters"`
149 TotalVolumes int `json:"total_volumes"`
150 PublishingStatus string `json:"publishing_status"`
151}