-
Notifications
You must be signed in to change notification settings - Fork 18
/
schedule.go
98 lines (80 loc) · 3.27 KB
/
schedule.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
package runscope
import "fmt"
// Schedule determines how often a test is executed. See https://api.blazemeter.com/api-monitoring/#schedules
type Schedule struct {
ID string `json:"id,omitempty"`
EnvironmentID string `json:"environment_id,omitempty"`
Interval string `json:"interval,omitempty"`
Note string `json:"note,omitempty"`
}
// NewSchedule creates a new schedule struct
func NewSchedule() *Schedule {
return &Schedule{}
}
// CreateSchedule creates a new test schedule. See https://api.blazemeter.com/api-monitoring/#schedule-details
func (client *Client) CreateSchedule(schedule *Schedule, bucketKey string, testID string) (*Schedule, error) {
newResource, error := client.createResource(schedule, "schedule", schedule.Note,
fmt.Sprintf("/buckets/%s/tests/%s/schedules", bucketKey, testID))
if error != nil {
return nil, error
}
newSchedule, error := getScheduleFromResponse(newResource.Data)
if error != nil {
return nil, error
}
return newSchedule, nil
}
// ReadSchedule list details about an existing test schedule. See https://api.blazemeter.com/api-monitoring/#schedule-details
func (client *Client) ReadSchedule(schedule *Schedule, bucketKey string, testID string) (*Schedule, error) {
resource, error := client.readResource("schedule", schedule.ID,
fmt.Sprintf("/buckets/%s/tests/%s/schedules/%s", bucketKey, testID, schedule.ID))
if error != nil {
return nil, error
}
readSchedule, error := getScheduleFromResponse(resource.Data)
if error != nil {
return nil, error
}
return readSchedule, nil
}
// ListSchedules list all the schedules for a given test. See https://api.blazemeter.com/api-monitoring/#test-schedule-list
func (client *Client) ListSchedules(bucketKey string, testID string) ([]*Schedule, error) {
resource, error := client.readResource("[]schedule", testID,
fmt.Sprintf("/buckets/%s/tests/%s/schedules", bucketKey, testID))
if error != nil {
return nil, error
}
readSchedules, error := getSchedulesFromResponse(resource.Data)
if error != nil {
return nil, error
}
return readSchedules, nil
}
// UpdateSchedule updates an existing test schedule. See https://api.blazemeter.com/api-monitoring/#modify-schedule
func (client *Client) UpdateSchedule(schedule *Schedule, bucketKey string, testID string) (*Schedule, error) {
resource, error := client.updateResource(schedule, "schedule", schedule.ID,
fmt.Sprintf("/buckets/%s/tests/%s/schedules/%s", bucketKey, testID, schedule.ID))
if error != nil {
return nil, error
}
readSchedule, error := getScheduleFromResponse(resource.Data)
if error != nil {
return nil, error
}
return readSchedule, nil
}
// DeleteSchedule delete an existing test schedule. See https://api.blazemeter.com/api-monitoring/#delete-test-schedule
func (client *Client) DeleteSchedule(schedule *Schedule, bucketKey string, testID string) error {
return client.deleteResource("schedule", schedule.ID,
fmt.Sprintf("/buckets/%s/tests/%s/schedules/%s", bucketKey, testID, schedule.ID))
}
func getScheduleFromResponse(response interface{}) (*Schedule, error) {
schedule := new(Schedule)
err := decode(schedule, response)
return schedule, err
}
func getSchedulesFromResponse(response interface{}) ([]*Schedule, error) {
var schedules []*Schedule
err := decode(&schedules, response)
return schedules, err
}