aboutsummaryrefslogtreecommitdiff
path: root/user/anime
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-24 22:05:32 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-24 22:05:32 +0530
commit10499ad3cf8db85a5c5ebd8112415d17a727c2ec (patch)
tree85b8dfdf8d419fa2e7c8eb53e81ad73551b704e5 /user/anime
parent314d9bf6cad4bebec431a217c23016680c56179b (diff)
added fields support for GetAnimeList
Diffstat (limited to 'user/anime')
-rw-r--r--user/anime/animelist.go30
1 files changed, 26 insertions, 4 deletions
diff --git a/user/anime/animelist.go b/user/anime/animelist.go
index f9ddff5..f6d9965 100644
--- a/user/anime/animelist.go
+++ b/user/anime/animelist.go
@@ -23,6 +23,7 @@ import (
"errors"
a "github.com/MikunoNaka/MAL2Go/anime"
e "github.com/MikunoNaka/MAL2Go/errhandlers"
+ u "github.com/MikunoNaka/MAL2Go/util"
)
const BASE_URL string = "https://api.myanimelist.net/v2"
@@ -37,7 +38,7 @@ func (c Client)DeleteAnime(id int) string {
}
// Get authenticated user's anime list
-func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.AnimeList, error){
+func (c Client) GetAnimeList(user, status, sort string, limit, offset int, fields []string) (a.AnimeList, error){
var userAnimeList a.AnimeList
// error handling for limit
limitErr := e.LimitErrHandler(limit, maxListLimit)
@@ -45,6 +46,15 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.An
return userAnimeList, limitErr
}
+ // handle all the errors for the fields
+ fields, err := e.FieldsErrHandler(fields)
+ if err != nil {
+ return userAnimeList, err
+ }
+
+ // append "list_status" field only used by this func.
+ fields = append(fields, "list_status")
+
// checks if valid sort is specified
if !e.IsValidListSort(sort) {
return userAnimeList, errors.New(fmt.Sprintf("GetAnimeList: Invalid sort specified: \"%s\"", sort))
@@ -60,14 +70,26 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.An
user = "@me"
}
- // if status is "" it returns all anime
var endpoint string
+ // if status is "" it returns all anime
if status == "" {
- endpoint = BASE_URL + "/users/" + user + "/animelist?sort=" + sort + "&limit=" + strconv.Itoa(limit) + "&offset=" + strconv.Itoa(offset)
+ endpoint, _ = u.UrlGenerator(
+ BASE_URL + "/users/" + user + "/animelist",
+ []string{"sort", "limit", "offset", "fields"},
+ [][]string{{sort}, {strconv.Itoa(limit)}, {strconv.Itoa(offset)}, fields},
+ true,
+ )
} else {
- endpoint = BASE_URL + "/users/" + user + "/animelist?status=" + status + "&sort=" + sort + "&limit=" + strconv.Itoa(limit) + "&offset=" + strconv.Itoa(offset)
+ // status gets included if specified
+ endpoint, _ = u.UrlGenerator(
+ BASE_URL + "/users/" + user + "/animelist",
+ []string{"status", "sort", "limit", "offset", "fields"},
+ [][]string{{status}, {sort}, {strconv.Itoa(limit)}, {strconv.Itoa(offset)}, fields},
+ true,
+ )
}
+
// get data from API
var animeListData AnimeListRaw
data := c.requestHandler(endpoint, "GET")