1package apimanagement
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// APIIssueCommentClient is the apiManagement Client
30type APIIssueCommentClient struct {
31	BaseClient
32}
33
34// NewAPIIssueCommentClient creates an instance of the APIIssueCommentClient client.
35func NewAPIIssueCommentClient(subscriptionID string) APIIssueCommentClient {
36	return NewAPIIssueCommentClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAPIIssueCommentClientWithBaseURI creates an instance of the APIIssueCommentClient client using a custom endpoint.
40// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewAPIIssueCommentClientWithBaseURI(baseURI string, subscriptionID string) APIIssueCommentClient {
42	return APIIssueCommentClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CreateOrUpdate creates a new Comment for the Issue in an API or updates an existing one.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// serviceName - the name of the API Management service.
49// apiid - API identifier. Must be unique in the current API Management service instance.
50// issueID - issue identifier. Must be unique in the current API Management service instance.
51// commentID - comment identifier within an Issue. Must be unique in the current Issue.
52// parameters - create parameters.
53// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
54func (client APIIssueCommentClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string, parameters IssueCommentContract, ifMatch string) (result IssueCommentContract, err error) {
55	if tracing.IsEnabled() {
56		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentClient.CreateOrUpdate")
57		defer func() {
58			sc := -1
59			if result.Response.Response != nil {
60				sc = result.Response.Response.StatusCode
61			}
62			tracing.EndSpan(ctx, sc, err)
63		}()
64	}
65	if err := validation.Validate([]validation.Validation{
66		{TargetValue: serviceName,
67			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
68				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
70		{TargetValue: apiid,
71			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
72				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
73				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
74		{TargetValue: issueID,
75			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
76				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
77				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
78		{TargetValue: commentID,
79			Constraints: []validation.Constraint{{Target: "commentID", Name: validation.MaxLength, Rule: 256, Chain: nil},
80				{Target: "commentID", Name: validation.MinLength, Rule: 1, Chain: nil},
81				{Target: "commentID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
82		{TargetValue: parameters,
83			Constraints: []validation.Constraint{{Target: "parameters.IssueCommentContractProperties", Name: validation.Null, Rule: false,
84				Chain: []validation.Constraint{{Target: "parameters.IssueCommentContractProperties.Text", Name: validation.Null, Rule: true, Chain: nil},
85					{Target: "parameters.IssueCommentContractProperties.UserID", Name: validation.Null, Rule: true, Chain: nil},
86				}}}}}); err != nil {
87		return result, validation.NewError("apimanagement.APIIssueCommentClient", "CreateOrUpdate", err.Error())
88	}
89
90	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, commentID, parameters, ifMatch)
91	if err != nil {
92		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "CreateOrUpdate", nil, "Failure preparing request")
93		return
94	}
95
96	resp, err := client.CreateOrUpdateSender(req)
97	if err != nil {
98		result.Response = autorest.Response{Response: resp}
99		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "CreateOrUpdate", resp, "Failure sending request")
100		return
101	}
102
103	result, err = client.CreateOrUpdateResponder(resp)
104	if err != nil {
105		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "CreateOrUpdate", resp, "Failure responding to request")
106	}
107
108	return
109}
110
111// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
112func (client APIIssueCommentClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string, parameters IssueCommentContract, ifMatch string) (*http.Request, error) {
113	pathParameters := map[string]interface{}{
114		"apiId":             autorest.Encode("path", apiid),
115		"commentId":         autorest.Encode("path", commentID),
116		"issueId":           autorest.Encode("path", issueID),
117		"resourceGroupName": autorest.Encode("path", resourceGroupName),
118		"serviceName":       autorest.Encode("path", serviceName),
119		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
120	}
121
122	const APIVersion = "2018-06-01-preview"
123	queryParameters := map[string]interface{}{
124		"api-version": APIVersion,
125	}
126
127	preparer := autorest.CreatePreparer(
128		autorest.AsContentType("application/json; charset=utf-8"),
129		autorest.AsPut(),
130		autorest.WithBaseURL(client.BaseURI),
131		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}/comments/{commentId}", pathParameters),
132		autorest.WithJSON(parameters),
133		autorest.WithQueryParameters(queryParameters))
134	if len(ifMatch) > 0 {
135		preparer = autorest.DecoratePreparer(preparer,
136			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
137	}
138	return preparer.Prepare((&http.Request{}).WithContext(ctx))
139}
140
141// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
142// http.Response Body if it receives an error.
143func (client APIIssueCommentClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
144	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
145}
146
147// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
148// closes the http.Response Body.
149func (client APIIssueCommentClient) CreateOrUpdateResponder(resp *http.Response) (result IssueCommentContract, err error) {
150	err = autorest.Respond(
151		resp,
152		client.ByInspecting(),
153		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
154		autorest.ByUnmarshallingJSON(&result),
155		autorest.ByClosing())
156	result.Response = autorest.Response{Response: resp}
157	return
158}
159
160// Delete deletes the specified comment from an Issue.
161// Parameters:
162// resourceGroupName - the name of the resource group.
163// serviceName - the name of the API Management service.
164// apiid - API identifier. Must be unique in the current API Management service instance.
165// issueID - issue identifier. Must be unique in the current API Management service instance.
166// commentID - comment identifier within an Issue. Must be unique in the current Issue.
167// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
168// request or it should be * for unconditional update.
169func (client APIIssueCommentClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string, ifMatch string) (result autorest.Response, err error) {
170	if tracing.IsEnabled() {
171		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentClient.Delete")
172		defer func() {
173			sc := -1
174			if result.Response != nil {
175				sc = result.Response.StatusCode
176			}
177			tracing.EndSpan(ctx, sc, err)
178		}()
179	}
180	if err := validation.Validate([]validation.Validation{
181		{TargetValue: serviceName,
182			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
183				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
184				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
185		{TargetValue: apiid,
186			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
187				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
188				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
189		{TargetValue: issueID,
190			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
191				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
192				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
193		{TargetValue: commentID,
194			Constraints: []validation.Constraint{{Target: "commentID", Name: validation.MaxLength, Rule: 256, Chain: nil},
195				{Target: "commentID", Name: validation.MinLength, Rule: 1, Chain: nil},
196				{Target: "commentID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
197		return result, validation.NewError("apimanagement.APIIssueCommentClient", "Delete", err.Error())
198	}
199
200	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, commentID, ifMatch)
201	if err != nil {
202		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "Delete", nil, "Failure preparing request")
203		return
204	}
205
206	resp, err := client.DeleteSender(req)
207	if err != nil {
208		result.Response = resp
209		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "Delete", resp, "Failure sending request")
210		return
211	}
212
213	result, err = client.DeleteResponder(resp)
214	if err != nil {
215		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "Delete", resp, "Failure responding to request")
216	}
217
218	return
219}
220
221// DeletePreparer prepares the Delete request.
222func (client APIIssueCommentClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string, ifMatch string) (*http.Request, error) {
223	pathParameters := map[string]interface{}{
224		"apiId":             autorest.Encode("path", apiid),
225		"commentId":         autorest.Encode("path", commentID),
226		"issueId":           autorest.Encode("path", issueID),
227		"resourceGroupName": autorest.Encode("path", resourceGroupName),
228		"serviceName":       autorest.Encode("path", serviceName),
229		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
230	}
231
232	const APIVersion = "2018-06-01-preview"
233	queryParameters := map[string]interface{}{
234		"api-version": APIVersion,
235	}
236
237	preparer := autorest.CreatePreparer(
238		autorest.AsDelete(),
239		autorest.WithBaseURL(client.BaseURI),
240		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}/comments/{commentId}", pathParameters),
241		autorest.WithQueryParameters(queryParameters),
242		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
243	return preparer.Prepare((&http.Request{}).WithContext(ctx))
244}
245
246// DeleteSender sends the Delete request. The method will close the
247// http.Response Body if it receives an error.
248func (client APIIssueCommentClient) DeleteSender(req *http.Request) (*http.Response, error) {
249	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
250}
251
252// DeleteResponder handles the response to the Delete request. The method always
253// closes the http.Response Body.
254func (client APIIssueCommentClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
255	err = autorest.Respond(
256		resp,
257		client.ByInspecting(),
258		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
259		autorest.ByClosing())
260	result.Response = resp
261	return
262}
263
264// Get gets the details of the issue Comment for an API specified by its identifier.
265// Parameters:
266// resourceGroupName - the name of the resource group.
267// serviceName - the name of the API Management service.
268// apiid - API identifier. Must be unique in the current API Management service instance.
269// issueID - issue identifier. Must be unique in the current API Management service instance.
270// commentID - comment identifier within an Issue. Must be unique in the current Issue.
271func (client APIIssueCommentClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string) (result IssueCommentContract, err error) {
272	if tracing.IsEnabled() {
273		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentClient.Get")
274		defer func() {
275			sc := -1
276			if result.Response.Response != nil {
277				sc = result.Response.Response.StatusCode
278			}
279			tracing.EndSpan(ctx, sc, err)
280		}()
281	}
282	if err := validation.Validate([]validation.Validation{
283		{TargetValue: serviceName,
284			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
285				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
286				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
287		{TargetValue: apiid,
288			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
289				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
290				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
291		{TargetValue: issueID,
292			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
293				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
294				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
295		{TargetValue: commentID,
296			Constraints: []validation.Constraint{{Target: "commentID", Name: validation.MaxLength, Rule: 256, Chain: nil},
297				{Target: "commentID", Name: validation.MinLength, Rule: 1, Chain: nil},
298				{Target: "commentID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
299		return result, validation.NewError("apimanagement.APIIssueCommentClient", "Get", err.Error())
300	}
301
302	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, issueID, commentID)
303	if err != nil {
304		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "Get", nil, "Failure preparing request")
305		return
306	}
307
308	resp, err := client.GetSender(req)
309	if err != nil {
310		result.Response = autorest.Response{Response: resp}
311		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "Get", resp, "Failure sending request")
312		return
313	}
314
315	result, err = client.GetResponder(resp)
316	if err != nil {
317		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "Get", resp, "Failure responding to request")
318	}
319
320	return
321}
322
323// GetPreparer prepares the Get request.
324func (client APIIssueCommentClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string) (*http.Request, error) {
325	pathParameters := map[string]interface{}{
326		"apiId":             autorest.Encode("path", apiid),
327		"commentId":         autorest.Encode("path", commentID),
328		"issueId":           autorest.Encode("path", issueID),
329		"resourceGroupName": autorest.Encode("path", resourceGroupName),
330		"serviceName":       autorest.Encode("path", serviceName),
331		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
332	}
333
334	const APIVersion = "2018-06-01-preview"
335	queryParameters := map[string]interface{}{
336		"api-version": APIVersion,
337	}
338
339	preparer := autorest.CreatePreparer(
340		autorest.AsGet(),
341		autorest.WithBaseURL(client.BaseURI),
342		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}/comments/{commentId}", pathParameters),
343		autorest.WithQueryParameters(queryParameters))
344	return preparer.Prepare((&http.Request{}).WithContext(ctx))
345}
346
347// GetSender sends the Get request. The method will close the
348// http.Response Body if it receives an error.
349func (client APIIssueCommentClient) GetSender(req *http.Request) (*http.Response, error) {
350	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
351}
352
353// GetResponder handles the response to the Get request. The method always
354// closes the http.Response Body.
355func (client APIIssueCommentClient) GetResponder(resp *http.Response) (result IssueCommentContract, err error) {
356	err = autorest.Respond(
357		resp,
358		client.ByInspecting(),
359		azure.WithErrorUnlessStatusCode(http.StatusOK),
360		autorest.ByUnmarshallingJSON(&result),
361		autorest.ByClosing())
362	result.Response = autorest.Response{Response: resp}
363	return
364}
365
366// GetEntityTag gets the entity state (Etag) version of the issue Comment for an API specified by its identifier.
367// Parameters:
368// resourceGroupName - the name of the resource group.
369// serviceName - the name of the API Management service.
370// apiid - API identifier. Must be unique in the current API Management service instance.
371// issueID - issue identifier. Must be unique in the current API Management service instance.
372// commentID - comment identifier within an Issue. Must be unique in the current Issue.
373func (client APIIssueCommentClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string) (result autorest.Response, err error) {
374	if tracing.IsEnabled() {
375		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentClient.GetEntityTag")
376		defer func() {
377			sc := -1
378			if result.Response != nil {
379				sc = result.Response.StatusCode
380			}
381			tracing.EndSpan(ctx, sc, err)
382		}()
383	}
384	if err := validation.Validate([]validation.Validation{
385		{TargetValue: serviceName,
386			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
387				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
388				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
389		{TargetValue: apiid,
390			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
391				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
392				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
393		{TargetValue: issueID,
394			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
395				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
396				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
397		{TargetValue: commentID,
398			Constraints: []validation.Constraint{{Target: "commentID", Name: validation.MaxLength, Rule: 256, Chain: nil},
399				{Target: "commentID", Name: validation.MinLength, Rule: 1, Chain: nil},
400				{Target: "commentID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
401		return result, validation.NewError("apimanagement.APIIssueCommentClient", "GetEntityTag", err.Error())
402	}
403
404	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, issueID, commentID)
405	if err != nil {
406		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "GetEntityTag", nil, "Failure preparing request")
407		return
408	}
409
410	resp, err := client.GetEntityTagSender(req)
411	if err != nil {
412		result.Response = resp
413		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "GetEntityTag", resp, "Failure sending request")
414		return
415	}
416
417	result, err = client.GetEntityTagResponder(resp)
418	if err != nil {
419		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "GetEntityTag", resp, "Failure responding to request")
420	}
421
422	return
423}
424
425// GetEntityTagPreparer prepares the GetEntityTag request.
426func (client APIIssueCommentClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, commentID string) (*http.Request, error) {
427	pathParameters := map[string]interface{}{
428		"apiId":             autorest.Encode("path", apiid),
429		"commentId":         autorest.Encode("path", commentID),
430		"issueId":           autorest.Encode("path", issueID),
431		"resourceGroupName": autorest.Encode("path", resourceGroupName),
432		"serviceName":       autorest.Encode("path", serviceName),
433		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
434	}
435
436	const APIVersion = "2018-06-01-preview"
437	queryParameters := map[string]interface{}{
438		"api-version": APIVersion,
439	}
440
441	preparer := autorest.CreatePreparer(
442		autorest.AsHead(),
443		autorest.WithBaseURL(client.BaseURI),
444		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}/comments/{commentId}", pathParameters),
445		autorest.WithQueryParameters(queryParameters))
446	return preparer.Prepare((&http.Request{}).WithContext(ctx))
447}
448
449// GetEntityTagSender sends the GetEntityTag request. The method will close the
450// http.Response Body if it receives an error.
451func (client APIIssueCommentClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
452	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
453}
454
455// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
456// closes the http.Response Body.
457func (client APIIssueCommentClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
458	err = autorest.Respond(
459		resp,
460		client.ByInspecting(),
461		azure.WithErrorUnlessStatusCode(http.StatusOK),
462		autorest.ByClosing())
463	result.Response = resp
464	return
465}
466
467// ListByService lists all comments for the Issue associated with the specified API.
468// Parameters:
469// resourceGroupName - the name of the resource group.
470// serviceName - the name of the API Management service.
471// apiid - API identifier. Must be unique in the current API Management service instance.
472// issueID - issue identifier. Must be unique in the current API Management service instance.
473// filter - | Field       | Supported operators    | Supported functions               |
474// |-------------|------------------------|-----------------------------------|
475//
476// |name | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith|
477// |userId | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith|
478// top - number of records to return.
479// skip - number of records to skip.
480func (client APIIssueCommentClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, filter string, top *int32, skip *int32) (result IssueCommentCollectionPage, err error) {
481	if tracing.IsEnabled() {
482		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentClient.ListByService")
483		defer func() {
484			sc := -1
485			if result.icc.Response.Response != nil {
486				sc = result.icc.Response.Response.StatusCode
487			}
488			tracing.EndSpan(ctx, sc, err)
489		}()
490	}
491	if err := validation.Validate([]validation.Validation{
492		{TargetValue: serviceName,
493			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
494				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
495				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
496		{TargetValue: apiid,
497			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
498				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
499				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
500		{TargetValue: issueID,
501			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
502				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
503				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
504		{TargetValue: top,
505			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
506				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
507		{TargetValue: skip,
508			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
509				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
510		return result, validation.NewError("apimanagement.APIIssueCommentClient", "ListByService", err.Error())
511	}
512
513	result.fn = client.listByServiceNextResults
514	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, filter, top, skip)
515	if err != nil {
516		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "ListByService", nil, "Failure preparing request")
517		return
518	}
519
520	resp, err := client.ListByServiceSender(req)
521	if err != nil {
522		result.icc.Response = autorest.Response{Response: resp}
523		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "ListByService", resp, "Failure sending request")
524		return
525	}
526
527	result.icc, err = client.ListByServiceResponder(resp)
528	if err != nil {
529		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "ListByService", resp, "Failure responding to request")
530	}
531
532	return
533}
534
535// ListByServicePreparer prepares the ListByService request.
536func (client APIIssueCommentClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, filter string, top *int32, skip *int32) (*http.Request, error) {
537	pathParameters := map[string]interface{}{
538		"apiId":             autorest.Encode("path", apiid),
539		"issueId":           autorest.Encode("path", issueID),
540		"resourceGroupName": autorest.Encode("path", resourceGroupName),
541		"serviceName":       autorest.Encode("path", serviceName),
542		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
543	}
544
545	const APIVersion = "2018-06-01-preview"
546	queryParameters := map[string]interface{}{
547		"api-version": APIVersion,
548	}
549	if len(filter) > 0 {
550		queryParameters["$filter"] = autorest.Encode("query", filter)
551	}
552	if top != nil {
553		queryParameters["$top"] = autorest.Encode("query", *top)
554	}
555	if skip != nil {
556		queryParameters["$skip"] = autorest.Encode("query", *skip)
557	}
558
559	preparer := autorest.CreatePreparer(
560		autorest.AsGet(),
561		autorest.WithBaseURL(client.BaseURI),
562		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}/comments", pathParameters),
563		autorest.WithQueryParameters(queryParameters))
564	return preparer.Prepare((&http.Request{}).WithContext(ctx))
565}
566
567// ListByServiceSender sends the ListByService request. The method will close the
568// http.Response Body if it receives an error.
569func (client APIIssueCommentClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
570	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
571}
572
573// ListByServiceResponder handles the response to the ListByService request. The method always
574// closes the http.Response Body.
575func (client APIIssueCommentClient) ListByServiceResponder(resp *http.Response) (result IssueCommentCollection, err error) {
576	err = autorest.Respond(
577		resp,
578		client.ByInspecting(),
579		azure.WithErrorUnlessStatusCode(http.StatusOK),
580		autorest.ByUnmarshallingJSON(&result),
581		autorest.ByClosing())
582	result.Response = autorest.Response{Response: resp}
583	return
584}
585
586// listByServiceNextResults retrieves the next set of results, if any.
587func (client APIIssueCommentClient) listByServiceNextResults(ctx context.Context, lastResults IssueCommentCollection) (result IssueCommentCollection, err error) {
588	req, err := lastResults.issueCommentCollectionPreparer(ctx)
589	if err != nil {
590		return result, autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "listByServiceNextResults", nil, "Failure preparing next results request")
591	}
592	if req == nil {
593		return
594	}
595	resp, err := client.ListByServiceSender(req)
596	if err != nil {
597		result.Response = autorest.Response{Response: resp}
598		return result, autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "listByServiceNextResults", resp, "Failure sending next results request")
599	}
600	result, err = client.ListByServiceResponder(resp)
601	if err != nil {
602		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentClient", "listByServiceNextResults", resp, "Failure responding to next results request")
603	}
604	return
605}
606
607// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
608func (client APIIssueCommentClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, filter string, top *int32, skip *int32) (result IssueCommentCollectionIterator, err error) {
609	if tracing.IsEnabled() {
610		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentClient.ListByService")
611		defer func() {
612			sc := -1
613			if result.Response().Response.Response != nil {
614				sc = result.page.Response().Response.Response.StatusCode
615			}
616			tracing.EndSpan(ctx, sc, err)
617		}()
618	}
619	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, issueID, filter, top, skip)
620	return
621}
622