-
Notifications
You must be signed in to change notification settings - Fork 2
/
project.go
83 lines (65 loc) · 1.74 KB
/
project.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
package flagsmithapi
import (
"fmt"
)
func (c *Client) GetProject(projectUUID string) (*Project, error) {
url := fmt.Sprintf("%s/projects/get-by-uuid/%s/", c.baseURL, projectUUID)
project := Project{}
resp, err := c.client.R().
SetResult(&project).
Get(url)
if err != nil {
return nil, err
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("flagsmithapi: Error getting project: %s", resp)
}
return &project, nil
}
func (c *Client) GetProjectByID(projectID int64) (*Project, error) {
url := fmt.Sprintf("%s/projects/%d/", c.baseURL, projectID)
project := Project{}
resp, err := c.client.R().
SetResult(&project).
Get(url)
if err != nil {
return nil, err
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("flagsmithapi: Error getting project: %s", resp)
}
return &project, nil
}
func (c *Client) CreateProject(project *Project) error {
url := fmt.Sprintf("%s/projects/", c.baseURL)
resp, err := c.client.R().SetBody(project).SetResult(project).Post(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error creating project: %s", resp)
}
return nil
}
func (c *Client) UpdateProject(project *Project) error {
url := fmt.Sprintf("%s/projects/%d/", c.baseURL, project.ID)
resp, err := c.client.R().SetBody(project).SetResult(project).Put(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error updating project: %s", resp)
}
return nil
}
func (c *Client) DeleteProject(projectID int64) error {
url := fmt.Sprintf("%s/projects/%d/", c.baseURL, projectID)
resp, err := c.client.R().Delete(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error deleting project: %s", resp)
}
return nil
}