aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <bokuwakanojogahoshii@yahoo.com>2022-02-21 08:17:20 +0000
committerGitHub <noreply@github.com>2022-02-21 08:17:20 +0000
commit8c685067611d829e5fb8eeaaba48508d15cd4dde (patch)
treea1ddcf1469d563d26d5c23afe8a58fecb3dad0c4
parentdbd642c32b1d2075cc5d0d00e29433753b742d13 (diff)
parent108f06aedec8834a314ed884f2795758a82fdb68 (diff)
Merge pull request #5 from MikunoNaka/offset-limit-fix
Removed any max limit for offset argument, since MAL doesn't even support that
-rw-r--r--anime/anime.go32
-rw-r--r--errhandlers/errhandlers.go7
-rw-r--r--user/anime/animelist.go7
3 files changed, 22 insertions, 24 deletions
diff --git a/anime/anime.go b/anime/anime.go
index 01dbbb5..9047033 100644
--- a/anime/anime.go
+++ b/anime/anime.go
@@ -34,10 +34,10 @@ const maxAnimeLimit int = 500
func (c Client) SearchAnime(searchString string, limit, offset int, fields []string) (AnimeSearch, error) {
var searchResults AnimeSearch
- // error handling for limit and offset
- limitsErr := e.LimitsErrHandler(limit, offset, maxAnimeLimit)
- if limitsErr != nil {
- return searchResults, limitsErr
+ // error handling for limit
+ limitErr := e.LimitErrHandler(limit, maxAnimeLimit)
+ if limitErr != nil {
+ return searchResults, limitErr
}
// handle all the errors for the fields
@@ -104,10 +104,10 @@ func (c Client) GetAnimeById(animeId int, fields []string) (Anime, error) {
func (c Client) GetAnimeRanking(rankingType string, limit, offset int, fields []string) (AnimeRanking, error) {
var animeRanking AnimeRanking
- // error handling for limit and offset
- limitsErr := e.LimitsErrHandler(limit, offset, maxAnimeLimit)
- if limitsErr != nil {
- return animeRanking, limitsErr
+ // error handling for limit
+ limitErr := e.LimitErrHandler(limit, maxAnimeLimit)
+ if limitErr != nil {
+ return animeRanking, limitErr
}
// handle all the errors for the fields
@@ -161,10 +161,10 @@ func (c Client) GetAnimeRanking(rankingType string, limit, offset int, fields []
func (c Client) GetSeasonalAnime(year, season, sort string, limit, offset int, fields []string) (SeasonalAnime, error) {
var seasonalAnime SeasonalAnime
- // error handling for limit and offset
- limitsErr := e.LimitsErrHandler(limit, offset, maxAnimeLimit)
- if limitsErr != nil {
- return seasonalAnime, limitsErr
+ // error handling for limit
+ limitErr := e.LimitErrHandler(limit, maxAnimeLimit)
+ if limitErr != nil {
+ return seasonalAnime, limitErr
}
// handle all the errors for the fields
@@ -215,10 +215,10 @@ func (c Client) GetSeasonalAnime(year, season, sort string, limit, offset int, f
func (c Client) GetSuggestedAnime(limit, offset int, fields []string) (SuggestedAnime, error){
var suggestedAnime SuggestedAnime
- // error handling for limit and offset
- limitsErr := e.LimitsErrHandler(limit, offset, maxAnimeLimit)
- if limitsErr != nil {
- return suggestedAnime, limitsErr
+ // error handling for limit
+ limitErr := e.LimitErrHandler(limit, maxAnimeLimit)
+ if limitErr != nil {
+ return suggestedAnime, limitErr
}
// handle all the errors for the fields
diff --git a/errhandlers/errhandlers.go b/errhandlers/errhandlers.go
index 59a45ae..14c1d33 100644
--- a/errhandlers/errhandlers.go
+++ b/errhandlers/errhandlers.go
@@ -41,13 +41,10 @@ func FieldsErrHandler(fields []string) ([]string, error) {
}
// if limit or error specified are above the limit
-func LimitsErrHandler(limit, offset, maxLimit int) error {
- maxOffset := maxLimit - limit
+func LimitErrHandler(limit, maxLimit int) error {
if limit > maxLimit {
return errors.New(fmt.Sprintf("InvalidLimitError: Limit specified too high (%d > %d).", limit, maxLimit))
- } else if offset > maxOffset {
- return errors.New(fmt.Sprintf("InvalidOffsetError: Offset specified too high (%d > %d).", offset, maxOffset))
- }
+ }
// return nil if no error
return nil
}
diff --git a/user/anime/animelist.go b/user/anime/animelist.go
index 01e0a0e..6516184 100644
--- a/user/anime/animelist.go
+++ b/user/anime/animelist.go
@@ -39,9 +39,10 @@ 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){
var userAnimeList a.AnimeList
- // error handling for limit and offset
- limitsErr := e.LimitsErrHandler(limit, offset, maxListLimit)
- if limitsErr != nil { return userAnimeList, limitsErr
+ // error handling for limit
+ limitErr := e.LimitErrHandler(limit, maxListLimit)
+ if limitErr != nil {
+ return userAnimeList, limitErr
}
// checks if valid sort is specified