-
Notifications
You must be signed in to change notification settings - Fork 3
/
eventapi_file.go
167 lines (149 loc) · 3.69 KB
/
eventapi_file.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
package webapi
import (
"encoding/json"
"errors"
"strconv"
"strings"
model "github.com/raceresult/go-model"
)
// File contains all api endpoints regarding the event file
type File struct {
api *EventAPI
}
// newFile creates a new File api endpoint group
func newFile(api *EventAPI) *File {
return &File{
api: api,
}
}
// Activate activates participants and returns the number of activated records
func (q *File) Activate(bib int, filter string, maxActivations int) (int, error) {
values := urlValues{
"bib": bib,
"filter": filter,
"maxActivations": maxActivations,
}
bts, err := q.api.get("file/activate", values)
if err != nil {
return 0, err
}
var dest int
if err := json.Unmarshal(bts, &dest); err != nil {
return 0, err
}
return dest, nil
}
// NotActivated returns the number of participants which are not activated
func (q *File) NotActivated(filter string) (int, error) {
values := urlValues{
"filter": filter,
}
bts, err := q.api.get("file/notactivated", values)
if err != nil {
return 0, err
}
var dest int
if err := json.Unmarshal(bts, &dest); err != nil {
return 0, err
}
return dest, nil
}
// SESVersion returns the version of the Sports Event Server
func (q *File) SESVersion() (*model.Version, error) {
bts, err := q.api.get("file/sesversion", nil)
if err != nil {
return nil, err
}
var dest model.Version
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return &dest, nil
}
// CheckExpression parses an expression
func (q *File) CheckExpression(expressions string, returnTree bool) (string, error) {
values := urlValues{
"expressions": expressions,
"returnTree": returnTree,
}
bts, err := q.api.get("file/checkexpression", values)
if err != nil {
return "", err
}
return string(bts), nil
}
// GetFile returns a copy of the entire event file
func (q *File) GetFile() ([]byte, error) {
bts, err := q.api.get("file/getfile", nil)
if err != nil {
return nil, err
}
return bts, nil
}
// ModJobID returns the modjobid of the file
func (q *File) ModJobID() (int, error) {
bts, err := q.api.get("file/modjobid", nil)
if err != nil {
return 0, err
}
var dest int
if err := json.Unmarshal(bts, &dest); err != nil {
return 0, err
}
return dest, nil
}
// ModJobIDs returns the normal modjobid and the settings modjobid of the file
func (q *File) ModJobIDs() (int, int, error) {
bts, err := q.api.get("file/modjobids", nil)
if err != nil {
return 0, 0, err
}
arr := strings.Split(string(bts), ";")
if len(arr) != 2 {
return 0, 0, errors.New("response invalid")
}
mid, _ := strconv.Atoi(arr[0])
midSettings, _ := strconv.Atoi(arr[1])
return mid, midSettings, nil
}
// Filename returns the filename of the event file
func (q *File) Filename() (string, error) {
bts, err := q.api.get("file/filename", nil)
if err != nil {
return "", err
}
return string(bts), nil
}
// Owner returns the user ID of the owner of the event.
// Available for online server only.
func (q *File) Owner() (int, error) {
bts, err := q.api.get("file/owner", nil)
if err != nil {
return 0, err
}
var dest int
if err := json.Unmarshal(bts, &dest); err != nil {
return 0, err
}
return dest, nil
}
// IsOwner returns true if the user owns the event.
// Available for online server only.
func (q *File) IsOwner() (bool, error) {
bts, err := q.api.get("file/isowner", nil)
if err != nil {
return false, err
}
var dest bool
err = json.Unmarshal(bts, &dest)
return dest, err
}
// Rights returns the user rights code this user has for this event.
// Available for online server only.
func (q *File) Rights() (string, error) {
bts, err := q.api.get("file/rights", nil)
if err != nil {
return "", err
}
return string(bts), nil
}