This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.go
83 lines (75 loc) · 2.46 KB
/
character.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
package parser
import (
"net/http"
"github.com/rl404/go-malscraper/errors"
"github.com/rl404/go-malscraper/model"
"github.com/rl404/go-malscraper/pkg/utils"
)
// GetCharacter to get character details.
func (p *Parser) GetCharacter(id int) (*model.Character, int, error) {
doc, code, err := p.getDoc(utils.BuildURL(malURL, "character", id), "#contentWrapper")
if err != nil {
return nil, code, err
}
d := p.character.GetDetails(doc)
if d == nil {
return nil, http.StatusNotFound, errors.ErrInvalidID
}
return d, http.StatusOK, nil
}
// GetCharacterArticle to get character featured article list.
func (p *Parser) GetCharacterArticle(id int) ([]model.ArticleItem, int, error) {
doc, code, err := p.getDoc(utils.BuildURL(malURL, "character", id, "a", "featured"), "#content")
if err != nil {
return nil, code, err
}
d := p.character.GetArticle(doc)
if d == nil {
return nil, http.StatusNotFound, errors.ErrInvalidID
}
return d, http.StatusOK, nil
}
// GetCharacterOgraphy to get character animeography/mangaography list.
func (p *Parser) GetCharacterOgraphy(t string, id int) ([]model.Role, int, error) {
doc, code, err := p.getDoc(utils.BuildURL(malURL, "character", id), "#contentWrapper")
if err != nil {
return nil, code, err
}
d := p.character.GetOgraphy(doc, t)
if d == nil {
return nil, http.StatusNotFound, errors.ErrInvalidID
}
return d, http.StatusOK, nil
}
// GetCharacterPicture to get character picture list.
func (p *Parser) GetCharacterPicture(id int) ([]string, int, error) {
doc, code, err := p.getDoc(utils.BuildURL(malURL, "character", id, "a", "pictures"), "#content")
if err != nil {
return nil, code, err
}
return p.character.GetPictures(doc), http.StatusOK, nil
}
// GetCharacterClub to get character club list.
func (p *Parser) GetCharacterClub(id int) ([]model.ClubItem, int, error) {
doc, code, err := p.getDoc(utils.BuildURL(malURL, "character", id, "a", "clubs"), "#content")
if err != nil {
return nil, code, err
}
d := p.character.GetClubs(doc)
if d == nil {
return nil, http.StatusNotFound, errors.ErrInvalidID
}
return d, http.StatusOK, nil
}
// GetCharacterVA to get character voice actor list.
func (p *Parser) GetCharacterVA(id int) ([]model.Role, int, error) {
doc, code, err := p.getDoc(utils.BuildURL(malURL, "character", id), "#contentWrapper")
if err != nil {
return nil, code, err
}
d := p.character.GetVA(doc)
if d == nil {
return nil, http.StatusNotFound, errors.ErrInvalidID
}
return d, http.StatusOK, nil
}