aboutsummaryrefslogtreecommitdiff
path: root/anime/anime.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-01-31 11:25:04 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-01-31 11:25:04 +0530
commit0dd65dd062362f913b3028e07e2f0c3afaec8894 (patch)
treef94a35aa5b19886bd39f8dec0acfe34e18d723e4 /anime/anime.go
parenta835f9b0b8b714a76d8b2f9c49b84f7042ddbd6a (diff)
Added a URL Generator
Diffstat (limited to 'anime/anime.go')
-rw-r--r--anime/anime.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/anime/anime.go b/anime/anime.go
index 7e5cf70..2c23209 100644
--- a/anime/anime.go
+++ b/anime/anime.go
@@ -2,8 +2,9 @@ package anime
import (
"encoding/json"
+ "errors"
"fmt"
- "errors"
+ "strconv"
)
// Each anime has its own ID on MAL
@@ -18,13 +19,18 @@ func GetAnimeById(token string, animeId int) Anime {
}
// Ranking is a list of anime sorted by their rank
-func GetAnimeRanking(token string, rankingType string) (AnimeRanking, error) {
+func GetAnimeRanking(token string, rankingType string, limit int) (AnimeRanking, error) {
var animeRanking AnimeRanking
if !isValidRankingType(rankingType) {
return animeRanking, errors.New(fmt.Sprintf("GetAnimeRanking: Invalid Ranking Type Given (\"%s\")", rankingType))
}
- endpoint := "https://api.myanimelist.net/v2/anime/ranking?ranking_type=all&limit=4"
+ endpoint, _ := urlGenerator(
+ "https://api.myanimelist.net/v2/anime/ranking",
+ []string{"ranking_type", "limit"},
+ [][]string{{rankingType}, {strconv.Itoa(limit)}},
+ true,
+ )
// gets data from API and stores it in a struct
var rankingData RawRanking