-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreview.go
More file actions
65 lines (59 loc) · 1.68 KB
/
Copy pathreview.go
File metadata and controls
65 lines (59 loc) · 1.68 KB
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
// review.go
package jikan
import (
"context"
"fmt"
"net/http"
"net/url"
"strconv"
)
type ReviewService struct {
c *Client
}
type Review struct {
MalID int `json:"mal_id"`
Score int `json:"score"`
Reactions struct {
Overall int `json:"overall"`
} `json:"reactions"`
Date string `json:"date"`
Review string `json:"review"`
IsSpoiler bool `json:"is_spoiler"`
Entry Resource `json:"entry"`
User struct {
Username string `json:"username"`
} `json:"user"`
}
func (s *ReviewService) Recent(ctx context.Context, page int) ([]Review, *Pagination, error) {
q := url.Values{"page": {strconv.Itoa(page)}}
var r struct {
Data []Review `json:"data"`
Pagination Pagination `json:"pagination"`
}
if err := s.c.Do(ctx, http.MethodGet, "/reviews/recent", q, &r); err != nil {
return nil, nil, err
}
return r.Data, &r.Pagination, nil
}
func (s *ReviewService) ForAnime(ctx context.Context, id ID, page int) ([]Review, *Pagination, error) {
q := url.Values{"page": {strconv.Itoa(page)}}
var r struct {
Data []Review `json:"data"`
Pagination Pagination `json:"pagination"`
}
if err := s.c.Do(ctx, http.MethodGet, fmt.Sprintf("/anime/%d/reviews", id), q, &r); err != nil {
return nil, nil, err
}
return r.Data, &r.Pagination, nil
}
func (s *ReviewService) ForManga(ctx context.Context, id ID, page int) ([]Review, *Pagination, error) {
q := url.Values{"page": {strconv.Itoa(page)}}
var r struct {
Data []Review `json:"data"`
Pagination Pagination `json:"pagination"`
}
if err := s.c.Do(ctx, http.MethodGet, fmt.Sprintf("/manga/%d/reviews", id), q, &r); err != nil {
return nil, nil, err
}
return r.Data, &r.Pagination, nil
}