diff options
Diffstat (limited to 'goanilist.go')
-rw-r--r-- | goanilist.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/goanilist.go b/goanilist.go index dc5d4b9..c280bb5 100644 --- a/goanilist.go +++ b/goanilist.go | |||
@@ -9,6 +9,7 @@ import ( | |||
9 | "log" | 9 | "log" |
10 | "net/http" | 10 | "net/http" |
11 | "net/url" | 11 | "net/url" |
12 | "sort" | ||
12 | "time" | 13 | "time" |
13 | ) | 14 | ) |
14 | 15 | ||
@@ -127,6 +128,39 @@ func (c *Client) User() (*UserResult, error) { | |||
127 | return res, nil | 128 | return res, nil |
128 | } | 129 | } |
129 | 130 | ||
131 | func (c *Client) Favourites(user int) (*FavouritesResult, error) { | ||
132 | if !c.IsCoupled { | ||
133 | return nil, ErrAnilistNotCoupled | ||
134 | } | ||
135 | if err := c.RenewToken(); err != nil { | ||
136 | return nil, err | ||
137 | } | ||
138 | res := &FavouritesResult{} | ||
139 | err := c.get(fmt.Sprintf("user/%d/favourites", user), res) | ||
140 | if err != nil { | ||
141 | return nil, err | ||
142 | } | ||
143 | if res.Characters != nil { | ||
144 | sort.Stable(res.Characters) | ||
145 | } | ||
146 | return res, nil | ||
147 | } | ||
148 | |||
149 | func (c *Client) CharacterPage(id int) (*CharacterPageResult, error) { | ||
150 | if !c.IsCoupled { | ||
151 | return nil, ErrAnilistNotCoupled | ||
152 | } | ||
153 | if err := c.RenewToken(); err != nil { | ||
154 | return nil, err | ||
155 | } | ||
156 | res := &CharacterPageResult{} | ||
157 | err := c.get(fmt.Sprintf("character/%d/page", id), res) | ||
158 | if err != nil { | ||
159 | return nil, err | ||
160 | } | ||
161 | return res, nil | ||
162 | } | ||
163 | |||
130 | func (c *Client) post(path string, values url.Values, result interface{}) error { | 164 | func (c *Client) post(path string, values url.Values, result interface{}) error { |
131 | resp, err := http.PostForm(fmt.Sprintf("%s%s", API_URL, path), values) | 165 | resp, err := http.PostForm(fmt.Sprintf("%s%s", API_URL, path), values) |
132 | if err != nil { | 166 | if err != nil { |
@@ -154,6 +188,7 @@ func (c *Client) handleResponse(resp *http.Response, path string, values url.Val | |||
154 | return err | 188 | return err |
155 | } | 189 | } |
156 | err = json.Unmarshal(body, result) | 190 | err = json.Unmarshal(body, result) |
191 | //log.Println(string(body)) //Praktisch zum testen von neuen API-Funktionen | ||
157 | if err != nil { | 192 | if err != nil { |
158 | log.Println(string(body)) | 193 | log.Println(string(body)) |
159 | return err | 194 | return err |