1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# MAL2Go/manga
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
``` fish
go get "github.com/MikunoNaka/MAL2Go/v2/manga"
```
## Usage
Firstly, import this package and instanciate the client.
``` go
import (
"github.com/MikunoNaka/MAL2Go/v2/manga"
)
```
Now instanciate with
``` go
myClient := manga.Client {
AuthToken: "Bearer " + yourTokenHere,
}
```
- ### 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
- [manga.go](anime.go)
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.
|