From 05fe09f3ec167417ea94fc04148ac110f18c4ad6 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 16 Jun 2022 22:20:17 +0530 Subject: added api error handling to user/anime and user/manga packages --- user/anime/animelist.go | 42 +++++++++++++-------------- user/anime/animelist.structs.go | 10 ++++--- user/anime/request_handler.go | 60 ++++++++++++++++++++++++++------------ user/anime/update_animelist.go | 60 +++++++++++++++++++------------------- user/manga/mangalist.go | 44 ++++++++++++++-------------- user/manga/mangalist.structs.go | 20 +++++-------- user/manga/request_handler.go | 58 +++++++++++++++++++++++++------------ user/manga/update_mangalist.go | 64 ++++++++++++++++++++--------------------- 8 files changed, 199 insertions(+), 159 deletions(-) (limited to 'user') diff --git a/user/anime/animelist.go b/user/anime/animelist.go index 2840df3..321e6d0 100644 --- a/user/anime/animelist.go +++ b/user/anime/animelist.go @@ -17,7 +17,7 @@ package anime import ( - "encoding/json" + "encoding/json" "strconv" "fmt" a "github.com/MikunoNaka/MAL2Go/anime" @@ -29,7 +29,7 @@ const BASE_URL string = "https://api.myanimelist.net/v2" const maxListLimit int = 1000 // Delete an anime from user's anime list -func (c Client)DeleteAnime(id int) string { +func (c Client)DeleteAnime(id int) (string, error) { endpoint := fmt.Sprintf("%s/anime/%d/my_list_status", BASE_URL, id) /* Returns 200 if anime successfully deleted * Alternatively returns 404 if anime not in user's anime list */ @@ -37,18 +37,19 @@ func (c Client)DeleteAnime(id int) string { } // Get authenticated user's anime list -func (c Client) GetAnimeList(user, status, sort string, limit, offset int, fields []string) (a.AnimeList, error){ - var userAnimeList a.AnimeList +// returns true as second value if there are more animes present +func (c Client) GetAnimeList(user, status, sort string, limit, offset int, fields []string) ([]a.Anime, bool, error){ + var userAnimeList []a.Anime // error handling for limit limitErr := e.LimitErrHandler(limit, maxListLimit) if limitErr != nil { - return userAnimeList, limitErr + return userAnimeList, false, limitErr } // handle all the errors for the fields fields, err := e.FieldsErrHandler(fields) if err != nil { - return userAnimeList, err + return userAnimeList, false, err } // append "list_status" field only used by this func. @@ -56,12 +57,12 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int, field // checks if valid sort is specified if !e.IsValidListSort(sort) { - return userAnimeList, e.InvalidSortError + return userAnimeList, false, e.InvalidSortError } // checks if valid status is specified if status != "" && !e.IsValidListStatus(status) { - return userAnimeList, e.InvalidStatusError + return userAnimeList, false, e.InvalidStatusError } // get own list if user not specified @@ -88,27 +89,24 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int, field ) } - // get data from API - var animeListData AnimeListRaw - data := c.requestHandler(endpoint, "GET") + var animeListData animeListRaw + data, err := c.requestHandler(endpoint, "GET") + if err != nil { + return userAnimeList, false, err + } json.Unmarshal([]byte(data), &animeListData) + nextPageExists := animeListData.Paging.NextPage != "" + // set ListStatus for each element and add it to array - var animes []a.Anime for _, element := range animeListData.Data { - anime := element.Anime - anime.ListStatus = element.ListStatus - - animes = append(animes, anime) - } + a := element.Anime + a.ListStatus = element.ListStatus - // finally create AnimeList - userAnimeList = a.AnimeList { - Animes: animes, - Paging: animeListData.Paging, + userAnimeList = append(userAnimeList, a) } - return userAnimeList, nil + return userAnimeList, nextPageExists, nil } diff --git a/user/anime/animelist.structs.go b/user/anime/animelist.structs.go index 80eb01a..c727d97 100644 --- a/user/anime/animelist.structs.go +++ b/user/anime/animelist.structs.go @@ -20,12 +20,15 @@ import ( "github.com/MikunoNaka/MAL2Go/anime" ) -type AnimeListRaw struct { +type animeListRaw struct { Data []struct { Anime anime.Anime `json:"node"` ListStatus anime.ListStatus `json:"list_status"` - } `json:"data"` - Paging anime.ListPaging `json:"paging"` + } `json:"data"` + Paging struct { + NextPage string `json:"next"` + PrevPage string `json:"previous"` + } `json:"paging"` } type UpdateAnimeData struct { @@ -35,7 +38,6 @@ type UpdateAnimeData struct { EpWatched int Priority int TimesRewatched int - // NOTE: idk what RewatchValue is RewatchValue int Tags string Comments string diff --git a/user/anime/request_handler.go b/user/anime/request_handler.go index abc0afc..45bfe83 100644 --- a/user/anime/request_handler.go +++ b/user/anime/request_handler.go @@ -16,22 +16,34 @@ package anime import ( - "encoding/json" - "io/ioutil" - "log" - "net/http" - "net/url" - "strconv" - "strings" + "encoding/json" + "io/ioutil" + "log" + "net/http" + "net/url" + "strconv" + "strings" + "errors" + "github.com/MikunoNaka/MAL2Go/util" ) -type serverResponse struct { - Message string - Error string +type UpdateResponse struct { + Status string `json:"status"` + Score int `json:"score"` + EpWatched int `json:"num_episodes_watched"` + IsRewatching bool `json:"is_rewatching"` + StartDate string `json:"start_date"` + FinishDate string `json:"finish_date"` + Priority string `json:"priority"` + TimesRewatched string `json:"num_times_rewatched"` + RewatchValue string `json:"rewatch_value"` + Tags string `json:"tags"` + Comments string `json:"string"` + UpdatedAt string `json:"updated_at"` } // Handles HTTP request with your OAuth token as a Header -func (c Client) requestHandler(endpoint, method string) string { +func (c Client) requestHandler(endpoint, method string) (string, error) { // generate request req, err := http.NewRequest(method, endpoint, nil) if err != nil { @@ -52,16 +64,23 @@ func (c Client) requestHandler(endpoint, method string) string { log.Fatal(err) } + // error handling (if API returns error) + var errMsg util.APIError + json.Unmarshal(body, &errMsg) + if errMsg.Err != "" { + return string(body), errors.New(errMsg.Err + " " + errMsg.Msg) + } + // for DeleteAnime, its endpoint returns null data if method == "DELETE" { - return strconv.Itoa(res.StatusCode) + return strconv.Itoa(res.StatusCode), nil } - return string(body) + return string(body), nil } // for PUT requests (used for updating anime) -func (c Client) putRequestHandler(endpoint string, params url.Values) serverResponse { +func (c Client) putRequestHandler(endpoint string, params url.Values) (UpdateResponse, error) { paramsEncoded := params.Encode() // generate request @@ -87,10 +106,15 @@ func (c Client) putRequestHandler(endpoint string, params url.Values) serverResp log.Fatal(err) } - // TODO: there are other serverResponses. Add them - // server response, ie message / error - var resp serverResponse + // error handling (if API returns error) + var errMsg util.APIError + json.Unmarshal(body, &errMsg) + if errMsg.Err != "" { + return UpdateResponse{}, errors.New(errMsg.Err + " " + errMsg.Msg) + } + + var resp UpdateResponse json.Unmarshal(body, &resp) - return resp + return resp, nil } diff --git a/user/anime/update_animelist.go b/user/anime/update_animelist.go index 780f079..ec0d60d 100644 --- a/user/anime/update_animelist.go +++ b/user/anime/update_animelist.go @@ -18,8 +18,8 @@ package anime import ( e "github.com/MikunoNaka/MAL2Go/errhandlers" "fmt" - "net/url" - "strconv" + "net/url" + "strconv" ) // generate the endpoint url with the anime id @@ -28,12 +28,12 @@ func endpointGenerator(id int) string { } // update just an anime's status -func (c Client)SetStatus(id int, status string) (serverResponse, error) { +func (c Client)SetStatus(id int, status string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified list status is valid if !e.IsValidListStatus(status) { - return serverResponse{}, e.InvalidStatusError + return UpdateResponse{}, e.InvalidStatusError } // data to be sent to the server @@ -41,11 +41,11 @@ func (c Client)SetStatus(id int, status string) (serverResponse, error) { params.Set("status", status) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's num of episodes watched -func (c Client)SetWatchedEpisodes(id int, episodesWatched int) (serverResponse, error) { +func (c Client)SetWatchedEpisodes(id int, episodesWatched int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -53,11 +53,11 @@ func (c Client)SetWatchedEpisodes(id int, episodesWatched int) (serverResponse, params.Set("num_watched_episodes", strconv.Itoa(episodesWatched)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's rewatching status -func (c Client)SetIsRewatching(id int, isRewatching bool) (serverResponse, error) { +func (c Client)SetIsRewatching(id int, isRewatching bool) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -65,16 +65,16 @@ func (c Client)SetIsRewatching(id int, isRewatching bool) (serverResponse, error params.Set("is_rewatching", strconv.FormatBool(isRewatching)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just the anime's score -func (c Client)SetScore(id int, score int) (serverResponse, error) { +func (c Client)SetScore(id int, score int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified score is valid if !e.IsValidScore(score) { - return serverResponse{}, e.InvalidScoreError + return UpdateResponse{}, e.InvalidScoreError } // data to be sent to the server @@ -82,16 +82,16 @@ func (c Client)SetScore(id int, score int) (serverResponse, error) { params.Set("score", strconv.Itoa(score)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's priority -func (c Client)SetPriority(id int, priority int) (serverResponse, error) { +func (c Client)SetPriority(id int, priority int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified priority is valid if !e.IsValidPriority(priority) { - return serverResponse{}, e.InvalidPriorityError + return UpdateResponse{}, e.InvalidPriorityError } // data to be sent to the server @@ -99,16 +99,16 @@ func (c Client)SetPriority(id int, priority int) (serverResponse, error) { params.Set("priority", strconv.Itoa(priority)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's rewatch value -func (c Client)SetRewatchValue(id int, rewatchValue int) (serverResponse, error) { +func (c Client)SetRewatchValue(id int, rewatchValue int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified rewatch value is valid if !e.IsValidRewatchValue(rewatchValue) { - return serverResponse{}, e.InvalidRewatchValueError + return UpdateResponse{}, e.InvalidRewatchValueError } // data to be sent to the server @@ -116,11 +116,11 @@ func (c Client)SetRewatchValue(id int, rewatchValue int) (serverResponse, error) params.Set("rewatch_value", strconv.Itoa(rewatchValue)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's rewatch count -func (c Client)SetRewatchCount(id int, rewatchCount int) (serverResponse, error) { +func (c Client)SetRewatchCount(id int, rewatchCount int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -128,11 +128,11 @@ func (c Client)SetRewatchCount(id int, rewatchCount int) (serverResponse, error) params.Set("num_times_rewatched", strconv.Itoa(rewatchCount)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's tags -func (c Client)UpdateTags(id int, tags string) (serverResponse, error) { +func (c Client)UpdateTags(id int, tags string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -140,11 +140,11 @@ func (c Client)UpdateTags(id int, tags string) (serverResponse, error) { params.Set("tags", tags) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's comments -func (c Client)UpdateComments(id int, comments string) (serverResponse, error) { +func (c Client)UpdateComments(id int, comments string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -152,34 +152,34 @@ func (c Client)UpdateComments(id int, comments string) (serverResponse, error) { params.Set("comments", comments) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } /* This will overwrite everything * i won't use it.. but it's pretty flexible * so this will stay here */ // Update/Add an anime to user's anime list -func (c Client)UpdateAnime(id int, data UpdateAnimeData) (serverResponse, error) { +func (c Client)UpdateAnime(id int, data UpdateAnimeData) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified list status is valid if !e.IsValidListStatus(data.Status) { - return serverResponse{}, e.InvalidStatusError + return UpdateResponse{}, e.InvalidStatusError } // checks if specified score is valid if !e.IsValidScore(data.Score) { - return serverResponse{}, e.InvalidScoreError + return UpdateResponse{}, e.InvalidScoreError } // checks if specified priority is valid if !e.IsValidPriority(data.Priority) { - return serverResponse{}, e.InvalidPriorityError + return UpdateResponse{}, e.InvalidPriorityError } // checks if specified rewatch value is valid if !e.IsValidRewatchValue(data.RewatchValue) { - return serverResponse{}, e.InvalidRereadValueError + return UpdateResponse{}, e.InvalidRereadValueError } params := url.Values{} @@ -197,6 +197,6 @@ func (c Client)UpdateAnime(id int, data UpdateAnimeData) (serverResponse, error) params.Set("comments", data.Comments) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } diff --git a/user/manga/mangalist.go b/user/manga/mangalist.go index af75e9f..b60b1d7 100644 --- a/user/manga/mangalist.go +++ b/user/manga/mangalist.go @@ -17,18 +17,19 @@ package manga import ( - "encoding/json" + "encoding/json" "strconv" "fmt" e "github.com/MikunoNaka/MAL2Go/errhandlers" u "github.com/MikunoNaka/MAL2Go/util" + m "github.com/MikunoNaka/MAL2Go/manga" ) const BASE_URL string = "https://api.myanimelist.net/v2" const maxListLimit int = 1000 // Delete a manga from user's manga list -func (c Client)DeleteManga(id int) string { +func (c Client)DeleteManga(id int) (string, error) { endpoint := fmt.Sprintf("%s/manga/%d/my_list_status", BASE_URL, id) /* Returns 200 if manga successfully deleted * Alternatively returns 404 if manga not in user's manga list */ @@ -36,18 +37,19 @@ func (c Client)DeleteManga(id int) string { } // Get authenticated user's manga list -func (c Client) GetMangaList(user, status, sort string, limit, offset int, fields []string) (MangaList, error){ - var userMangaList MangaList +// returns true as second value if there are more mangas present +func (c Client) GetMangaList(user, status, sort string, limit, offset int, fields []string) ([]m.Manga, bool, error){ + var userMangaList []m.Manga // error handling for limit limitErr := e.LimitErrHandler(limit, maxListLimit) if limitErr != nil { - return userMangaList, limitErr + return userMangaList, false, limitErr } // handle all the errors for the fields fields, err := e.FieldsErrHandler(fields) if err != nil { - return userMangaList, err + return userMangaList, false, err } // append "list_status" field only used by this func. @@ -55,12 +57,12 @@ func (c Client) GetMangaList(user, status, sort string, limit, offset int, field // checks if valid sort is specified if !e.IsValidMangaListSort(sort) { - return userMangaList, e.InvalidSortError + return userMangaList, false, e.InvalidSortError } // checks if valid status is specified if status != "" && !e.IsValidMangaListStatus(status) { - return userMangaList, e.InvalidStatusError + return userMangaList, false, e.InvalidStatusError } // get own list if user not specified @@ -88,25 +90,23 @@ func (c Client) GetMangaList(user, status, sort string, limit, offset int, field } // get data from API - var mangaListData MangaListRaw - data := c.requestHandler(endpoint, "GET") + var mangaListData mangaListRaw + data, err := c.requestHandler(endpoint, "GET") + if err != nil { + return userMangaList, false, err + } json.Unmarshal([]byte(data), &mangaListData) - // set MyListStatus for each element and add it to array - var mangas []Manga - for _, element := range mangaListData.Data { - a := element.Manga - a.ListStatus = element.ListStatus + nextPageExists := mangaListData.Paging.NextPage != "" - mangas = append(mangas, a) - } + // set MyListStatus for each element and add it to slice + for _, element := range mangaListData.Data { + m := element.Manga + m.ListStatus = element.ListStatus - // finally create AnimeList - userMangaList = MangaList { - Mangas: mangas, - Paging: mangaListData.Paging, + userMangaList = append(userMangaList, m) } - return userMangaList, nil + return userMangaList, nextPageExists, nil } diff --git a/user/manga/mangalist.structs.go b/user/manga/mangalist.structs.go index 0ea7d70..d7e5352 100644 --- a/user/manga/mangalist.structs.go +++ b/user/manga/mangalist.structs.go @@ -17,23 +17,18 @@ package manga import ( - "github.com/MikunoNaka/MAL2Go/util" "github.com/MikunoNaka/MAL2Go/manga" ) -type Manga manga.Manga - -type MangaListRaw struct { +type mangaListRaw struct { Data []struct { - Manga Manga `json:"node"` + Manga manga.Manga `json:"node"` ListStatus manga.ListStatus `json:"list_status"` - } `json:"data"` - Paging util.ListPaging `json:"paging"` -} - -type MangaList struct { - Mangas []Manga - Paging util.ListPaging + } `json:"data"` + Paging struct { + NextPage string `json:"next"` + PrevPage string `json:"previous"` + } `json:"paging"` } type UpdateMangaData struct { @@ -44,7 +39,6 @@ type UpdateMangaData struct { ChaptersRead int Priority int TimesReread int - // NOTE: idk what RereadValue is RereadValue int Tags string Comments string diff --git a/user/manga/request_handler.go b/user/manga/request_handler.go index ff2b0df..0258b38 100644 --- a/user/manga/request_handler.go +++ b/user/manga/request_handler.go @@ -16,22 +16,32 @@ package manga import ( - "encoding/json" - "io/ioutil" - "log" - "net/http" - "net/url" - "strconv" - "strings" + "encoding/json" + "io/ioutil" + "log" + "net/http" + "net/url" + "strconv" + "strings" + "errors" + "github.com/MikunoNaka/MAL2Go/util" ) -type serverResponse struct { - Message string - Error string +type UpdateResponse struct { + Status string `json:"status"` + Score int `json:"score"` + VolumesRead int `json:"num_volumes_read"` + ChaptersRead int `json:"num_chapters_read"` + IsRereading bool `json:"is_rereading"` + Priority string `json:"priority"` + TimesReread string `json:"num_times_reread"` + RereadValue string `json:"reread_value"` + Tags string `json:"tags"` + Comments string `json:"string"` } // Handles HTTP request with your OAuth token as a Header -func (c Client) requestHandler(endpoint, method string) string { +func (c Client) requestHandler(endpoint, method string) (string, error) { // generate request req, err := http.NewRequest(method, endpoint, nil) if err != nil { @@ -52,16 +62,23 @@ func (c Client) requestHandler(endpoint, method string) string { log.Fatal(err) } + // error handling (if API returns error) + var errMsg util.APIError + json.Unmarshal(body, &errMsg) + if errMsg.Err != "" { + return string(body), errors.New(errMsg.Err + " " + errMsg.Msg) + } + // for DeleteAnime, its endpoint returns null data if method == "DELETE" { - return strconv.Itoa(res.StatusCode) + return strconv.Itoa(res.StatusCode), nil } - return string(body) + return string(body), nil } // for PUT requests (used for updating anime) -func (c Client) putRequestHandler(endpoint string, params url.Values) serverResponse { +func (c Client) putRequestHandler(endpoint string, params url.Values) (UpdateResponse, error) { paramsEncoded := params.Encode() // generate request @@ -87,10 +104,15 @@ func (c Client) putRequestHandler(endpoint string, params url.Values) serverResp log.Fatal(err) } - // TODO: there are other serverResponses. Add them - // server response, ie message / error - var resp serverResponse + // error handling (if API returns error) + var errMsg util.APIError + json.Unmarshal(body, &errMsg) + if errMsg.Err != "" { + return UpdateResponse{}, errors.New(errMsg.Err + " " + errMsg.Msg) + } + + var resp UpdateResponse json.Unmarshal(body, &resp) - return resp + return resp, nil } diff --git a/user/manga/update_mangalist.go b/user/manga/update_mangalist.go index 2fbbe48..b60bfd0 100644 --- a/user/manga/update_mangalist.go +++ b/user/manga/update_mangalist.go @@ -18,8 +18,8 @@ package manga import ( e "github.com/MikunoNaka/MAL2Go/errhandlers" "fmt" - "net/url" - "strconv" + "net/url" + "strconv" ) // generate the endpoint url with the manga id @@ -28,12 +28,12 @@ func endpointGenerator(id int) string { } // update just an manga's status -func (c Client)SetStatus(id int, status string) (serverResponse, error) { +func (c Client)SetStatus(id int, status string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified list status is valid if !e.IsValidMangaListStatus(status) { - return serverResponse{}, e.InvalidStatusError + return UpdateResponse{}, e.InvalidStatusError } // data to be sent to the server @@ -41,11 +41,11 @@ func (c Client)SetStatus(id int, status string) (serverResponse, error) { params.Set("status", status) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's num of volumes read -func (c Client)SetVolumesRead(id int, volumes int) (serverResponse, error) { +func (c Client)SetVolumesRead(id int, volumes int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -53,11 +53,11 @@ func (c Client)SetVolumesRead(id int, volumes int) (serverResponse, error) { params.Set("num_volumes_read", strconv.Itoa(volumes)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's num of chapters read -func (c Client)SetChaptersRead(id int, chapters int) (serverResponse, error) { +func (c Client)SetChaptersRead(id int, chapters int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -65,11 +65,11 @@ func (c Client)SetChaptersRead(id int, chapters int) (serverResponse, error) { params.Set("num_chapters_read", strconv.Itoa(chapters)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's rereading status -func (c Client)SetIsRereading(id int, isRereading bool) (serverResponse, error) { +func (c Client)SetIsRereading(id int, isRereading bool) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -77,16 +77,16 @@ func (c Client)SetIsRereading(id int, isRereading bool) (serverResponse, error) params.Set("is_rereading", strconv.FormatBool(isRereading)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just the manga's score -func (c Client)SetScore(id int, score int) (serverResponse, error) { +func (c Client)SetScore(id int, score int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified score is valid if !e.IsValidScore(score) { - return serverResponse{}, e.InvalidScoreError + return UpdateResponse{}, e.InvalidScoreError } // data to be sent to the server @@ -94,16 +94,16 @@ func (c Client)SetScore(id int, score int) (serverResponse, error) { params.Set("score", strconv.Itoa(score)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's priority -func (c Client)SetPriority(id int, priority int) (serverResponse, error) { +func (c Client)SetPriority(id int, priority int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified priority is valid if !e.IsValidPriority(priority) { - return serverResponse{}, e.InvalidPriorityError + return UpdateResponse{}, e.InvalidPriorityError } // data to be sent to the server @@ -111,16 +111,16 @@ func (c Client)SetPriority(id int, priority int) (serverResponse, error) { params.Set("priority", strconv.Itoa(priority)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's reread value -func (c Client)SetRereadValue(id int, rereadValue int) (serverResponse, error) { +func (c Client)SetRereadValue(id int, rereadValue int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified reread value is valid if !e.IsValidRewatchValue(rereadValue) { - return serverResponse{}, e.InvalidRereadValueError + return UpdateResponse{}, e.InvalidRereadValueError } // data to be sent to the server @@ -128,11 +128,11 @@ func (c Client)SetRereadValue(id int, rereadValue int) (serverResponse, error) { params.Set("reread_value", strconv.Itoa(rereadValue)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's reread count -func (c Client)SetRereadCount(id int, rereadCount int) (serverResponse, error) { +func (c Client)SetRereadCount(id int, rereadCount int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -140,11 +140,11 @@ func (c Client)SetRereadCount(id int, rereadCount int) (serverResponse, error) { params.Set("num_times_reread", strconv.Itoa(rereadCount)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's tags -func (c Client)UpdateTags(id int, tags string) (serverResponse, error) { +func (c Client)UpdateTags(id int, tags string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -152,11 +152,11 @@ func (c Client)UpdateTags(id int, tags string) (serverResponse, error) { params.Set("tags", tags) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just a manga's comments -func (c Client)UpdateComments(id int, comments string) (serverResponse, error) { +func (c Client)UpdateComments(id int, comments string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -164,34 +164,34 @@ func (c Client)UpdateComments(id int, comments string) (serverResponse, error) { params.Set("comments", comments) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } /* NOTE: This will overwrite everything * i won't use it.. but it's pretty flexible * so this will stay here */ // Update/Add a manga to user's manga list -func (c Client)UpdateManga(id int, data UpdateMangaData) (serverResponse, error) { +func (c Client)UpdateManga(id int, data UpdateMangaData) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified list status is valid if !e.IsValidMangaListStatus(data.Status) { - return serverResponse{}, e.InvalidStatusError + return UpdateResponse{}, e.InvalidStatusError } // checks if specified score is valid if !e.IsValidScore(data.Score) { - return serverResponse{}, e.InvalidScoreError + return UpdateResponse{}, e.InvalidScoreError } // checks if specified priority is valid if !e.IsValidPriority(data.Priority) { - return serverResponse{}, e.InvalidPriorityError + return UpdateResponse{}, e.InvalidPriorityError } // checks if specified reread value is valid if !e.IsValidRewatchValue(data.RereadValue) { - return serverResponse{}, e.InvalidRereadValueError + return UpdateResponse{}, e.InvalidRereadValueError } params := url.Values{} @@ -209,6 +209,6 @@ func (c Client)UpdateManga(id int, data UpdateMangaData) (serverResponse, error) params.Set("comments", data.Comments) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } -- cgit v1.2.3