-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.go
106 lines (94 loc) · 2.89 KB
/
action.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 ganboard
import "encoding/json"
// GetAvailableActions https://docs.kanboard.org/en/latest/api/action_procedures.html#getavailableactions
func (c *Client) GetAvailableActions() (map[string]string, error) {
query := request{
Client: c,
Method: "getAvailableActions",
}
response, err := query.decodeMapStringString()
return response, err
}
// GetAvailableActionEvents https://docs.kanboard.org/en/latest/api/action_procedures.html#getavailableactionevents
func (c *Client) GetAvailableActionEvents() (map[string]string, error) {
query := request{
Client: c,
Method: "getAvailableActionEvents",
}
response, err := query.decodeMapStringString()
return response, err
}
// GetCompatibleActionEvents https://docs.kanboard.org/en/latest/api/action_procedures.html#getcompatibleactionevents
func (c *Client) GetCompatibleActionEvents(actionName string) (map[string]string, error) {
query := request{
Client: c,
Method: "getCompatibleActionEvents",
Params: map[string]string{
"action_name": actionName,
},
}
response, err := query.decodeMapStringString()
return response, err
}
// GetActions https://docs.kanboard.org/en/latest/api/action_procedures.html#getactions
func (c *Client) GetActions(projectID int) (Action, error) {
query := request{
Client: c,
Method: "getActions",
Params: map[string]int{
"project_id": projectID,
},
}
response, err := query.decodeAction()
return response, err
}
// CreateAction https://docs.kanboard.org/en/latest/api/action_procedures.html#createaction
func (c *Client) CreateAction(params ActionParams) (int, error) {
query := request{
Client: c,
Method: "createAction",
Params: params,
}
response, err := query.decodeInt()
return response, err
}
// RemoveAction https://docs.kanboard.org/en/latest/api/action_procedures.html#createaction
func (c *Client) RemoveAction(actionID int) (bool, error) {
query := request{
Client: c,
Method: "removeAction",
Params: map[string]int{
"action_id": actionID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// Action type
type Action struct {
ID int `json:"id,string"`
ProjectID int `json:"project_id,string"`
EventName string `json:"event_name"`
ActionName string `json:"action_name"`
Params map[string]string `json:"params"`
}
// ActionParams input for CreateAction
type ActionParams struct {
ProjectID int `json:"project_id,string"`
EventName string `json:"event_name"`
ActionName string `json:"action_name"`
Params map[string]string `json:"params"`
}
func (r *request) decodeAction() (Action, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return Action{}, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result Action `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}