diff options
author | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-02-28 13:06:16 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@protonmail.ch> | 2022-02-28 13:06:16 +0530 |
commit | 95b8ab702708538ccaf26efd141b448148ac6d6d (patch) | |
tree | 62d41395d8d45f9045c64974f7dcf7c15b7755ef /manga | |
parent | 2bf5302f9a653f46f7932329fd03aa3688afc35b (diff) |
documented manga package and fixed errors in anime README
Diffstat (limited to 'manga')
-rw-r--r-- | manga/README.md | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/manga/README.md b/manga/README.md index 74a97a3..f7bf690 100644 --- a/manga/README.md +++ b/manga/README.md @@ -1,5 +1,7 @@ # MAL2Go/manga -MAL2Go `manga` package has functionality related to getting data about anime. +MAL2Go `manga` package has functionality related to getting data about manga. + +To *update* manga status (score, status, etc) refer to [`user/manga`](../user/manga) package. ## Installation In a terminal, run @@ -24,14 +26,85 @@ myClient := manga.Client { - ### Searching for a manga ``` go +searchString := "kanojo okarishimasu" // your search string here + +// max amount of results to pull. Max is 500 +limit := 10 + +// if the offset is 2 it will skip the first 2 results, then pull the next 10 +offset := 0 + +// the API by default only returns some basic data +// you can specify some fields as a []string slice. +// it will return the default fields even if they aren't specified +var DefaultMangaFields []string = []string{ + "id", "title", "main_picture", + "alternative_titles", "start_date", "end_date", + "synopsis", "mean", "rank", + "popularity", "num_list_users", "num_scoring_users", + "nsfw", "created_at", "media_type", + "status", "genres", "my_list_status", + "num_volumes", "num_chapters", "authors", + "pictures", "background", "related_anime", + "related_manga", "recommendations", "serialization", +} // for all default fields fields := []string{} will also work + +// finally making the API request +searchResults, err := myClient.SearchManga(searchString, limit, offset, fields) + +// searchResults.Mangas is a list of all the Mangas returned by the API as search results +// print list of the search results +for _, manga := range searchResults.Mangas { + fmt.Println(manga.Title) +} + +// results have page numbers +fmt.Println(searchResults.Paging.NextPage, searchResults.Paging.PrevPage) ``` - ### Getting a manga's info +Each manga on MyAnimeList has a unique ID, which you need to find it + ``` go +mangaId := 108407 +fields := []string{} // pull every field + +manga, err := myClient.GetMangaById(mangaId, fields) +if err != nil { + fmt.Println(err) +} + +fmt.Println(manga.Title, manga.MeanScore, manga.ListStatus.Status) ``` - ### Get manga ranking +Ranking is a list of mangas sorted by their rank + +Possible ranking types are: +- `all` +- `manga` +- `novels` +- `oneshots` +- `doujin` +- `manhwa` +- `manhua` +- `bypopularity` +- `favorite` + ``` go +rankingType := "favorite" +limit, offset := 10, 0 +fields := []string{"title"} + +ranking, err := myClient.GetMangaRanking(rankingType, limit, offset, fields) + +// loop over the array mangas returned by the API +for _, manga := range ranking.Mangas { + fmt.Printf("Title: %s, Rank Number: %d", manga.Title, manga.RankNum) +} + +// ranking lists have page numbers +fmt.Println(ranking.Paging.NextPage, ranking.Paging.PrevPage) ``` ## Structure @@ -41,5 +114,15 @@ Contains all the exported functions for pulling data from the API. - [manga.structs.go](anime.structs.go) Contains all the structs representing a manga entry on MyAnimeList. +- [ranking.structs.go](ranking.structs.go) +Representing anime ranking data both in the form returned +by the API and the formatted form to be returned by this package. + +- [search.structs.go](search.structs.go) +Representing search results. + +- [request_handler.go](request_handler.go) +Responsible for making HTTP requests. + - [client.go](client.go) The Client for accessing the API with this package. |