1package apimanagement 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 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// UserSubscriptionClient is the client for the UserSubscription methods of the Apimanagement service. 19type UserSubscriptionClient struct { 20 BaseClient 21} 22 23// NewUserSubscriptionClient creates an instance of the UserSubscriptionClient client. 24func NewUserSubscriptionClient() UserSubscriptionClient { 25 return UserSubscriptionClient{New()} 26} 27 28// List lists the collection of subscriptions of the specified user. 29// Parameters: 30// apimBaseURL - the management endpoint of the API Management service, for example 31// https://myapimservice.management.azure-api.net. 32// UID - user identifier. Must be unique in the current API Management service instance. 33// filter - | Field | Supported operators | Supported functions | 34// |--------------|------------------------|---------------------------------------------| 35// | id | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 36// | name | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 37// | stateComment | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 38// | userId | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 39// | productId | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 40// | state | eq | | 41// top - number of records to return. 42// skip - number of records to skip. 43func (client UserSubscriptionClient) List(ctx context.Context, apimBaseURL string, UID string, filter string, top *int32, skip *int32) (result SubscriptionCollectionPage, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/UserSubscriptionClient.List") 46 defer func() { 47 sc := -1 48 if result.sc.Response.Response != nil { 49 sc = result.sc.Response.Response.StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 if err := validation.Validate([]validation.Validation{ 55 {TargetValue: UID, 56 Constraints: []validation.Constraint{{Target: "UID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 57 {Target: "UID", Name: validation.MinLength, Rule: 1, Chain: nil}, 58 {Target: "UID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 59 {TargetValue: top, 60 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 61 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 62 {TargetValue: skip, 63 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 64 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 65 return result, validation.NewError("apimanagement.UserSubscriptionClient", "List", err.Error()) 66 } 67 68 result.fn = client.listNextResults 69 req, err := client.ListPreparer(ctx, apimBaseURL, UID, filter, top, skip) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "apimanagement.UserSubscriptionClient", "List", nil, "Failure preparing request") 72 return 73 } 74 75 resp, err := client.ListSender(req) 76 if err != nil { 77 result.sc.Response = autorest.Response{Response: resp} 78 err = autorest.NewErrorWithError(err, "apimanagement.UserSubscriptionClient", "List", resp, "Failure sending request") 79 return 80 } 81 82 result.sc, err = client.ListResponder(resp) 83 if err != nil { 84 err = autorest.NewErrorWithError(err, "apimanagement.UserSubscriptionClient", "List", resp, "Failure responding to request") 85 return 86 } 87 if result.sc.hasNextLink() && result.sc.IsEmpty() { 88 err = result.NextWithContext(ctx) 89 return 90 } 91 92 return 93} 94 95// ListPreparer prepares the List request. 96func (client UserSubscriptionClient) ListPreparer(ctx context.Context, apimBaseURL string, UID string, filter string, top *int32, skip *int32) (*http.Request, error) { 97 urlParameters := map[string]interface{}{ 98 "apimBaseUrl": apimBaseURL, 99 } 100 101 pathParameters := map[string]interface{}{ 102 "uid": autorest.Encode("path", UID), 103 } 104 105 const APIVersion = "2017-03-01" 106 queryParameters := map[string]interface{}{ 107 "api-version": APIVersion, 108 } 109 if len(filter) > 0 { 110 queryParameters["$filter"] = autorest.Encode("query", filter) 111 } 112 if top != nil { 113 queryParameters["$top"] = autorest.Encode("query", *top) 114 } 115 if skip != nil { 116 queryParameters["$skip"] = autorest.Encode("query", *skip) 117 } 118 119 preparer := autorest.CreatePreparer( 120 autorest.AsGet(), 121 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 122 autorest.WithPathParameters("/users/{uid}/subscriptions", pathParameters), 123 autorest.WithQueryParameters(queryParameters)) 124 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 125} 126 127// ListSender sends the List request. The method will close the 128// http.Response Body if it receives an error. 129func (client UserSubscriptionClient) ListSender(req *http.Request) (*http.Response, error) { 130 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 131} 132 133// ListResponder handles the response to the List request. The method always 134// closes the http.Response Body. 135func (client UserSubscriptionClient) ListResponder(resp *http.Response) (result SubscriptionCollection, err error) { 136 err = autorest.Respond( 137 resp, 138 azure.WithErrorUnlessStatusCode(http.StatusOK), 139 autorest.ByUnmarshallingJSON(&result), 140 autorest.ByClosing()) 141 result.Response = autorest.Response{Response: resp} 142 return 143} 144 145// listNextResults retrieves the next set of results, if any. 146func (client UserSubscriptionClient) listNextResults(ctx context.Context, lastResults SubscriptionCollection) (result SubscriptionCollection, err error) { 147 req, err := lastResults.subscriptionCollectionPreparer(ctx) 148 if err != nil { 149 return result, autorest.NewErrorWithError(err, "apimanagement.UserSubscriptionClient", "listNextResults", nil, "Failure preparing next results request") 150 } 151 if req == nil { 152 return 153 } 154 resp, err := client.ListSender(req) 155 if err != nil { 156 result.Response = autorest.Response{Response: resp} 157 return result, autorest.NewErrorWithError(err, "apimanagement.UserSubscriptionClient", "listNextResults", resp, "Failure sending next results request") 158 } 159 result, err = client.ListResponder(resp) 160 if err != nil { 161 err = autorest.NewErrorWithError(err, "apimanagement.UserSubscriptionClient", "listNextResults", resp, "Failure responding to next results request") 162 } 163 return 164} 165 166// ListComplete enumerates all values, automatically crossing page boundaries as required. 167func (client UserSubscriptionClient) ListComplete(ctx context.Context, apimBaseURL string, UID string, filter string, top *int32, skip *int32) (result SubscriptionCollectionIterator, err error) { 168 if tracing.IsEnabled() { 169 ctx = tracing.StartSpan(ctx, fqdn+"/UserSubscriptionClient.List") 170 defer func() { 171 sc := -1 172 if result.Response().Response.Response != nil { 173 sc = result.page.Response().Response.Response.StatusCode 174 } 175 tracing.EndSpan(ctx, sc, err) 176 }() 177 } 178 result.page, err = client.List(ctx, apimBaseURL, UID, filter, top, skip) 179 return 180} 181