aboutsummaryrefslogtreecommitdiff
path: root/types.go
blob: e451806a30d079fbdbf62689545bcc5cc9f63ab6 (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
package goanilist

import "encoding/json"

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"`
}

func (e *FlexibleError) ParseRawError() {
	ce := complexError{}
	err := json.Unmarshal(e.RawError, &ce)
	if err == nil {
		e.Error = ce.Error
		e.ErrorMessage = ce.ErrorDescription
	} 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"`
}