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 | |
parent | 2bf5302f9a653f46f7932329fd03aa3688afc35b (diff) |
documented manga package and fixed errors in anime README
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | anime/README.md | 11 | ||||
-rw-r--r-- | manga/README.md | 85 | ||||
-rw-r--r-- | user/anime/README.md | 7 | ||||
-rw-r--r-- | user/manga/README.md | 194 | ||||
-rw-r--r-- | user/manga/update_mangalist.go | 12 |
6 files changed, 296 insertions, 17 deletions
@@ -9,6 +9,7 @@ go get github.com/MikunoNaka/MAL2Go/anime go get github.com/MikunoNaka/MAL2Go/manga go get github.com/MikunoNaka/MAL2Go/user go get github.com/MikunoNaka/MAL2Go/user/anime +go get github.com/MikunoNaka/MAL2Go/user/manga ``` To install the packages you'd usually need. To find out more about what each package does, refer to [Package Structure](#Package-Structure) @@ -27,6 +28,9 @@ has the functionality for getting user data and updating information. [user/animelist](user/anime) package has the functionality to update the authenticated user's anime list status, etc. +[user/animelist](user/anime) package +has the functionality to update the authenticated user's manga list status, etc. + [util](util) package has some code used by multiple packages that I think don't belong particularly to one single package diff --git a/anime/README.md b/anime/README.md index 5ea7922..72c92b7 100644 --- a/anime/README.md +++ b/anime/README.md @@ -95,16 +95,13 @@ Possible ranking types are: ``` go rankingType := "favorite" limit, offset := 10, 0 -fields := []string{"title", "media_type"} +fields := []string{"title"} ranking, err := myClient.GetAnimeRanking(rankingType, limit, offset, fields) -// loop over the array of "titles" returned by the API -for _, rankingAnime := range ranking.Titles { - anime := rankingAnime.Anime - rankNum := rankingAnime.RankNum - - fmt.Printf("Title: %s, Rank Number: %d", anime.Title, rankNum) +// loop over the array of animes returned by the API +for _, anime := range ranking.Animes { + fmt.Printf("Title: %s, Rank Number: %d", anime.Title, anime.RankNum) } // ranking lists have page numbers 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. diff --git a/user/anime/README.md b/user/anime/README.md index e2194e0..80ce4e6 100644 --- a/user/anime/README.md +++ b/user/anime/README.md @@ -1,4 +1,4 @@ -# MAL2Go/user +# MAL2Go/user/anime MAL2Go `user/anime` package has functionality related to updating the user's anime list. To *get* anime data, refer to the [`anime`](../../anime) package. @@ -39,14 +39,13 @@ fmt.Println(resp) - ### Get user's anime list Possible statuses are: -- `` - `watching` - `completed` - `on_hold` - `dropped` - `plan_to_watch` -Leaving blank (``) gets all the anime +Leaving blank (`""`) gets all the anime Possible sorts are: - `list_score` @@ -55,7 +54,7 @@ Possible sorts are: - `anime_start_date` - `anime_id` (beta) -Leaving user blank or as `"@me"` returns the authenticated user's list +Leaving user blank (`""`) or as `"@me"` returns the authenticated user's list ``` go user := "0ZeroTsu" diff --git a/user/manga/README.md b/user/manga/README.md index 1a6c636..db4ed5c 100644 --- a/user/manga/README.md +++ b/user/manga/README.md @@ -1,19 +1,203 @@ -# MAL2Go/user -MAL2Go `user/anime` package has functionality related to updating the user's anime list. +# MAL2Go/user/manga +MAL2Go `user/manga` package has functionality related to updating the user's manga list. + +To *get* anime data, refer to the [`manga`](../../manga) package. + +**There are multiple possible server responses and errors currently haven't been implemented yet.** + +## Installation +In a terminal, run +``` fish +go get "github.com/MikunoNaka/MAL2Go/user/manga" +``` ## Usage Firstly, import this package and instanciate the client. ``` go import ( - "github.com/MikunoNaka/MAL2Go/user/anime" + "github.com/MikunoNaka/MAL2Go/user/manga" ) ``` Now instanciate with ``` go -myClient := anime.Client { +myClient := manga.Client { AuthToken: "Bearer " + yourTokenHere, } ``` -**More to be added later** +- ### Delete a manga from user's anime list +``` go +mangaId := 108407 // manga's ID + +resp := myClient.DeleteManga(mangaId) + +/* if manga is successfully deleted, resp is 200 + * if manga isn't in the list resp is 404 */ +fmt.Println(resp) +``` + +- ### Get user's manga list +Possible statuses are: +- `reading` +- `completed` +- `on_hold` +- `dropped` +- `plan_to_watch` + +Leaving blank (`""`) gets all the anime + +Possible sorts are: +- `list_score` +- `list_updated_at` +- `manga_title` +- `manga_start_date` +- `manga_id` (beta) + +Leaving user blank (`""`) or as `"@me"` returns the authenticated user's list + +``` go +user := "0ZeroTsu" +status := "reading" +sort := "list_score" + +limit := 1000 // max is 1000 +offset := 0 + +// fields := []string{} means get all the fields +fields := []string{"title"} + +mangaList, err := myClient.GetMangaList(user, status, sort, limit, offset, fields) +if err != nil { + fmt.Println(err) +} + +// mangaList.Mangas is an array of the mangas in the list +for _, manga := range mangaList.Mangas { + fmt.Println(manga.Title) +} + +fmt.Println(mangaList.Paging.NextPage, mangaList.Paging.PrevPage) +``` + +- ### Set a manga's status +``` go +mangaId := 108407 // manga's ID +status := "dropped" +resp, _ := myClient.SetStatus(mangaId, status) +fmt.Println(resp.Error, resp.Message) +``` + +- ### Set read volumes +``` go +mangaId := 108407 // manga's ID +volumesRead := 10 +resp, _ := myClient.SetVolumesRead(mangaId, volumesRead) +fmt.Println(resp.Error, resp.Message) +``` + +- ### Set read chapters +``` go +mangaId := 108407 // manga's ID +chaptersRead := 150 +resp, _ := myClient.SetChaptersread(mangaId, chaptersRead) +fmt.Println(resp.Error, resp.Message) +``` + +- ### Set is rereading status +``` go +mangaId := 108407 // manga's ID +isRereading := true +_, _ := myClient.SetIsRereading(mangaId, isRereading) +``` + +- ### Set a manga's score +``` go +mangaId := 108407 // manga's ID +score := 1 +_, _ := myClient.SetScore(mangaId, score) +``` + +- ### Set a manga's priority +Priority on MyAnimeList ranges from 0 to 2 +``` go +mangaId := 108407 // manga's ID +priority := 2 +_, _ := myClient.SetPriority(mangaId, priority) +``` + +- ### Set a manga's reread value +Reread value on MyAnimeList ranges from 0 to 5 +``` go +mangaId := 108407 // manga's ID +rereadValue := 4 +_, _ := myClient.SetRereadValue(mangaId, rereadValue) +``` + +- ### Set a manga's reread count +Number of times user has reread the manga. There is no limit +``` go +mangaId := 108407 // manga's ID +rereadCount := 69 +_, _ := myClient.SetRereadCount(mangaId, rereadCount) +``` + +- ### Set a manga's tags +``` go +mangaId := 108407 // manga's ID +tags := "tags" +_, _ := myClient.UpdateTags(mangaId, tags) +``` + +- ### Set a manga's comments +``` go +mangaId := 108407 // manga's ID +comments := "I hate but love this" +_, _ := myClient.UpdateComments(mangaId, comments) +``` + +- ### Update all fields of a manga +WARNING: this function can overwrite any data and set it to null +if you don't specify a value to it. + +Refrain/use it carefully to avoid data loss. + +``` go +updateData := manga.UpdateMangaData { + Status: "dropped", + IsRereading: true, + Score: 1, + VolumesRead: 10, + ChaptersRead: 150, + Priority: 2, + TimesReread: 69, + RereadValue: 4, + Tags: "tags", + Comments: "I hate but love this", +} + +mangaId := 108407 // manga's ID + +resp, err := myClient.UpdateManga(mangaId, updateData) +if err != nil { + fmt.Println(err) +} + +fmt.Println(resp.Error, resp.Message) +``` + +## Structure +- [mangalist.go](mangalist.go) +Contains the exported functions to do some basic functions with manga lists. + +- [mangalist.structs.go](mangalist.structs.go) +Contains all the structs representing mangalist data pulled from MyAnimeList. + +- [client.go](client.go) +The Client for accessing the API with this package. + +- [request_handler.go](request_handler.go) +Responsible for making HTTP requests + +- [update_mangalist.go](update_mangalist.go) +Contains all the exported functions to update a manga entry in user's mangalist. diff --git a/user/manga/update_mangalist.go b/user/manga/update_mangalist.go index cac27e8..423a919 100644 --- a/user/manga/update_mangalist.go +++ b/user/manga/update_mangalist.go @@ -45,6 +45,18 @@ func (c Client)SetStatus(id int, status string) (serverResponse, error) { return c.putRequestHandler(endpoint, params), nil } +// update just a manga's num of volumes read +func (c Client)SetVolumesRead(id int, volumes int) (serverResponse, error) { + endpoint := endpointGenerator(id) + + // data to be sent to the server + params := url.Values{} + params.Set("num_volumes_read", strconv.Itoa(volumes)) + + // make API request + return c.putRequestHandler(endpoint, params), nil +} + // update just a manga's num of chapters read func (c Client)SetChaptersRead(id int, chapters int) (serverResponse, error) { endpoint := endpointGenerator(id) |