aboutsummaryrefslogtreecommitdiff
path: root/manga/manga.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-23 21:04:55 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-23 21:04:55 +0530
commit7a68abbc9e492934cf4170d5a0ff52a456fe92bd (patch)
tree1347f0f474a400d43eea29ad2d48d25d3b4ea620 /manga/manga.go
parenta92af9a2dd6ac31db2024bdaab06df2da2d4face (diff)
added second endpoint: GetMangaById
Diffstat (limited to 'manga/manga.go')
-rw-r--r--manga/manga.go47
1 files changed, 22 insertions, 25 deletions
diff --git a/manga/manga.go b/manga/manga.go
index dd79db2..2bbc7d4 100644
--- a/manga/manga.go
+++ b/manga/manga.go
@@ -74,31 +74,28 @@ func (c Client) SearchManga(searchString string, limit, offset int, fields []str
return searchResults, nil
}
-// // Each anime has its own ID on MAL
-// func (c Client) GetAnimeById(animeId int, fields []string) (Anime, error) {
-// var anime Anime
-//
-// // handle all the errors for the fields
-// fields, err := e.FieldsErrHandler(fields)
-// if err != nil {
-// return anime, err
-// }
-//
-// endpoint, _ := u.UrlGenerator(
-// BASE_URL + "/" + strconv.Itoa(animeId),
-// []string{"fields"},
-// /* it seems to still return all fields from the API.
-// * this might be an issue with MAL itself
-// * TODO: look into this */
-// [][]string{fields},
-// true,
-// )
-//
-// data := c.requestHandler(endpoint)
-// json.Unmarshal([]byte(data), &anime)
-//
-// return anime, nil
-// }
+// Each manga has its own ID on MAL
+func (c Client) GetMangaById(mangaId int, fields []string) (Manga, error) {
+ var manga Manga
+
+ // handle all the errors for the fields
+ fields, err := e.FieldsErrHandler(fields)
+ if err != nil {
+ return manga, err
+ }
+
+ endpoint, _ := u.UrlGenerator(
+ BASE_URL + "/" + strconv.Itoa(mangaId),
+ []string{"fields"},
+ [][]string{fields},
+ true,
+ )
+
+ data := c.requestHandler(endpoint)
+ json.Unmarshal([]byte(data), &manga)
+
+ return manga, nil
+}
// // Ranking is a list of anime sorted by their rank
// func (c Client) GetAnimeRanking(rankingType string, limit, offset int, fields []string) (AnimeRanking, error) {