-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtop.go
157 lines (138 loc) · 3.98 KB
/
top.go
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package jikan
import (
"fmt"
"net/url"
"strconv"
"time"
)
// TopAnime struct
type TopAnime struct {
Data []AnimeBase `json:"data"`
Pagination Pagination `json:"pagination"`
}
type TopAnimeType string
const (
TopAnimeTypeTv TopAnimeType = "tv"
TopAnimeTypeMovie TopAnimeType = "movie"
TopAnimeTypeOva TopAnimeType = "ova"
TopAnimeTypeSpecial TopAnimeType = "special"
TopAnimeTypeOna TopAnimeType = "ona"
TopAnimeTypeMusic TopAnimeType = "music"
)
type TopAnimeFilter string
const (
TopAnimeFilterAiring TopAnimeFilter = "airing"
TopAnimeFilterUpcoming TopAnimeFilter = "upcoming"
TopAnimeFilterByPopularity TopAnimeFilter = "bypopularity"
TopAnimeFilterFavorite TopAnimeFilter = "favorite"
)
// GetTopAnime returns top anime
func GetTopAnime(subType TopAnimeType, filter TopAnimeFilter, page int) (*TopAnime, error) {
res := &TopAnime{}
query := url.Values{}
query.Set("page", strconv.Itoa(page))
if subType != "" {
query.Set("type", string(subType))
}
if filter != "" {
query.Set("filter", string(filter))
}
err := urlToStruct(fmt.Sprintf("/top/anime?%s", query.Encode()), res)
if err != nil {
return nil, err
}
return res, nil
}
// TopManga struct
type TopManga struct {
Data []MangaBase `json:"data"`
Pagination Pagination `json:"pagination"`
}
type TopMangaType string
const (
TopMangaTypeManga TopMangaType = "manga"
TopMangaTypeNodel TopMangaType = "novel"
TopMangaTypeLightnovel TopMangaType = "lightnovel"
TopMangaTypeOneshot TopMangaType = "oneshot"
TopMangaTypeDoujin TopMangaType = "doujin"
TopMangaTypeManhwa TopMangaType = "manhwa"
TopMangaTypeManhua TopMangaType = "manhua"
)
type TopMangaFilter string
const (
TopMangaFilterPublishing TopMangaFilter = "publishing"
TopMangaFilterUpcoming TopMangaFilter = "upcoming"
TopMangaFilterByPopularity TopMangaFilter = "bypopularity"
TopMangaFilterFavorite TopMangaFilter = "favorite"
)
// GetTopManga returns top manga
func GetTopManga(subType TopMangaType, filter TopMangaFilter, page int) (*TopManga, error) {
res := &TopManga{}
query := url.Values{}
query.Set("page", strconv.Itoa(page))
if subType != "" {
query.Set("type", string(subType))
}
if filter != "" {
query.Set("filter", string(filter))
}
err := urlToStruct(fmt.Sprintf("/top/manga?%s", query.Encode()), res)
if err != nil {
return nil, err
}
return res, nil
}
// TopPeople struct
type TopPeople struct {
Data []PeopleBase `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetTopPeople returns top people
func GetTopPeople(page int) (*TopPeople, error) {
res := &TopPeople{}
err := urlToStruct(fmt.Sprintf("/top/people?page=%d", page), res)
if err != nil {
return nil, err
}
return res, nil
}
// TopCharacters struct
type TopCharacters struct {
Data []CharactersBase `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetTopCharacters returns top characters
func GetTopCharacters(page int) (*TopCharacters, error) {
res := &TopCharacters{}
err := urlToStruct(fmt.Sprintf("/top/characters?page=%d", page), res)
if err != nil {
return nil, err
}
return res, nil
}
// TopReviews struct
type TopReviews struct {
Data []struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
Type string `json:"type"`
Votes int `json:"votes"`
Date time.Time `json:"date"`
Review string `json:"review"`
EpisodesWatched int `json:"episodes_watched"`
Scores ScoresLong `json:"scores"`
Entry EntryTitle3 `json:"entry"`
User UserItem `json:"user"`
ChaptersRead int `json:"chapters_read"`
} `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetTopReviews returns top reviews
func GetTopReviews(page int) (*TopReviews, error) {
res := &TopReviews{}
err := urlToStruct(fmt.Sprintf("/top/reviews?page=%d", page), res)
if err != nil {
return nil, err
}
return res, nil
}