-
Notifications
You must be signed in to change notification settings - Fork 2
/
environment.go
80 lines (63 loc) · 1.85 KB
/
environment.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
package flagsmithapi
import (
"fmt"
)
func (c *Client) GetEnvironment(apiKey string) (*Environment, error) {
url := fmt.Sprintf("%s/environments/%s/", c.baseURL, apiKey)
environment := Environment{}
resp, err := c.client.R().
SetResult(&environment).Get(url)
if err != nil {
return nil, err
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("flagsmithapi: Error getting environment: %s", resp)
}
return &environment, nil
}
func (c *Client) GetEnvironmentByUUID(uuid string) (*Environment, error) {
url := fmt.Sprintf("%s/environments/get-by-uuid/%s/", c.baseURL, uuid)
environment := Environment{}
resp, err := c.client.R().
SetResult(&environment).Get(url)
if err != nil {
return nil, err
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("flagsmithapi: Error getting environment: %s", resp)
}
return &environment, nil
}
func (c *Client) CreateEnvironment(environment *Environment) error {
url := fmt.Sprintf("%s/environments/", c.baseURL)
resp, err := c.client.R().SetBody(environment).SetResult(environment).Post(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error creating environment: %s", resp)
}
return nil
}
func (c *Client) UpdateEnvironment(environment *Environment) error {
url := fmt.Sprintf("%s/environments/%s/", c.baseURL, environment.APIKey)
resp, err := c.client.R().SetBody(environment).SetResult(environment).Put(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error creating environment: %s", resp)
}
return nil
}
func (c *Client) DeleteEnvironment(apiKey string) error {
url := fmt.Sprintf("%s/environments/%s/", c.baseURL, apiKey)
resp, err := c.client.R().Delete(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error deleting environment: %s", resp)
}
return nil
}