generated from davidji99/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsegments.go
115 lines (95 loc) · 3.84 KB
/
segments.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
108
109
110
111
112
113
114
115
package api
import (
"github.com/davidji99/simpleresty"
)
// SegmentsService handles communication with the segment related
// methods of the Split.io APIv2.
//
// Reference: https://docs.split.io/reference#segments-overview
type SegmentsService service
// Segment represents a Split segment.
type Segment struct {
Name *string `json:"name"`
Description *string `json:"description,omitempty"`
Environment *Environment `json:"environment"`
TrafficType *TrafficType `json:"trafficType"`
CreationTime *int64 `json:"creationTime"`
Tags []*Tag `json:"tags,omitempty"`
}
// SegmentKeysList
type SegmentKeysList struct {
Keys []*SegmentKey `json:"keys"`
GenericListResult
}
// SegmentKey
type SegmentKey struct {
Key *string `json:"key"`
}
// SegmentListResult represents the response returned when listing all segments.
type SegmentListResult struct {
Objects []*Segment `json:"objects"`
GenericListResult
}
// SegmentRequest represents a request to create a segment.
type SegmentRequest struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
// List all segments.
//
// Reference: https://docs.split.io/reference#list-segments
func (s *SegmentsService) List(workspaceID string) (*SegmentListResult, *simpleresty.Response, error) {
var result SegmentListResult
urlStr := s.client.http.RequestURL("/segments/ws/%s", workspaceID)
response, getErr := s.client.get(urlStr, &result, nil)
return &result, response, getErr
}
// Get a segment.
//
// Reference: n/a
func (s *SegmentsService) Get(workspaceID, name string) (*Segment, *simpleresty.Response, error) {
var result Segment
urlStr := s.client.http.RequestURL("/segments/ws/%s/%s", workspaceID, name)
response, getErr := s.client.get(urlStr, &result, nil)
return &result, response, getErr
}
// Create a segment. This API does not configure the Segment in any environment.
//
// Reference: https://docs.split.io/reference#create-segment
func (s *SegmentsService) Create(workspaceID, trafficTypeID string, opts *SegmentRequest) (*Segment, *simpleresty.Response, error) {
var result Segment
urlStr := s.client.http.RequestURL("/segments/ws/%s/trafficTypes/%s", workspaceID, trafficTypeID)
response, createErr := s.client.post(urlStr, &result, opts)
return &result, response, createErr
}
// There exists an update (PUT) endpoint to modify the description but that is an internal endpoint:
// https://app.split.io/internal/api/segmentMetadata/updateDescription/<SEGMENT_ID>
//
// TODO: implement this method whenever this endpoint is GA.
//func (s *SegmentsService) Update() {
//}
// Delete a segment. This will automatically unconfigure the Segment Definition from all environments.
//
// Reference: https://docs.split.io/reference#delete-segment
func (s *SegmentsService) Delete(workspaceID, segmentName string) (*simpleresty.Response, error) {
urlStr := s.client.http.RequestURL("/segments/ws/%s/%s", workspaceID, segmentName)
response, deleteErr := s.client.delete(urlStr, nil, nil)
return response, deleteErr
}
// Activate a Segment in an environment to be able to set its definitions.
//
// Reference: https://docs.split.io/reference#enable-segment-in-environment
func (s *SegmentsService) Activate(environmentID, segmentName string) (*Segment, *simpleresty.Response, error) {
var result Segment
urlStr := s.client.http.RequestURL("/segments/%s/%s", environmentID, segmentName)
response, err := s.client.post(urlStr, &result, nil)
return &result, response, err
}
// Deactivate a Segment in an environment.
//
// Reference: https://docs.split.io/reference#deactivate-segment-in-environment
func (s *SegmentsService) Deactivate(environmentID, segmentName string) (*simpleresty.Response, error) {
urlStr := s.client.http.RequestURL("/segments/%s/%s", environmentID, segmentName)
response, err := s.client.delete(urlStr, nil, nil)
return response, err
}