diff options
author | rtz12 <koenig@fagott.pw> | 2016-11-13 02:45:39 (UTC) |
---|---|---|
committer | rtz12 <koenig@fagott.pw> | 2016-11-13 02:45:39 (UTC) |
commit | ff9f4f328619377f5035c4835ff8c587f4661fc4 (patch) | |
tree | b4b33e78174648aa7fbc44e4b3ebb81405a7d7b0 /types.go |
Go Anilist-API wurde implementiert
Diffstat (limited to 'types.go')
-rw-r--r-- | types.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/types.go b/types.go new file mode 100644 index 0000000..e451806 --- /dev/null +++ b/types.go | |||
@@ -0,0 +1,48 @@ | |||
1 | package goanilist | ||
2 | |||
3 | import "encoding/json" | ||
4 | |||
5 | type APIError interface { | ||
6 | Get() *FlexibleError | ||
7 | } | ||
8 | |||
9 | type FlexibleError struct { | ||
10 | RawError json.RawMessage `json:"error"` | ||
11 | Error string | ||
12 | ErrorMessage string `json:"error_message"` | ||
13 | } | ||
14 | |||
15 | type complexError struct { | ||
16 | Error string `json:"error"` | ||
17 | ErrorDescription string `json:"error_description"` | ||
18 | } | ||
19 | |||
20 | func (e *FlexibleError) ParseRawError() { | ||
21 | ce := complexError{} | ||
22 | err := json.Unmarshal(e.RawError, &ce) | ||
23 | if err == nil { | ||
24 | e.Error = ce.Error | ||
25 | e.ErrorMessage = ce.ErrorDescription | ||
26 | } else { | ||
27 | e.Error = string(e.RawError) | ||
28 | } | ||
29 | } | ||
30 | |||
31 | func (e *FlexibleError) Get() *FlexibleError { | ||
32 | return e | ||
33 | } | ||
34 | |||
35 | type AccessTokenResult struct { | ||
36 | FlexibleError | ||
37 | AccessToken string `json:"access_token"` | ||
38 | TokenType string `json:"token_type"` | ||
39 | Expires int64 `json:"expires"` | ||
40 | ExpiresIn int `json:"expires_in"` | ||
41 | RefreshToken string `json:"refresh_token"` | ||
42 | } | ||
43 | |||
44 | type UserResult struct { | ||
45 | FlexibleError | ||
46 | ID int `json:"id"` | ||
47 | DisplayName string `json:"display_name"` | ||
48 | } | ||