-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstudio.go
103 lines (93 loc) · 2.77 KB
/
studio.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
package verniy
import "context"
type studioResponse struct {
Data struct {
Studio Studio `json:"studio"`
} `json:"data"`
}
func (c *Client) studioQuery(params QueryParam, fields ...StudioField) string {
p := make([]string, len(fields))
for i := range fields {
p[i] = string(fields[i])
}
return FieldObject("Studio", params, p...)
}
// GetStudio to get anime list produced by the studio.
func (c *Client) GetStudio(id int, page int, perPage int, fields ...StudioField) (*Studio, error) {
return c.GetStudioWithContext(context.Background(), id, page, perPage, fields...)
}
// GetStudioWithContext to get anime list produced by the studio with context.
func (c *Client) GetStudioWithContext(ctx context.Context, id int, page int, perPage int, fields ...StudioField) (*Studio, error) {
if len(fields) == 0 {
fields = []StudioField{
StudioFieldID,
StudioFieldName,
StudioFieldIsAnimationStudio,
StudioFieldFavourites,
StudioFieldMedia(StudioParamMedia{
Page: page,
PerPage: perPage,
Sort: []MediaSort{MediaSortStartDateDesc},
},
MediaConnectionFieldPageInfo(
PageInfoFieldTotal,
PageInfoFieldPerPage,
PageInfoFieldCurrentPage,
PageInfoFieldLastPage,
PageInfoFieldHasNextPage),
MediaConnectionFieldEdges(
MediaEdgeFieldIsMainStudio,
MediaEdgeFieldNode(
MediaFieldID,
MediaFieldTitle(
MediaTitleFieldEnglish,
MediaTitleFieldNative,
MediaTitleFieldRomaji),
MediaFieldCoverImage(MediaCoverImageFieldMedium),
MediaFieldStartDate,
MediaFieldEndDate,
MediaFieldDescription,
MediaFieldSeason,
MediaFieldSeasonYear,
MediaFieldType,
MediaFieldFormat,
MediaFieldStatusV2,
MediaFieldGenres,
MediaFieldIsAdult,
MediaFieldAverageScore,
MediaFieldPopularity))),
}
}
query := FieldObject("query", QueryParam{
"$id": "Int",
}, c.studioQuery(QueryParam{
"id": "$id",
}, fields...))
var d studioResponse
err := c.post(ctx, query, QueryParam{
"id": id,
}, &d)
if err != nil {
return nil, err
}
return &d.Data.Studio, nil
}
// GetStudios to get list of studios.
func (c *Client) GetStudios(page int, perPage int, fields ...StudioField) (*Page, error) {
return c.GetStudiosWithContext(context.Background(), page, perPage, fields...)
}
// GetStudiosWithContext to get list of studios with context.
func (c *Client) GetStudiosWithContext(ctx context.Context, page int, perPage int, fields ...StudioField) (*Page, error) {
if len(fields) == 0 {
fields = []StudioField{
StudioFieldID,
StudioFieldName,
StudioFieldIsAnimationStudio,
StudioFieldFavourites,
}
}
pageFields := PageFieldStudios(PageParamStudios{
Sort: []StudioSort{StudioSortName},
}, "", fields...)
return c.page(ctx, page, perPage, pageFields)
}