-
Notifications
You must be signed in to change notification settings - Fork 18
/
team.go
107 lines (89 loc) · 2.81 KB
/
team.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
package runscope
import (
"fmt"
"time"
)
// Integration represents an integration with a third-party. See https://www.runscope.com/docs/api/integrations
type Integration struct {
ID string `json:"id"`
UUID string `json:"uuid"`
IntegrationType string `json:"type"`
Description string `json:"description,omitempty"`
}
// People represents a person belonging to a team. See https://www.runscope.com/docs/api/teams
type People struct {
ID string `json:"id"`
UUID string `json:"uuid"`
Name string `json:"name"`
Email string `json:"email"`
CreatedAt time.Time `json:"created_at"`
LastLoginAt time.Time `json:"last_login_at"`
GroupName string `json:"group_name"`
}
type Agent struct {
Version string `json:"version"`
AgentID string `json:"agent_id"`
Name string `json:"name"`
}
// ListIntegrations list all configured integrations for your team. See https://www.runscope.com/docs/api/integrations
func (client *Client) ListIntegrations(teamID string) ([]*Integration, error) {
resource, error := client.readResource("integration", teamID,
fmt.Sprintf("/teams/%s/integrations", teamID))
if error != nil {
return nil, error
}
integration, error := getIntegrationFromResponse(resource.Data)
if error != nil {
return nil, error
}
return integration, nil
}
// ListPeople list all the people on your team. See https://www.runscope.com/docs/api/teams
func (client *Client) ListPeople(teamID string) ([]*People, error) {
resource, error := client.readResource("people", teamID,
fmt.Sprintf("/teams/%s/people", teamID))
if error != nil {
return nil, error
}
people, error := getPeopleFromResponse(resource.Data)
if error != nil {
return nil, error
}
return people, nil
}
// ListAgents list all the agents. See https://api.blazemeter.com/api-monitoring/#agents
func (client *Client) ListAgents(teamID string) ([]*Agent, error) {
resource, error := client.readResource("agents", teamID,
fmt.Sprintf("/teams/%s/agents", teamID))
if error != nil {
return nil, error
}
agents, error := getAgentsFromResponse(resource.Data)
if error != nil {
return nil, error
}
return agents, nil
}
func choose(items []*Integration, test func(*Integration) bool) (result []*Integration) {
for _, item := range items {
if test(item) {
result = append(result, item)
}
}
return
}
func getIntegrationFromResponse(response interface{}) ([]*Integration, error) {
var integrations []*Integration
err := decode(&integrations, response)
return integrations, err
}
func getPeopleFromResponse(response interface{}) ([]*People, error) {
var people []*People
err := decode(&people, response)
return people, err
}
func getAgentsFromResponse(response interface{}) ([]*Agent, error) {
var agents []*Agent
err := decode(&agents, response)
return agents, err
}