This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
/
manga.go
68 lines (62 loc) · 2.01 KB
/
manga.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
package mangadex
import (
"context"
"encoding/json"
"fmt"
"github.com/google/go-querystring/query"
"github.com/pkg/errors"
)
// Manga contains information about a given manga.
type Manga struct {
ID int `json:"id"`
Title string `json:"title"`
AltTitles []string `json:"altTitles"`
Description string `json:"description"`
Artist []string `json:"artist"`
Author []string `json:"author"`
Publication struct {
Language string `json:"language"`
Status int `json:"status"`
Demographic int `json:"demographic"`
} `json:"publication"`
Tags []int `json:"tags"`
LastChapter string `json:"lastChapter"`
LastVolume string `json:"lastVolume"`
IsHentai bool `json:"isHentai"`
Links map[string]string `json:"links"`
Relations []struct {
ID int `json:"id"`
Title string `json:"title"`
Type int `json:"type"`
IsHentai bool `json:"isHentai"`
} `json:"relations"`
Rating struct {
Bayesian float64 `json:"bayesian"`
Mean float64 `json:"mean"`
Users int `json:"users"`
} `json:"rating"`
Views int `json:"views"`
Follows int `json:"follows"`
Comments int `json:"comments"`
LastUploaded Timestamp `json:"lastUploaded"`
MainCover string `json:"mainCover"`
}
// MangaOptions contains options that can be passed to the endpoint.
type MangaOptions struct{}
// Manga returns a manga.
func (c *Client) Manga(ctx context.Context, id int, opts *MangaOptions) (Manga, error) {
values, err := query.Values(opts)
if err != nil {
return Manga{}, errors.Wrap(err, "could not encode options")
}
raw, err := c.get(ctx, fmt.Sprintf("/manga/%d", id), values)
if err != nil {
return Manga{}, errors.Wrapf(err, "could not get manga %d", id)
}
var res Manga
if err := json.Unmarshal(raw, &res); err != nil {
return Manga{}, errors.Wrapf(err, "could not unmarshal manga %d", id)
}
return res, nil
}
func (m Manga) String() string { return m.Title }