aboutsummaryrefslogtreecommitdiff
path: root/anime
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-01-31 12:21:19 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-01-31 12:21:19 +0530
commit97a02c2d9b309ae7e6ed2c0b807ed02913ded98c (patch)
tree070f670a182dce85690a4029e1c32ef5a8033f91 /anime
parentcaa17299f9f70addca805eb94a8174efcdda6985 (diff)
Added error handling for if limit is exceeded
Diffstat (limited to 'anime')
-rw-r--r--anime/anime.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/anime/anime.go b/anime/anime.go
index 1439221..5d207ea 100644
--- a/anime/anime.go
+++ b/anime/anime.go
@@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"log"
+ "math"
"strconv"
)
@@ -75,16 +76,25 @@ func GetAnimeById(token string, animeId int, fields []string) (Anime, error) {
}
// Ranking is a list of anime sorted by their rank
-func GetAnimeRanking(token string, rankingType string, limit int) (AnimeRanking, error) {
+func GetAnimeRanking(token string, rankingType string, limit int, offset int) (AnimeRanking, error) {
var animeRanking AnimeRanking
+
+ // if limit exceeds what MAL supports
+ if limit > 500 {
+ return animeRanking, errors.New(fmt.Sprintf("GetAnimeRanking: Limit too high(%d). Max limit is 500", limit))
+ } else if offset > 499 {
+ return animeRanking, errors.New(fmt.Sprintf("GetAnimeRanking: Offset too high(%d). Max offset for mal2go is 499", offset))
+ }
+
+ // if ranking type is invalid
if !isValidRankingType(rankingType) {
return animeRanking, errors.New(fmt.Sprintf("GetAnimeRanking: Invalid ranking type specified: \"%s\"", rankingType))
}
endpoint, _ := urlGenerator(
BASE_URL + "/ranking",
- []string{"ranking_type", "limit"},
- [][]string{{rankingType}, {strconv.Itoa(limit)}},
+ []string{"ranking_type", "limit", "offset"},
+ [][]string{{rankingType}, {strconv.Itoa(limit)}, {strconv.Itoa(offset)}},
true,
)