From 74a5f1ce1594d01ef7caeb3c5fcac047a7d8f9b3 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 14 Feb 2022 23:02:38 +0530 Subject: fixed UpdateAnime not working, though incomplete and kinda dangerous right now --- user/anime/request_handler.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'user/anime/request_handler.go') 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) -- cgit v1.2.3