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 "net/http" 26) 27 28// ReportsClient is the apiManagement Client 29type ReportsClient struct { 30 BaseClient 31} 32 33// NewReportsClient creates an instance of the ReportsClient client. 34func NewReportsClient(subscriptionID string) ReportsClient { 35 return NewReportsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewReportsClientWithBaseURI creates an instance of the ReportsClient client. 39func NewReportsClientWithBaseURI(baseURI string, subscriptionID string) ReportsClient { 40 return ReportsClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// ListByService lists report records. 44// Parameters: 45// resourceGroupName - the name of the resource group. 46// serviceName - the name of the API Management service. 47// aggregation - report aggregation. 48// filter - the filter to apply on the operation. 49// top - number of records to return. 50// skip - number of records to skip. 51// interval - by time interval. This value is only applicable to ByTime aggregation. Interval must be multiple 52// of 15 minutes and may not be zero. The value should be in ISO 8601 format 53// (http://en.wikipedia.org/wiki/ISO_8601#Durations).This code can be used to convert TimSpan to a valid 54// interval string: XmlConvert.ToString(new TimeSpan(hours, minutes, secconds)) 55func (client ReportsClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, aggregation ReportsAggregation, filter string, top *int32, skip *int32, interval string) (result ReportCollectionPage, err error) { 56 if err := validation.Validate([]validation.Validation{ 57 {TargetValue: serviceName, 58 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 59 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 60 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 61 {TargetValue: top, 62 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 63 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}}, 64 {TargetValue: skip, 65 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 66 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil { 67 return result, validation.NewError("apimanagement.ReportsClient", "ListByService", err.Error()) 68 } 69 70 result.fn = client.listByServiceNextResults 71 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, aggregation, filter, top, skip, interval) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByService", nil, "Failure preparing request") 74 return 75 } 76 77 resp, err := client.ListByServiceSender(req) 78 if err != nil { 79 result.rc.Response = autorest.Response{Response: resp} 80 err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByService", resp, "Failure sending request") 81 return 82 } 83 84 result.rc, err = client.ListByServiceResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "ListByService", resp, "Failure responding to request") 87 } 88 89 return 90} 91 92// ListByServicePreparer prepares the ListByService request. 93func (client ReportsClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, aggregation ReportsAggregation, filter string, top *int32, skip *int32, interval string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "aggregation": autorest.Encode("path", aggregation), 96 "resourceGroupName": autorest.Encode("path", resourceGroupName), 97 "serviceName": autorest.Encode("path", serviceName), 98 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 99 } 100 101 const APIVersion = "2016-07-07" 102 queryParameters := map[string]interface{}{ 103 "api-version": APIVersion, 104 } 105 if len(filter) > 0 { 106 queryParameters["$filter"] = autorest.Encode("query", filter) 107 } 108 if top != nil { 109 queryParameters["$top"] = autorest.Encode("query", *top) 110 } 111 if skip != nil { 112 queryParameters["$skip"] = autorest.Encode("query", *skip) 113 } 114 if len(interval) > 0 { 115 queryParameters["interval"] = autorest.Encode("query", interval) 116 } 117 118 preparer := autorest.CreatePreparer( 119 autorest.AsGet(), 120 autorest.WithBaseURL(client.BaseURI), 121 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/{aggregation}", pathParameters), 122 autorest.WithQueryParameters(queryParameters)) 123 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 124} 125 126// ListByServiceSender sends the ListByService request. The method will close the 127// http.Response Body if it receives an error. 128func (client ReportsClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 129 return autorest.SendWithSender(client, req, 130 azure.DoRetryWithRegistration(client.Client)) 131} 132 133// ListByServiceResponder handles the response to the ListByService request. The method always 134// closes the http.Response Body. 135func (client ReportsClient) ListByServiceResponder(resp *http.Response) (result ReportCollection, err error) { 136 err = autorest.Respond( 137 resp, 138 client.ByInspecting(), 139 azure.WithErrorUnlessStatusCode(http.StatusOK), 140 autorest.ByUnmarshallingJSON(&result), 141 autorest.ByClosing()) 142 result.Response = autorest.Response{Response: resp} 143 return 144} 145 146// listByServiceNextResults retrieves the next set of results, if any. 147func (client ReportsClient) listByServiceNextResults(lastResults ReportCollection) (result ReportCollection, err error) { 148 req, err := lastResults.reportCollectionPreparer() 149 if err != nil { 150 return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByServiceNextResults", nil, "Failure preparing next results request") 151 } 152 if req == nil { 153 return 154 } 155 resp, err := client.ListByServiceSender(req) 156 if err != nil { 157 result.Response = autorest.Response{Response: resp} 158 return result, autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByServiceNextResults", resp, "Failure sending next results request") 159 } 160 result, err = client.ListByServiceResponder(resp) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "apimanagement.ReportsClient", "listByServiceNextResults", resp, "Failure responding to next results request") 163 } 164 return 165} 166 167// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 168func (client ReportsClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, aggregation ReportsAggregation, filter string, top *int32, skip *int32, interval string) (result ReportCollectionIterator, err error) { 169 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, aggregation, filter, top, skip, interval) 170 return 171} 172