diff options
author | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-02-14 23:02:38 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-02-14 23:02:38 +0530 |
commit | 74a5f1ce1594d01ef7caeb3c5fcac047a7d8f9b3 (patch) | |
tree | 24123f6e0dc0d7663ea8e4ddf9de366cd1874f79 /user/anime/request_handler.go | |
parent | a5a96fe4673048d49f8f14665e4065e199b1179b (diff) |
fixed UpdateAnime not working, though incomplete and kinda dangerous right now
Diffstat (limited to 'user/anime/request_handler.go')
-rw-r--r-- | user/anime/request_handler.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/user/anime/request_handler.go b/user/anime/request_handler.go index 3de8e4a..6f29d88 100644 --- a/user/anime/request_handler.go +++ b/user/anime/request_handler.go @@ -17,8 +17,9 @@ package anime import ( - "bytes" + "strings" "encoding/json" + "net/url" "io/ioutil" "log" "net/http" @@ -61,13 +62,21 @@ func (c AnimeListClient) requestHandler(endpoint, method string) string { } // for PUT requests (used by UpdateAnime) -func (c AnimeListClient) putRequestHandler(endpoint string, data []uint8) serverResponse { +func (c AnimeListClient) putRequestHandler(endpoint string, updateData UpdateAnimeData) serverResponse { + // TODO: make this do other stuff + p := url.Values{} + p.Set("score", strconv.Itoa(updateData.Score)) + p.Set("num_watched_episodes", strconv.Itoa(updateData.EpWatched)) + // generate request - req, err := http.NewRequest(http.MethodPut, endpoint, bytes.NewBuffer(data)) + req, err := http.NewRequest(http.MethodPut, endpoint, strings.NewReader(p.Encode())) if err != nil { log.Fatal(err) } req.Header.Add("Authorization", c.AuthToken) + // this makes the sending-data-to-server magic work + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + req.Header.Add("Content-Length", strconv.Itoa(len(p.Encode()))) // do request res, err := c.HttpClient.Do(req) |