-
Notifications
You must be signed in to change notification settings - Fork 3
/
eventapi_registrations.go
89 lines (78 loc) · 1.99 KB
/
eventapi_registrations.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
package webapi
import (
"encoding/json"
"github.com/raceresult/go-model/registration"
)
// Registrations contains all api endpoints regarding certificate sets
type Registrations struct {
api *EventAPI
}
// newRegistrations creates a new Registrations api endpoint group
func newRegistrations(api *EventAPI) *Registrations {
return &Registrations{
api: api,
}
}
// Names returns the names of all certificate sets
func (q *Registrations) Names() ([]string, error) {
bts, err := q.api.get("registrations/names", nil)
if err != nil {
return nil, err
}
return parseJsonStringArr(bts)
}
// Get returns a certificate sets
func (q *Registrations) Get(name string) (*registration.Registration, error) {
values := urlValues{
"name": name,
}
bts, err := q.api.get("registrations/get", values)
if err != nil {
return nil, err
}
var dest registration.Registration
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return &dest, nil
}
// Save saves a certificate sets
func (q *Registrations) Save(item *registration.Registration) error {
_, err := q.api.post("registrations/save", nil, item)
return err
}
// Delete deletes a certificate sets
func (q *Registrations) Delete(name string) error {
values := urlValues{
"name": name,
}
_, err := q.api.get("registrations/delete", values)
return err
}
// Copy creates a copy of a certificate sets
func (q *Registrations) Copy(name, newName string) error {
values := urlValues{
"name": name,
"newName": newName,
}
_, err := q.api.get("registrations/copy", values)
return err
}
// Rename renames a certificate sets
func (q *Registrations) Rename(name, newName string) error {
values := urlValues{
"name": name,
"newName": newName,
}
_, err := q.api.get("registrations/rename", values)
return err
}
// New creates a certificate sets
func (q *Registrations) New(name string, group bool) error {
values := urlValues{
"name": name,
"group": group,
}
_, err := q.api.get("registrations/new", values)
return err
}