/
agent_role.go
51 lines (43 loc) · 1.33 KB
/
agent_role.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
package freshservice
import (
"fmt"
"net/http"
"time"
)
const (
agentRolesUrl = "roles"
agentRoleIdUrl = "roles/%d"
)
// AgentRoles contains Collection an array of AgentRole
type AgentRoles struct {
Collection []AgentRole `json:"roles"`
}
// agentRoleWrapper contains Details of an AgentRole
type agentRoleWrapper struct {
Details AgentRole `json:"role"`
}
// AgentRole represents a FreshService AgentRole
type AgentRole struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Default bool `json:"default"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// ListAgentRolesOptions represents pagination/filtering for AgentRoles
type ListAgentRolesOptions struct {
ListOptions
}
// GetAgentRole will return a single AgentRole by id
func (s *AgentService) GetAgentRole(id int) (*AgentRole, *http.Response, error) {
o := new(agentRoleWrapper)
res, err := s.client.Get(fmt.Sprintf(agentRoleIdUrl, id), &o)
return &o.Details, res, err
}
// ListAgentRoles will return paginated/filtered AgentRoles using ListAgentRolesOptions
func (s *AgentService) ListAgentRoles(opt ListAgentRolesOptions) (*AgentRoles, *http.Response, error) {
o := new(AgentRoles)
res, err := s.client.List(agentRolesUrl, opt, &o)
return o, res, err
}