-
Notifications
You must be signed in to change notification settings - Fork 26
/
action.go
66 lines (57 loc) · 2.35 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
package civogo
import (
"bytes"
"encoding/json"
"fmt"
"time"
"github.com/google/go-querystring/query"
)
// PaginateActionList is a struct for a page of actions
type PaginateActionList struct {
Page int `json:"page"`
PerPage int `json:"per_page"`
Pages int `json:"pages"`
Items []Action `json:"items"`
}
// Action is a struct for an individual action within the database and when serialized
type Action struct {
ID int `json:"id" gorm:"autoIncrement"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
AccountID string `json:"account_id"`
UserID string `json:"user_id"`
Type string `json:"type"`
Details string `json:"details,omitempty"`
RelatedID string `json:"related_id,omitempty"`
RelatedType string `json:"related_type,omitempty"`
Debug bool `json:"debug"`
}
// ActionListRequest is a struct for the request to list actions
type ActionListRequest struct {
PerPage int `json:"per_page,omitempty" url:"per_page,omitempty"`
Page int `json:"page,omitempty" url:"page,omitempty"`
IncludeDebug bool `json:"include_debug,omitempty" url:"include_debug,omitempty"`
ResourceID string `json:"resource_id,omitempty" url:"resource_id,omitempty"`
Details string `json:"details,omitempty" url:"details,omitempty"`
RelatedID string `json:"related_id,omitempty" url:"related_id,omitempty"`
ResourceType string `json:"resource_type,omitempty" url:"resource_type,omitempty"`
ActionType string `json:"action_type,omitempty" url:"action_type,omitempty"`
CreatedAt string `json:"created_at,omitempty" url:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty" url:"updated_at,omitempty"`
UserID string `json:"user_id,omitempty" url:"user_id,omitempty"`
}
// ListActions returns a page of actions
func (c *Client) ListActions(listRequest *ActionListRequest) (*PaginateActionList, error) {
url := "/v2/actions"
vals, err := query.Values(listRequest)
if err != nil {
return nil, err
}
resp, err := c.SendGetRequest(fmt.Sprintf("%s?%s", url, vals.Encode()))
if err != nil {
return nil, decodeError(err)
}
paginateActionList := PaginateActionList{}
err = json.NewDecoder(bytes.NewReader(resp)).Decode(&paginateActionList)
return &paginateActionList, err
}