-
Notifications
You must be signed in to change notification settings - Fork 2
/
bucket.go
78 lines (63 loc) · 1.85 KB
/
bucket.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
package runscope
import (
"encoding/json"
"fmt"
)
// Bucket represents a Runscope bucket for grouping tests
type Bucket struct {
Name string `json:"name"`
AuthToken string `json:"auth_token"`
Default bool `json:"default"`
Key string `json:"key"`
Team Team `json:"team"`
VerifySSL bool `json:"verify_ssl"`
CollectionsURL string `json:"collections_url"`
MessagesURL string `json:"messages_url"`
TestsURL string `json:"tests_url"`
TriggerURL string `json:"trigger_url"`
}
// NewBucketRequest are the options used to create a new bucket
type NewBucketRequest struct {
Name string `json:"name"`
TeamUUID string `json:"team_uuid"`
}
// ListBuckets returns all buckets for a given account
func (client *Client) ListBuckets() ([]Bucket, error) {
var buckets = []Bucket{}
content, err := client.Get("buckets")
if err != nil {
return buckets, err
}
err = unmarshal(content, &buckets)
return buckets, err
}
// GetBucket fetches the details for a single bucket specified by the Bucket Key
func (client *Client) GetBucket(bucketKey string) (Bucket, error) {
var bucket = Bucket{}
path := fmt.Sprintf("buckets/%s", bucketKey)
content, err := client.Get(path)
if err != nil {
return bucket, err
}
err = unmarshal(content, &bucket)
return bucket, err
}
// NewBucket creates a new Runscope bucket
func (client *Client) NewBucket(newBucketRequest *NewBucketRequest) (Bucket, error) {
var bucket = Bucket{}
data, err := json.Marshal(newBucketRequest)
if err != nil {
return bucket, err
}
content, err := client.Post("buckets", data)
if err != nil {
return bucket, err
}
err = unmarshal(content, &bucket)
return bucket, err
}
// DeleteBucket removes a bucket from the account
func (client *Client) DeleteBucket(bucketKey string) error {
path := fmt.Sprintf("buckets/%s", bucketKey)
return client.Delete(path)
}