-
Notifications
You must be signed in to change notification settings - Fork 1
/
events_based_billing_segments_controller.go
266 lines (244 loc) · 12.1 KB
/
events_based_billing_segments_controller.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
Package advancedbilling
This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
package advancedbilling
import (
"context"
"fmt"
"github.com/apimatic/go-core-runtime/https"
"github.com/apimatic/go-core-runtime/utilities"
"github.com/maxio-com/ab-golang-sdk/errors"
"github.com/maxio-com/ab-golang-sdk/models"
"net/http"
)
// EventsBasedBillingSegmentsController represents a controller struct.
type EventsBasedBillingSegmentsController struct {
baseController
}
// NewEventsBasedBillingSegmentsController creates a new instance of EventsBasedBillingSegmentsController.
// It takes a baseController as a parameter and returns a pointer to the EventsBasedBillingSegmentsController.
func NewEventsBasedBillingSegmentsController(baseController baseController) *EventsBasedBillingSegmentsController {
eventsBasedBillingSegmentsController := EventsBasedBillingSegmentsController{baseController: baseController}
return &eventsBasedBillingSegmentsController
}
// CreateSegment takes context, componentId, pricePointId, body as parameters and
// returns an models.ApiResponse with models.SegmentResponse data and
// an error if there was an issue with the request or response.
// This endpoint creates a new Segment for a Component with segmented Metric. It allows you to specify properties to bill upon and prices for each Segment. You can only pass as many "property_values" as the related Metric has segmenting properties defined.
// You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax.
func (e *EventsBasedBillingSegmentsController) CreateSegment(
ctx context.Context,
componentId string,
pricePointId string,
body *models.CreateSegmentRequest) (
models.ApiResponse[models.SegmentResponse],
error) {
req := e.prepareRequest(
ctx,
"POST",
fmt.Sprintf("/components/%v/price_points/%v/segments.json", componentId, pricePointId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewEventBasedBillingSegmentErrors},
})
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.SegmentResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.SegmentResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// ListSegmentsForPricePointInput represents the input of the ListSegmentsForPricePoint endpoint.
type ListSegmentsForPricePointInput struct {
// ID or Handle for the Component
ComponentId string
// ID or Handle for the Price Point belonging to the Component
PricePointId string
// Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
// Use in query `page=1`.
Page *int
// This parameter indicates how many records to fetch in each request. Default value is 30. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
// Use in query `per_page=200`.
PerPage *int
// Filter to use for List Segments for a Price Point operation
Filter *models.ListSegmentsFilter
}
// ListSegmentsForPricePoint takes context, componentId, pricePointId, page, perPage, filter as parameters and
// returns an models.ApiResponse with models.ListSegmentsResponse data and
// an error if there was an issue with the request or response.
// This endpoint allows you to fetch Segments created for a given Price Point. They will be returned in the order of creation.
// You can pass `page` and `per_page` parameters in order to access all of the segments. By default it will return `30` records. You can set `per_page` to `200` at most.
// You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax.
func (e *EventsBasedBillingSegmentsController) ListSegmentsForPricePoint(
ctx context.Context,
input ListSegmentsForPricePointInput) (
models.ApiResponse[models.ListSegmentsResponse],
error) {
req := e.prepareRequest(
ctx,
"GET",
fmt.Sprintf("/components/%v/price_points/%v/segments.json", input.ComponentId, input.PricePointId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewEventBasedBillingListSegmentsErrors},
})
if input.Page != nil {
req.QueryParam("page", *input.Page)
}
if input.PerPage != nil {
req.QueryParam("per_page", *input.PerPage)
}
if input.Filter != nil {
req.QueryParam("filter", *input.Filter)
}
var result models.ListSegmentsResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.ListSegmentsResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// UpdateSegment takes context, componentId, pricePointId, id, body as parameters and
// returns an models.ApiResponse with models.SegmentResponse data and
// an error if there was an issue with the request or response.
// This endpoint updates a single Segment for a Component with a segmented Metric. It allows you to update the pricing for the segment.
// You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax.
func (e *EventsBasedBillingSegmentsController) UpdateSegment(
ctx context.Context,
componentId string,
pricePointId string,
id float64,
body *models.UpdateSegmentRequest) (
models.ApiResponse[models.SegmentResponse],
error) {
req := e.prepareRequest(
ctx,
"PUT",
fmt.Sprintf("/components/%v/price_points/%v/segments/%v.json", componentId, pricePointId, id),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewEventBasedBillingSegmentErrors},
})
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.SegmentResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.SegmentResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// DeleteSegment takes context, componentId, pricePointId, id as parameters and
// returns an *Response and
// an error if there was an issue with the request or response.
// This endpoint allows you to delete a Segment with specified ID.
// You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax.
func (e *EventsBasedBillingSegmentsController) DeleteSegment(
ctx context.Context,
componentId string,
pricePointId string,
id float64) (
*http.Response,
error) {
req := e.prepareRequest(
ctx,
"DELETE",
fmt.Sprintf("/components/%v/price_points/%v/segments/%v.json", componentId, pricePointId, id),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'."},
})
httpCtx, err := req.Call()
if err != nil {
return httpCtx.Response, err
}
return httpCtx.Response, err
}
// BulkCreateSegments takes context, componentId, pricePointId, body as parameters and
// returns an models.ApiResponse with models.ListSegmentsResponse data and
// an error if there was an issue with the request or response.
// This endpoint allows you to create multiple segments in one request. The array of segments can contain up to `2000` records.
// If any of the records contain an error the whole request would fail and none of the requested segments get created. The error response contains a message for only the one segment that failed validation, with the corresponding index in the array.
// You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax.
func (e *EventsBasedBillingSegmentsController) BulkCreateSegments(
ctx context.Context,
componentId string,
pricePointId string,
body *models.BulkCreateSegments) (
models.ApiResponse[models.ListSegmentsResponse],
error) {
req := e.prepareRequest(
ctx,
"POST",
fmt.Sprintf("/components/%v/price_points/%v/segments/bulk.json", componentId, pricePointId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewEventBasedBillingSegment},
})
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.ListSegmentsResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.ListSegmentsResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// BulkUpdateSegments takes context, componentId, pricePointId, body as parameters and
// returns an models.ApiResponse with models.ListSegmentsResponse data and
// an error if there was an issue with the request or response.
// This endpoint allows you to update multiple segments in one request. The array of segments can contain up to `1000` records.
// If any of the records contain an error the whole request would fail and none of the requested segments get updated. The error response contains a message for only the one segment that failed validation, with the corresponding index in the array.
// You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax.
func (e *EventsBasedBillingSegmentsController) BulkUpdateSegments(
ctx context.Context,
componentId string,
pricePointId string,
body *models.BulkUpdateSegments) (
models.ApiResponse[models.ListSegmentsResponse],
error) {
req := e.prepareRequest(
ctx,
"PUT",
fmt.Sprintf("/components/%v/price_points/%v/segments/bulk.json", componentId, pricePointId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewEventBasedBillingSegment},
})
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.ListSegmentsResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.ListSegmentsResponse](decoder)
return models.NewApiResponse(result, resp), err
}