-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclubs.go
106 lines (94 loc) · 2.25 KB
/
clubs.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
104
105
106
package jikan
import (
"fmt"
"net/url"
"time"
)
// ClubsBase struct
type ClubsBase struct {
MalId int `json:"mal_id"`
Name string `json:"name"`
Url string `json:"url"`
Images struct {
Jpg struct {
ImageUrl string `json:"image_url"`
} `json:"jpg"`
} `json:"images"`
Members int `json:"members"`
Category string `json:"category"`
Created time.Time `json:"created"`
Access string `json:"access"`
}
// ClubsById struct
type ClubsById struct {
Data ClubsBase `json:"data"`
}
// GetClubsById returns club by id
func GetClubsById(id int) (*ClubsById, error) {
res := &ClubsById{}
err := urlToStruct(fmt.Sprintf("/clubs/%d", id), res)
if err != nil {
return nil, err
}
return res, nil
}
type ClubMembers struct {
Data []UserItem `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetClubMembers returns club members
func GetClubMembers(id, page int) (*ClubMembers, error) {
res := &ClubMembers{}
err := urlToStruct(fmt.Sprintf("/clubs/%d/members?page=%d", id, page), res)
if err != nil {
return nil, err
}
return res, nil
}
// ClubStaff struct
type ClubStaff struct {
Data []struct {
Url string `json:"url"`
Username string `json:"username"`
} `json:"data"`
}
// GetClubStaff returns club staff
func GetClubStaff(id int) (*ClubStaff, error) {
res := &ClubStaff{}
err := urlToStruct(fmt.Sprintf("/clubs/%d/staff", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// ClubRelations struct
type ClubRelations struct {
Data struct {
Anime []MalItem `json:"anime"`
Manga []MalItem `json:"manga"`
Characters []MalItem `json:"characters"`
} `json:"data"`
}
// GetClubRelations returns club relations
func GetClubRelations(id int) (*ClubRelations, error) {
res := &ClubRelations{}
err := urlToStruct(fmt.Sprintf("/clubs/%d/relations", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// ClubsSearch struct
type ClubsSearch struct {
Data []ClubsBase `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetClubsSearch returns clubs search
func GetClubsSearch(query url.Values) (*ClubsSearch, error) {
res := &ClubsSearch{}
err := urlToStruct(fmt.Sprintf("/clubs?%s", query.Encode()), res)
if err != nil {
return nil, err
}
return res, nil
}