generated from davidji99/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgroups.go
107 lines (86 loc) · 2.95 KB
/
groups.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 api
import (
"github.com/davidji99/simpleresty"
)
// GroupsService handles communication with the group related
// methods of the Split.io APIv2.
//
// Reference: https://docs.split.io/reference#groups-overview
type GroupsService service
// Group represents a group in Split.
type Group struct {
ID *string `json:"id"`
Name *string `json:"name"`
Description *string `json:"description"`
Type *string `json:"type"`
}
// GroupListResult
type GroupListResult struct {
Data []*Group `json:"objects"`
NextMarker *string `json:"nextMarker,omitempty"`
PreviousMarker *string `json:"previousMarker,omitempty"`
Limit *int `json:"limit"`
Count *int `json:"count"`
}
// GroupListOpts
type GroupListOpts struct {
// 1-200 are the potential values. Default=50
Limit int `url:"limit,omitempty"`
}
// GroupRequest
type GroupRequest struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}
// List all active Groups in the organization
//
// Reference: https://docs.split.io/reference#list-groups
func (g *GroupsService) List(opts *GroupListOpts) (*GroupListResult, *simpleresty.Response, error) {
var result GroupListResult
//Here I have a problem with the RequestURLWithParams, TBD
urlStr, urlStrErr := g.client.http.RequestURLWithQueryParams("/groups", opts)
if urlStrErr != nil {
return nil, nil, urlStrErr
}
// Execute the request
response, getErr := g.client.get(urlStr, &result, nil)
return &result, response, getErr
}
// Get a group by their group Id.
//
// Reference: https://docs.split.io/reference#get-group
func (g *GroupsService) Get(id string) (*Group, *simpleresty.Response, error) {
var result Group
urlStr := g.client.http.RequestURL("/groups/%s", id)
response, getErr := g.client.get(urlStr, &result, nil)
return &result, response, getErr
}
// Create a new group in your organization.
//
// Reference: https://docs.split.io/reference#create-group
func (g *GroupsService) Create(opts *GroupRequest) (*Group, *simpleresty.Response, error) {
var result Group
urlStr := g.client.http.RequestURL("/groups")
// Execute the request
response, getErr := g.client.post(urlStr, &result, opts)
return &result, response, getErr
}
// Update a group in your organization.
//
// Reference: https://docs.split.io/reference#update-group
func (g *GroupsService) Update(id string, opts *GroupRequest) (*Group, *simpleresty.Response, error) {
var result Group
urlStr := g.client.http.RequestURL("/groups/%s", id)
// Execute the request
response, getErr := g.client.put(urlStr, &result, opts)
return &result, response, getErr
}
// Delete a group in your organization.
//
// Reference: https://docs.split.io/reference#delete-group
func (g *GroupsService) Delete(id string) (*simpleresty.Response, error) {
urlStr := g.client.http.RequestURL("/groups/%s", id)
// Execute the request
response, getErr := g.client.delete(urlStr, nil, nil)
return response, getErr
}