-
Notifications
You must be signed in to change notification settings - Fork 3
/
project.go
107 lines (94 loc) · 2.54 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
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 sdk
type ProjectsInterface interface {
Create(organizationID string, name string) (*ProjectResponse, error)
List(organizationID string) (*ProjectsResponse, error)
Get(projectID string) (*ProjectResponse, error)
Update(projectID string, organizationID string, name string) (*ProjectResponse, error)
Delete(projectIDs []string) (*ProjectsDeleteResponse, error)
}
type Projects struct {
CommandRunner CommandRunnerInterface
}
func NewProjects(commandRunner CommandRunnerInterface) *Projects {
return &Projects{CommandRunner: commandRunner}
}
func (p *Projects) Get(id string) (*ProjectResponse, error) {
command := Command{
Projects: &ProjectsCommand{
Get: &ProjectGetRequest{
ID: id,
},
},
}
var response ProjectResponse
if err := p.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}
func (p *Projects) Create(organizationID string, name string) (*ProjectResponse, error) {
command := Command{
Projects: &ProjectsCommand{
Create: &ProjectCreateRequest{
OrganizationID: organizationID,
Name: name,
},
},
}
var response ProjectResponse
if err := p.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}
func (p *Projects) List(organizationID string) (*ProjectsResponse, error) {
command := Command{
Projects: &ProjectsCommand{
List: &ProjectsListRequest{
OrganizationID: organizationID,
},
},
}
var response ProjectsResponse
if err := p.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}
func (p *Projects) Update(projectID, organizationID, name string) (*ProjectResponse, error) {
command := Command{
Projects: &ProjectsCommand{
Update: &ProjectPutRequest{
ID: projectID,
OrganizationID: organizationID,
Name: name,
},
},
}
var response ProjectResponse
if err := p.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}
func (p *Projects) Delete(projectIDs []string) (*ProjectsDeleteResponse, error) {
command := Command{
Projects: &ProjectsCommand{
Delete: &ProjectsDeleteRequest{
IDS: projectIDs,
},
},
}
var response ProjectsDeleteResponse
if err := p.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}
func (p *Projects) executeCommand(command Command, target interface{}) error {
responseStr, err := p.CommandRunner.RunCommand(command)
if err != nil {
return err
}
return checkSuccessAndError(responseStr, target)
}