-
Notifications
You must be signed in to change notification settings - Fork 1
/
novel.go
87 lines (79 loc) · 2.07 KB
/
novel.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
package pixiv
import (
"net/url"
"strconv"
)
// NovelService does ops with novels.
type NovelService service
// AddHistory adds novel browsing history.
func (s *NovelService) AddHistory(novelIDs []int) error {
return s.api.postWithValues(nil,
s.api.BaseURL+"/v2/user/browsing-history/novel/add",
nil, url.Values{
"novel_ids[]": intsToStrings(novelIDs),
}, "novel: add history",
)
}
// AddBookmark adds novel to public or private bookmark.
func (s *NovelService) AddBookmark(novelID int, restrict Restrict, opts *AddBookmarkOptions) error {
return s.api.postWithValues(nil,
s.api.BaseURL+"/v2/novel/bookmark/add",
opts, url.Values{
"novel_id": {strconv.Itoa(novelID)},
"restrict": {string(restrict)},
}, "novel: bookmark add",
)
}
// DeleteBookmark deletes novel from public and private bookmark
func (s *NovelService) DeleteBookmark(novelID int) error {
return s.api.postWithValues(nil,
s.api.BaseURL+"/v1/novel/bookmark/delete",
nil, url.Values{
"novel_id": {strconv.Itoa(novelID)},
}, "novel: bookmark add",
)
}
// Text fetches text of the novel.
func (s *NovelService) Text(novelID int) (*RespNovelText, error) {
r := &RespNovelText{}
err := s.api.getWithValues(r,
s.api.BaseURL+"/v1/novel/text",
nil, url.Values{
"novel_id": {strconv.Itoa(novelID)},
}, "novel: text",
)
if err != nil {
return nil, err
}
return r, nil
}
// Comments fetches comments of the novel.
func (s *NovelService) Comments(novelID int) (*RespComments, error) {
r := &RespComments{api: s.api}
err := s.api.getWithValues(r,
s.api.BaseURL+"/v2/novel/comments",
nil, url.Values{
"novel_id": {strconv.Itoa(novelID)},
}, "novel: comments",
)
if err != nil {
return nil, err
}
return r, nil
}
// Detail fetches novel's detail by it's id.
//
// The API seems not used in Pixiv's app.
func (s *NovelService) Detail(novelID int) (*RespNovel, error) {
r := &RespNovel{}
err := s.api.getWithValues(r,
s.api.BaseURL+"/v2/novel/detail",
nil, url.Values{
"novel_id": {strconv.Itoa(novelID)},
}, "novel: detail",
)
if err != nil {
return nil, err
}
return r, nil
}