1package databox 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// ServiceClient is the client for the Service methods of the Databox service. 19type ServiceClient struct { 20 BaseClient 21} 22 23// NewServiceClient creates an instance of the ServiceClient client. 24func NewServiceClient(subscriptionID string) ServiceClient { 25 return NewServiceClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewServiceClientWithBaseURI creates an instance of the ServiceClient client using a custom endpoint. Use this when 29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewServiceClientWithBaseURI(baseURI string, subscriptionID string) ServiceClient { 31 return ServiceClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// ListAvailableSkus this method provides the list of available skus for the given subscription and location. 35// Parameters: 36// location - the location of the resource 37// availableSkuRequest - filters for showing the available skus. 38func (client ServiceClient) ListAvailableSkus(ctx context.Context, location string, availableSkuRequest AvailableSkuRequest) (result AvailableSkusResultPage, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.ListAvailableSkus") 41 defer func() { 42 sc := -1 43 if result.asr.Response.Response != nil { 44 sc = result.asr.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 if err := validation.Validate([]validation.Validation{ 50 {TargetValue: availableSkuRequest, 51 Constraints: []validation.Constraint{{Target: "availableSkuRequest.TransferType", Name: validation.Null, Rule: true, Chain: nil}, 52 {Target: "availableSkuRequest.Country", Name: validation.Null, Rule: true, Chain: nil}, 53 {Target: "availableSkuRequest.Location", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 54 return result, validation.NewError("databox.ServiceClient", "ListAvailableSkus", err.Error()) 55 } 56 57 result.fn = client.listAvailableSkusNextResults 58 req, err := client.ListAvailableSkusPreparer(ctx, location, availableSkuRequest) 59 if err != nil { 60 err = autorest.NewErrorWithError(err, "databox.ServiceClient", "ListAvailableSkus", nil, "Failure preparing request") 61 return 62 } 63 64 resp, err := client.ListAvailableSkusSender(req) 65 if err != nil { 66 result.asr.Response = autorest.Response{Response: resp} 67 err = autorest.NewErrorWithError(err, "databox.ServiceClient", "ListAvailableSkus", resp, "Failure sending request") 68 return 69 } 70 71 result.asr, err = client.ListAvailableSkusResponder(resp) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "databox.ServiceClient", "ListAvailableSkus", resp, "Failure responding to request") 74 return 75 } 76 if result.asr.hasNextLink() && result.asr.IsEmpty() { 77 err = result.NextWithContext(ctx) 78 return 79 } 80 81 return 82} 83 84// ListAvailableSkusPreparer prepares the ListAvailableSkus request. 85func (client ServiceClient) ListAvailableSkusPreparer(ctx context.Context, location string, availableSkuRequest AvailableSkuRequest) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "location": autorest.Encode("path", location), 88 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 89 } 90 91 const APIVersion = "2018-01-01" 92 queryParameters := map[string]interface{}{ 93 "api-version": APIVersion, 94 } 95 96 preparer := autorest.CreatePreparer( 97 autorest.AsContentType("application/json; charset=utf-8"), 98 autorest.AsPost(), 99 autorest.WithBaseURL(client.BaseURI), 100 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DataBox/locations/{location}/availableSkus", pathParameters), 101 autorest.WithJSON(availableSkuRequest), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// ListAvailableSkusSender sends the ListAvailableSkus request. The method will close the 107// http.Response Body if it receives an error. 108func (client ServiceClient) ListAvailableSkusSender(req *http.Request) (*http.Response, error) { 109 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110} 111 112// ListAvailableSkusResponder handles the response to the ListAvailableSkus request. The method always 113// closes the http.Response Body. 114func (client ServiceClient) ListAvailableSkusResponder(resp *http.Response) (result AvailableSkusResult, err error) { 115 err = autorest.Respond( 116 resp, 117 azure.WithErrorUnlessStatusCode(http.StatusOK), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// listAvailableSkusNextResults retrieves the next set of results, if any. 125func (client ServiceClient) listAvailableSkusNextResults(ctx context.Context, lastResults AvailableSkusResult) (result AvailableSkusResult, err error) { 126 req, err := lastResults.availableSkusResultPreparer(ctx) 127 if err != nil { 128 return result, autorest.NewErrorWithError(err, "databox.ServiceClient", "listAvailableSkusNextResults", nil, "Failure preparing next results request") 129 } 130 if req == nil { 131 return 132 } 133 resp, err := client.ListAvailableSkusSender(req) 134 if err != nil { 135 result.Response = autorest.Response{Response: resp} 136 return result, autorest.NewErrorWithError(err, "databox.ServiceClient", "listAvailableSkusNextResults", resp, "Failure sending next results request") 137 } 138 result, err = client.ListAvailableSkusResponder(resp) 139 if err != nil { 140 err = autorest.NewErrorWithError(err, "databox.ServiceClient", "listAvailableSkusNextResults", resp, "Failure responding to next results request") 141 } 142 return 143} 144 145// ListAvailableSkusComplete enumerates all values, automatically crossing page boundaries as required. 146func (client ServiceClient) ListAvailableSkusComplete(ctx context.Context, location string, availableSkuRequest AvailableSkuRequest) (result AvailableSkusResultIterator, err error) { 147 if tracing.IsEnabled() { 148 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.ListAvailableSkus") 149 defer func() { 150 sc := -1 151 if result.Response().Response.Response != nil { 152 sc = result.page.Response().Response.Response.StatusCode 153 } 154 tracing.EndSpan(ctx, sc, err) 155 }() 156 } 157 result.page, err = client.ListAvailableSkus(ctx, location, availableSkuRequest) 158 return 159} 160 161// ValidateAddressMethod this method validates the customer shipping address and provide alternate addresses if any. 162// Parameters: 163// location - the location of the resource 164// validateAddress - shipping address of the customer. 165func (client ServiceClient) ValidateAddressMethod(ctx context.Context, location string, validateAddress ValidateAddress) (result AddressValidationOutput, err error) { 166 if tracing.IsEnabled() { 167 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.ValidateAddressMethod") 168 defer func() { 169 sc := -1 170 if result.Response.Response != nil { 171 sc = result.Response.Response.StatusCode 172 } 173 tracing.EndSpan(ctx, sc, err) 174 }() 175 } 176 if err := validation.Validate([]validation.Validation{ 177 {TargetValue: validateAddress, 178 Constraints: []validation.Constraint{{Target: "validateAddress.ShippingAddress", Name: validation.Null, Rule: true, 179 Chain: []validation.Constraint{{Target: "validateAddress.ShippingAddress.StreetAddress1", Name: validation.Null, Rule: true, Chain: nil}, 180 {Target: "validateAddress.ShippingAddress.Country", Name: validation.Null, Rule: true, Chain: nil}, 181 {Target: "validateAddress.ShippingAddress.PostalCode", Name: validation.Null, Rule: true, Chain: nil}, 182 }}}}}); err != nil { 183 return result, validation.NewError("databox.ServiceClient", "ValidateAddressMethod", err.Error()) 184 } 185 186 req, err := client.ValidateAddressMethodPreparer(ctx, location, validateAddress) 187 if err != nil { 188 err = autorest.NewErrorWithError(err, "databox.ServiceClient", "ValidateAddressMethod", nil, "Failure preparing request") 189 return 190 } 191 192 resp, err := client.ValidateAddressMethodSender(req) 193 if err != nil { 194 result.Response = autorest.Response{Response: resp} 195 err = autorest.NewErrorWithError(err, "databox.ServiceClient", "ValidateAddressMethod", resp, "Failure sending request") 196 return 197 } 198 199 result, err = client.ValidateAddressMethodResponder(resp) 200 if err != nil { 201 err = autorest.NewErrorWithError(err, "databox.ServiceClient", "ValidateAddressMethod", resp, "Failure responding to request") 202 return 203 } 204 205 return 206} 207 208// ValidateAddressMethodPreparer prepares the ValidateAddressMethod request. 209func (client ServiceClient) ValidateAddressMethodPreparer(ctx context.Context, location string, validateAddress ValidateAddress) (*http.Request, error) { 210 pathParameters := map[string]interface{}{ 211 "location": autorest.Encode("path", location), 212 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 213 } 214 215 const APIVersion = "2018-01-01" 216 queryParameters := map[string]interface{}{ 217 "api-version": APIVersion, 218 } 219 220 preparer := autorest.CreatePreparer( 221 autorest.AsContentType("application/json; charset=utf-8"), 222 autorest.AsPost(), 223 autorest.WithBaseURL(client.BaseURI), 224 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DataBox/locations/{location}/validateAddress", pathParameters), 225 autorest.WithJSON(validateAddress), 226 autorest.WithQueryParameters(queryParameters)) 227 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 228} 229 230// ValidateAddressMethodSender sends the ValidateAddressMethod request. The method will close the 231// http.Response Body if it receives an error. 232func (client ServiceClient) ValidateAddressMethodSender(req *http.Request) (*http.Response, error) { 233 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 234} 235 236// ValidateAddressMethodResponder handles the response to the ValidateAddressMethod request. The method always 237// closes the http.Response Body. 238func (client ServiceClient) ValidateAddressMethodResponder(resp *http.Response) (result AddressValidationOutput, err error) { 239 err = autorest.Respond( 240 resp, 241 azure.WithErrorUnlessStatusCode(http.StatusOK), 242 autorest.ByUnmarshallingJSON(&result), 243 autorest.ByClosing()) 244 result.Response = autorest.Response{Response: resp} 245 return 246} 247