1 package apimanagement
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type NotificationClient struct {
20 BaseClient
21 }
22
23
24 func NewNotificationClient(subscriptionID string) NotificationClient {
25 return NewNotificationClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewNotificationClientWithBaseURI(baseURI string, subscriptionID string) NotificationClient {
31 return NotificationClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client NotificationClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, ifMatch string) (result NotificationContract, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.CreateOrUpdate")
43 defer func() {
44 sc := -1
45 if result.Response.Response != nil {
46 sc = result.Response.Response.StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: serviceName,
53 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
54 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
55 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
56 return result, validation.NewError("apimanagement.NotificationClient", "CreateOrUpdate", err.Error())
57 }
58
59 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, notificationName, ifMatch)
60 if err != nil {
61 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "CreateOrUpdate", nil, "Failure preparing request")
62 return
63 }
64
65 resp, err := client.CreateOrUpdateSender(req)
66 if err != nil {
67 result.Response = autorest.Response{Response: resp}
68 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "CreateOrUpdate", resp, "Failure sending request")
69 return
70 }
71
72 result, err = client.CreateOrUpdateResponder(resp)
73 if err != nil {
74 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "CreateOrUpdate", resp, "Failure responding to request")
75 return
76 }
77
78 return
79 }
80
81
82 func (client NotificationClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, ifMatch string) (*http.Request, error) {
83 pathParameters := map[string]interface{}{
84 "notificationName": autorest.Encode("path", notificationName),
85 "resourceGroupName": autorest.Encode("path", resourceGroupName),
86 "serviceName": autorest.Encode("path", serviceName),
87 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
88 }
89
90 const APIVersion = "2018-01-01"
91 queryParameters := map[string]interface{}{
92 "api-version": APIVersion,
93 }
94
95 preparer := autorest.CreatePreparer(
96 autorest.AsPut(),
97 autorest.WithBaseURL(client.BaseURI),
98 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}", pathParameters),
99 autorest.WithQueryParameters(queryParameters))
100 if len(ifMatch) > 0 {
101 preparer = autorest.DecoratePreparer(preparer,
102 autorest.WithHeader("If-Match", autorest.String(ifMatch)))
103 }
104 return preparer.Prepare((&http.Request{}).WithContext(ctx))
105 }
106
107
108
109 func (client NotificationClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
110 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
111 }
112
113
114
115 func (client NotificationClient) CreateOrUpdateResponder(resp *http.Response) (result NotificationContract, err error) {
116 err = autorest.Respond(
117 resp,
118 azure.WithErrorUnlessStatusCode(http.StatusOK),
119 autorest.ByUnmarshallingJSON(&result),
120 autorest.ByClosing())
121 result.Response = autorest.Response{Response: resp}
122 return
123 }
124
125
126
127
128
129
130 func (client NotificationClient) Get(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (result NotificationContract, err error) {
131 if tracing.IsEnabled() {
132 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.Get")
133 defer func() {
134 sc := -1
135 if result.Response.Response != nil {
136 sc = result.Response.Response.StatusCode
137 }
138 tracing.EndSpan(ctx, sc, err)
139 }()
140 }
141 if err := validation.Validate([]validation.Validation{
142 {TargetValue: serviceName,
143 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
144 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
145 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
146 return result, validation.NewError("apimanagement.NotificationClient", "Get", err.Error())
147 }
148
149 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, notificationName)
150 if err != nil {
151 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "Get", nil, "Failure preparing request")
152 return
153 }
154
155 resp, err := client.GetSender(req)
156 if err != nil {
157 result.Response = autorest.Response{Response: resp}
158 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "Get", resp, "Failure sending request")
159 return
160 }
161
162 result, err = client.GetResponder(resp)
163 if err != nil {
164 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "Get", resp, "Failure responding to request")
165 return
166 }
167
168 return
169 }
170
171
172 func (client NotificationClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (*http.Request, error) {
173 pathParameters := map[string]interface{}{
174 "notificationName": autorest.Encode("path", notificationName),
175 "resourceGroupName": autorest.Encode("path", resourceGroupName),
176 "serviceName": autorest.Encode("path", serviceName),
177 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
178 }
179
180 const APIVersion = "2018-01-01"
181 queryParameters := map[string]interface{}{
182 "api-version": APIVersion,
183 }
184
185 preparer := autorest.CreatePreparer(
186 autorest.AsGet(),
187 autorest.WithBaseURL(client.BaseURI),
188 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}", pathParameters),
189 autorest.WithQueryParameters(queryParameters))
190 return preparer.Prepare((&http.Request{}).WithContext(ctx))
191 }
192
193
194
195 func (client NotificationClient) GetSender(req *http.Request) (*http.Response, error) {
196 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
197 }
198
199
200
201 func (client NotificationClient) GetResponder(resp *http.Response) (result NotificationContract, err error) {
202 err = autorest.Respond(
203 resp,
204 azure.WithErrorUnlessStatusCode(http.StatusOK),
205 autorest.ByUnmarshallingJSON(&result),
206 autorest.ByClosing())
207 result.Response = autorest.Response{Response: resp}
208 return
209 }
210
211
212
213
214
215
216
217 func (client NotificationClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result NotificationCollectionPage, err error) {
218 if tracing.IsEnabled() {
219 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.ListByService")
220 defer func() {
221 sc := -1
222 if result.nc.Response.Response != nil {
223 sc = result.nc.Response.Response.StatusCode
224 }
225 tracing.EndSpan(ctx, sc, err)
226 }()
227 }
228 if err := validation.Validate([]validation.Validation{
229 {TargetValue: serviceName,
230 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
231 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
232 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
233 {TargetValue: top,
234 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
235 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
236 {TargetValue: skip,
237 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
238 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
239 return result, validation.NewError("apimanagement.NotificationClient", "ListByService", err.Error())
240 }
241
242 result.fn = client.listByServiceNextResults
243 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, top, skip)
244 if err != nil {
245 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "ListByService", nil, "Failure preparing request")
246 return
247 }
248
249 resp, err := client.ListByServiceSender(req)
250 if err != nil {
251 result.nc.Response = autorest.Response{Response: resp}
252 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "ListByService", resp, "Failure sending request")
253 return
254 }
255
256 result.nc, err = client.ListByServiceResponder(resp)
257 if err != nil {
258 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "ListByService", resp, "Failure responding to request")
259 return
260 }
261 if result.nc.hasNextLink() && result.nc.IsEmpty() {
262 err = result.NextWithContext(ctx)
263 return
264 }
265
266 return
267 }
268
269
270 func (client NotificationClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (*http.Request, error) {
271 pathParameters := map[string]interface{}{
272 "resourceGroupName": autorest.Encode("path", resourceGroupName),
273 "serviceName": autorest.Encode("path", serviceName),
274 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
275 }
276
277 const APIVersion = "2018-01-01"
278 queryParameters := map[string]interface{}{
279 "api-version": APIVersion,
280 }
281 if top != nil {
282 queryParameters["$top"] = autorest.Encode("query", *top)
283 }
284 if skip != nil {
285 queryParameters["$skip"] = autorest.Encode("query", *skip)
286 }
287
288 preparer := autorest.CreatePreparer(
289 autorest.AsGet(),
290 autorest.WithBaseURL(client.BaseURI),
291 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications", pathParameters),
292 autorest.WithQueryParameters(queryParameters))
293 return preparer.Prepare((&http.Request{}).WithContext(ctx))
294 }
295
296
297
298 func (client NotificationClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
299 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
300 }
301
302
303
304 func (client NotificationClient) ListByServiceResponder(resp *http.Response) (result NotificationCollection, err error) {
305 err = autorest.Respond(
306 resp,
307 azure.WithErrorUnlessStatusCode(http.StatusOK),
308 autorest.ByUnmarshallingJSON(&result),
309 autorest.ByClosing())
310 result.Response = autorest.Response{Response: resp}
311 return
312 }
313
314
315 func (client NotificationClient) listByServiceNextResults(ctx context.Context, lastResults NotificationCollection) (result NotificationCollection, err error) {
316 req, err := lastResults.notificationCollectionPreparer(ctx)
317 if err != nil {
318 return result, autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "listByServiceNextResults", nil, "Failure preparing next results request")
319 }
320 if req == nil {
321 return
322 }
323 resp, err := client.ListByServiceSender(req)
324 if err != nil {
325 result.Response = autorest.Response{Response: resp}
326 return result, autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "listByServiceNextResults", resp, "Failure sending next results request")
327 }
328 result, err = client.ListByServiceResponder(resp)
329 if err != nil {
330 err = autorest.NewErrorWithError(err, "apimanagement.NotificationClient", "listByServiceNextResults", resp, "Failure responding to next results request")
331 }
332 return
333 }
334
335
336 func (client NotificationClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result NotificationCollectionIterator, err error) {
337 if tracing.IsEnabled() {
338 ctx = tracing.StartSpan(ctx, fqdn+"/NotificationClient.ListByService")
339 defer func() {
340 sc := -1
341 if result.Response().Response.Response != nil {
342 sc = result.page.Response().Response.Response.StatusCode
343 }
344 tracing.EndSpan(ctx, sc, err)
345 }()
346 }
347 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, top, skip)
348 return
349 }
350
View as plain text