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// APIIssueCommentsClient is the apiManagement Client
30type APIIssueCommentsClient struct {
31	BaseClient
32}
33
34// NewAPIIssueCommentsClient creates an instance of the APIIssueCommentsClient client.
35func NewAPIIssueCommentsClient(subscriptionID string) APIIssueCommentsClient {
36	return NewAPIIssueCommentsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAPIIssueCommentsClientWithBaseURI creates an instance of the APIIssueCommentsClient client using a custom
40// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
41// stack).
42func NewAPIIssueCommentsClientWithBaseURI(baseURI string, subscriptionID string) APIIssueCommentsClient {
43	return APIIssueCommentsClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// ListByService lists all comments for the Issue associated with the specified API.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// serviceName - the name of the API Management service.
50// apiid - API identifier. Must be unique in the current API Management service instance.
51// issueID - issue identifier. Must be unique in the current API Management service instance.
52// filter - | Field       | Supported operators    | Supported functions               |
53// |-------------|------------------------|-----------------------------------|
54// | id          | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
55// | userId          | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
56// top - number of records to return.
57// skip - number of records to skip.
58func (client APIIssueCommentsClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, filter string, top *int32, skip *int32) (result IssueCommentCollectionPage, err error) {
59	if tracing.IsEnabled() {
60		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentsClient.ListByService")
61		defer func() {
62			sc := -1
63			if result.icc.Response.Response != nil {
64				sc = result.icc.Response.Response.StatusCode
65			}
66			tracing.EndSpan(ctx, sc, err)
67		}()
68	}
69	if err := validation.Validate([]validation.Validation{
70		{TargetValue: serviceName,
71			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
72				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
73				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
74		{TargetValue: apiid,
75			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
76				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
77				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
78		{TargetValue: issueID,
79			Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil},
80				{Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil},
81				{Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
82		{TargetValue: top,
83			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
84				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
85		{TargetValue: skip,
86			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
87				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
88		return result, validation.NewError("apimanagement.APIIssueCommentsClient", "ListByService", err.Error())
89	}
90
91	result.fn = client.listByServiceNextResults
92	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, filter, top, skip)
93	if err != nil {
94		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentsClient", "ListByService", nil, "Failure preparing request")
95		return
96	}
97
98	resp, err := client.ListByServiceSender(req)
99	if err != nil {
100		result.icc.Response = autorest.Response{Response: resp}
101		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentsClient", "ListByService", resp, "Failure sending request")
102		return
103	}
104
105	result.icc, err = client.ListByServiceResponder(resp)
106	if err != nil {
107		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentsClient", "ListByService", resp, "Failure responding to request")
108	}
109
110	return
111}
112
113// ListByServicePreparer prepares the ListByService request.
114func (client APIIssueCommentsClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, filter string, top *int32, skip *int32) (*http.Request, error) {
115	pathParameters := map[string]interface{}{
116		"apiId":             autorest.Encode("path", apiid),
117		"issueId":           autorest.Encode("path", issueID),
118		"resourceGroupName": autorest.Encode("path", resourceGroupName),
119		"serviceName":       autorest.Encode("path", serviceName),
120		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
121	}
122
123	const APIVersion = "2017-03-01"
124	queryParameters := map[string]interface{}{
125		"api-version": APIVersion,
126	}
127	if len(filter) > 0 {
128		queryParameters["$filter"] = autorest.Encode("query", filter)
129	}
130	if top != nil {
131		queryParameters["$top"] = autorest.Encode("query", *top)
132	}
133	if skip != nil {
134		queryParameters["$skip"] = autorest.Encode("query", *skip)
135	}
136
137	preparer := autorest.CreatePreparer(
138		autorest.AsGet(),
139		autorest.WithBaseURL(client.BaseURI),
140		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}/comments", pathParameters),
141		autorest.WithQueryParameters(queryParameters))
142	return preparer.Prepare((&http.Request{}).WithContext(ctx))
143}
144
145// ListByServiceSender sends the ListByService request. The method will close the
146// http.Response Body if it receives an error.
147func (client APIIssueCommentsClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
148	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
149}
150
151// ListByServiceResponder handles the response to the ListByService request. The method always
152// closes the http.Response Body.
153func (client APIIssueCommentsClient) ListByServiceResponder(resp *http.Response) (result IssueCommentCollection, err error) {
154	err = autorest.Respond(
155		resp,
156		client.ByInspecting(),
157		azure.WithErrorUnlessStatusCode(http.StatusOK),
158		autorest.ByUnmarshallingJSON(&result),
159		autorest.ByClosing())
160	result.Response = autorest.Response{Response: resp}
161	return
162}
163
164// listByServiceNextResults retrieves the next set of results, if any.
165func (client APIIssueCommentsClient) listByServiceNextResults(ctx context.Context, lastResults IssueCommentCollection) (result IssueCommentCollection, err error) {
166	req, err := lastResults.issueCommentCollectionPreparer(ctx)
167	if err != nil {
168		return result, autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentsClient", "listByServiceNextResults", nil, "Failure preparing next results request")
169	}
170	if req == nil {
171		return
172	}
173	resp, err := client.ListByServiceSender(req)
174	if err != nil {
175		result.Response = autorest.Response{Response: resp}
176		return result, autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentsClient", "listByServiceNextResults", resp, "Failure sending next results request")
177	}
178	result, err = client.ListByServiceResponder(resp)
179	if err != nil {
180		err = autorest.NewErrorWithError(err, "apimanagement.APIIssueCommentsClient", "listByServiceNextResults", resp, "Failure responding to next results request")
181	}
182	return
183}
184
185// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
186func (client APIIssueCommentsClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, filter string, top *int32, skip *int32) (result IssueCommentCollectionIterator, err error) {
187	if tracing.IsEnabled() {
188		ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueCommentsClient.ListByService")
189		defer func() {
190			sc := -1
191			if result.Response().Response.Response != nil {
192				sc = result.page.Response().Response.Response.StatusCode
193			}
194			tracing.EndSpan(ctx, sc, err)
195		}()
196	}
197	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, issueID, filter, top, skip)
198	return
199}
200