-
Notifications
You must be signed in to change notification settings - Fork 3
/
eventapi_lists.go
218 lines (197 loc) · 5.92 KB
/
eventapi_lists.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package webapi
import (
"encoding/json"
"github.com/raceresult/go-model/list"
)
// Lists contains all api endpoints regarding lists
type Lists struct {
api *EventAPI
}
// newLists creates a new Lists api endpoint group
func newLists(api *EventAPI) *Lists {
return &Lists{
api: api,
}
}
// Names returns the names of all lists
func (q *Lists) Names() ([]string, error) {
bts, err := q.api.get("lists/names", nil)
if err != nil {
return nil, err
}
return parseJsonStringArr(bts)
}
// Delete deletes a list
func (q *Lists) Delete(name string) error {
values := urlValues{
"name": name,
}
_, err := q.api.get("lists/delete", values)
return err
}
// Copy creates a copy of a list
func (q *Lists) Copy(name, newName string) error {
values := urlValues{
"name": name,
"newName": newName,
}
_, err := q.api.get("lists/copy", values)
return err
}
// Rename renames a list
func (q *Lists) Rename(name, newName string) error {
values := urlValues{
"name": name,
"newName": newName,
}
_, err := q.api.get("lists/rename", values)
return err
}
// New creates a new list
func (q *Lists) New(name string) error {
values := urlValues{
"name": name,
}
_, err := q.api.get("lists/new", values)
return err
}
// Get returns the settings of a list
func (q *Lists) Get(name string, noTranslate bool, lang string) (*list.List, error) {
values := urlValues{
"name": name,
"noTranslate": noTranslate,
"lang": lang,
}
bts, err := q.api.get("lists/get", values)
if err != nil {
return nil, err
}
var dest *list.List
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return dest, nil
}
// Save saves a list
func (q *Lists) Save(item *list.List) error {
_, err := q.api.post("lists/save", nil, item)
return err
}
// CreatePDF creates a list in PDF format
func (q *Lists) CreatePDF(name string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "pdf",
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// CreateHTML creates a list in HTML format
func (q *Lists) CreateHTML(name string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "html",
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// CreateXML creates a list in XML format
func (q *Lists) CreateXML(name string, charset string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "xml",
"charset": charset,
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// CreateJSON creates a list in JSON format
func (q *Lists) CreateJSON(name string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "JSON",
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// CreateNewspaper creates a list in Newspaper format
func (q *Lists) CreateNewspaper(name string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "newspaper",
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// CreateCSV creates a list in CSV format
func (q *Lists) CreateCSV(name string, charset string, separator string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "csv",
"charset": charset,
"separator": separator,
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// CreateText creates a list in Text format
func (q *Lists) CreateText(name string, charset string, separator string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "text",
"charset": charset,
"separator": separator,
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// CreateXLSX creates a list in XLSX format
func (q *Lists) CreateXLSX(name string, contests []int, filter string, selectorResult string, lang string) ([]byte, error) {
values := urlValues{
"name": name,
"format": "xlsx",
"contest": intSliceToString(contests),
"filter": filter,
"selectorResult": selectorResult,
"lang": lang,
}
return q.api.get("lists/create", values)
}
// ParticipantsNotActivated returns the number of participants in the list which are not activated
func (q *Lists) ParticipantsNotActivated(name string, contests []int, onlyWithUnderscores bool) (int, error) {
values := urlValues{
"name": name,
"contest": intSliceToString(contests),
"onlyWithUnderscores": onlyWithUnderscores,
}
bts, err := q.api.get("lists/participantsnotactivated", values)
if err != nil {
return 0, err
}
var dest int
if err := json.Unmarshal(bts, &dest); err != nil {
return 0, err
}
return dest, nil
}