1package databoxedge 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// OrdersClient is the client for the Orders methods of the Databoxedge service. 19type OrdersClient struct { 20 BaseClient 21} 22 23// NewOrdersClient creates an instance of the OrdersClient client. 24func NewOrdersClient(subscriptionID string) OrdersClient { 25 return NewOrdersClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewOrdersClientWithBaseURI creates an instance of the OrdersClient 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 NewOrdersClientWithBaseURI(baseURI string, subscriptionID string) OrdersClient { 31 return OrdersClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate sends the create or update request. 35// Parameters: 36// deviceName - the device name. 37// order - the order to be created or updated. 38// resourceGroupName - the resource group name. 39func (client OrdersClient) CreateOrUpdate(ctx context.Context, deviceName string, order Order, resourceGroupName string) (result OrdersCreateOrUpdateFuture, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.CreateOrUpdate") 42 defer func() { 43 sc := -1 44 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 45 sc = result.FutureAPI.Response().StatusCode 46 } 47 tracing.EndSpan(ctx, sc, err) 48 }() 49 } 50 if err := validation.Validate([]validation.Validation{ 51 {TargetValue: order, 52 Constraints: []validation.Constraint{{Target: "order.OrderProperties", Name: validation.Null, Rule: false, 53 Chain: []validation.Constraint{{Target: "order.OrderProperties.ContactInformation", Name: validation.Null, Rule: true, 54 Chain: []validation.Constraint{{Target: "order.OrderProperties.ContactInformation.ContactPerson", Name: validation.Null, Rule: true, Chain: nil}, 55 {Target: "order.OrderProperties.ContactInformation.CompanyName", Name: validation.Null, Rule: true, Chain: nil}, 56 {Target: "order.OrderProperties.ContactInformation.Phone", Name: validation.Null, Rule: true, Chain: nil}, 57 {Target: "order.OrderProperties.ContactInformation.EmailList", Name: validation.Null, Rule: true, Chain: nil}, 58 }}, 59 {Target: "order.OrderProperties.ShippingAddress", Name: validation.Null, Rule: true, 60 Chain: []validation.Constraint{{Target: "order.OrderProperties.ShippingAddress.AddressLine1", Name: validation.Null, Rule: true, Chain: nil}, 61 {Target: "order.OrderProperties.ShippingAddress.PostalCode", Name: validation.Null, Rule: true, Chain: nil}, 62 {Target: "order.OrderProperties.ShippingAddress.City", Name: validation.Null, Rule: true, Chain: nil}, 63 {Target: "order.OrderProperties.ShippingAddress.State", Name: validation.Null, Rule: true, Chain: nil}, 64 {Target: "order.OrderProperties.ShippingAddress.Country", Name: validation.Null, Rule: true, Chain: nil}, 65 }}, 66 }}}}}); err != nil { 67 return result, validation.NewError("databoxedge.OrdersClient", "CreateOrUpdate", err.Error()) 68 } 69 70 req, err := client.CreateOrUpdatePreparer(ctx, deviceName, order, resourceGroupName) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "CreateOrUpdate", nil, "Failure preparing request") 73 return 74 } 75 76 result, err = client.CreateOrUpdateSender(req) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "CreateOrUpdate", nil, "Failure sending request") 79 return 80 } 81 82 return 83} 84 85// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 86func (client OrdersClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, order Order, resourceGroupName string) (*http.Request, error) { 87 pathParameters := map[string]interface{}{ 88 "deviceName": autorest.Encode("path", deviceName), 89 "resourceGroupName": autorest.Encode("path", resourceGroupName), 90 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 91 } 92 93 const APIVersion = "2019-07-01" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsContentType("application/json; charset=utf-8"), 100 autorest.AsPut(), 101 autorest.WithBaseURL(client.BaseURI), 102 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders/default", pathParameters), 103 autorest.WithJSON(order), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 109// http.Response Body if it receives an error. 110func (client OrdersClient) CreateOrUpdateSender(req *http.Request) (future OrdersCreateOrUpdateFuture, err error) { 111 var resp *http.Response 112 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113 if err != nil { 114 return 115 } 116 var azf azure.Future 117 azf, err = azure.NewFutureFromResponse(resp) 118 future.FutureAPI = &azf 119 future.Result = future.result 120 return 121} 122 123// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 124// closes the http.Response Body. 125func (client OrdersClient) CreateOrUpdateResponder(resp *http.Response) (result Order, err error) { 126 err = autorest.Respond( 127 resp, 128 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 129 autorest.ByUnmarshallingJSON(&result), 130 autorest.ByClosing()) 131 result.Response = autorest.Response{Response: resp} 132 return 133} 134 135// Delete sends the delete request. 136// Parameters: 137// deviceName - the device name. 138// resourceGroupName - the resource group name. 139func (client OrdersClient) Delete(ctx context.Context, deviceName string, resourceGroupName string) (result OrdersDeleteFuture, err error) { 140 if tracing.IsEnabled() { 141 ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.Delete") 142 defer func() { 143 sc := -1 144 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 145 sc = result.FutureAPI.Response().StatusCode 146 } 147 tracing.EndSpan(ctx, sc, err) 148 }() 149 } 150 req, err := client.DeletePreparer(ctx, deviceName, resourceGroupName) 151 if err != nil { 152 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Delete", nil, "Failure preparing request") 153 return 154 } 155 156 result, err = client.DeleteSender(req) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Delete", nil, "Failure sending request") 159 return 160 } 161 162 return 163} 164 165// DeletePreparer prepares the Delete request. 166func (client OrdersClient) DeletePreparer(ctx context.Context, deviceName string, resourceGroupName string) (*http.Request, error) { 167 pathParameters := map[string]interface{}{ 168 "deviceName": autorest.Encode("path", deviceName), 169 "resourceGroupName": autorest.Encode("path", resourceGroupName), 170 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 171 } 172 173 const APIVersion = "2019-07-01" 174 queryParameters := map[string]interface{}{ 175 "api-version": APIVersion, 176 } 177 178 preparer := autorest.CreatePreparer( 179 autorest.AsDelete(), 180 autorest.WithBaseURL(client.BaseURI), 181 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders/default", pathParameters), 182 autorest.WithQueryParameters(queryParameters)) 183 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 184} 185 186// DeleteSender sends the Delete request. The method will close the 187// http.Response Body if it receives an error. 188func (client OrdersClient) DeleteSender(req *http.Request) (future OrdersDeleteFuture, err error) { 189 var resp *http.Response 190 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 191 if err != nil { 192 return 193 } 194 var azf azure.Future 195 azf, err = azure.NewFutureFromResponse(resp) 196 future.FutureAPI = &azf 197 future.Result = future.result 198 return 199} 200 201// DeleteResponder handles the response to the Delete request. The method always 202// closes the http.Response Body. 203func (client OrdersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 204 err = autorest.Respond( 205 resp, 206 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 207 autorest.ByClosing()) 208 result.Response = resp 209 return 210} 211 212// Get sends the get request. 213// Parameters: 214// deviceName - the device name. 215// resourceGroupName - the resource group name. 216func (client OrdersClient) Get(ctx context.Context, deviceName string, resourceGroupName string) (result Order, err error) { 217 if tracing.IsEnabled() { 218 ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.Get") 219 defer func() { 220 sc := -1 221 if result.Response.Response != nil { 222 sc = result.Response.Response.StatusCode 223 } 224 tracing.EndSpan(ctx, sc, err) 225 }() 226 } 227 req, err := client.GetPreparer(ctx, deviceName, resourceGroupName) 228 if err != nil { 229 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Get", nil, "Failure preparing request") 230 return 231 } 232 233 resp, err := client.GetSender(req) 234 if err != nil { 235 result.Response = autorest.Response{Response: resp} 236 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Get", resp, "Failure sending request") 237 return 238 } 239 240 result, err = client.GetResponder(resp) 241 if err != nil { 242 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Get", resp, "Failure responding to request") 243 return 244 } 245 246 return 247} 248 249// GetPreparer prepares the Get request. 250func (client OrdersClient) GetPreparer(ctx context.Context, deviceName string, resourceGroupName string) (*http.Request, error) { 251 pathParameters := map[string]interface{}{ 252 "deviceName": autorest.Encode("path", deviceName), 253 "resourceGroupName": autorest.Encode("path", resourceGroupName), 254 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 255 } 256 257 const APIVersion = "2019-07-01" 258 queryParameters := map[string]interface{}{ 259 "api-version": APIVersion, 260 } 261 262 preparer := autorest.CreatePreparer( 263 autorest.AsGet(), 264 autorest.WithBaseURL(client.BaseURI), 265 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders/default", pathParameters), 266 autorest.WithQueryParameters(queryParameters)) 267 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 268} 269 270// GetSender sends the Get request. The method will close the 271// http.Response Body if it receives an error. 272func (client OrdersClient) GetSender(req *http.Request) (*http.Response, error) { 273 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 274} 275 276// GetResponder handles the response to the Get request. The method always 277// closes the http.Response Body. 278func (client OrdersClient) GetResponder(resp *http.Response) (result Order, err error) { 279 err = autorest.Respond( 280 resp, 281 azure.WithErrorUnlessStatusCode(http.StatusOK), 282 autorest.ByUnmarshallingJSON(&result), 283 autorest.ByClosing()) 284 result.Response = autorest.Response{Response: resp} 285 return 286} 287 288// ListByDataBoxEdgeDevice sends the list by data box edge device request. 289// Parameters: 290// deviceName - the device name. 291// resourceGroupName - the resource group name. 292func (client OrdersClient) ListByDataBoxEdgeDevice(ctx context.Context, deviceName string, resourceGroupName string) (result OrderListPage, err error) { 293 if tracing.IsEnabled() { 294 ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.ListByDataBoxEdgeDevice") 295 defer func() { 296 sc := -1 297 if result.ol.Response.Response != nil { 298 sc = result.ol.Response.Response.StatusCode 299 } 300 tracing.EndSpan(ctx, sc, err) 301 }() 302 } 303 result.fn = client.listByDataBoxEdgeDeviceNextResults 304 req, err := client.ListByDataBoxEdgeDevicePreparer(ctx, deviceName, resourceGroupName) 305 if err != nil { 306 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "ListByDataBoxEdgeDevice", nil, "Failure preparing request") 307 return 308 } 309 310 resp, err := client.ListByDataBoxEdgeDeviceSender(req) 311 if err != nil { 312 result.ol.Response = autorest.Response{Response: resp} 313 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "ListByDataBoxEdgeDevice", resp, "Failure sending request") 314 return 315 } 316 317 result.ol, err = client.ListByDataBoxEdgeDeviceResponder(resp) 318 if err != nil { 319 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "ListByDataBoxEdgeDevice", resp, "Failure responding to request") 320 return 321 } 322 if result.ol.hasNextLink() && result.ol.IsEmpty() { 323 err = result.NextWithContext(ctx) 324 return 325 } 326 327 return 328} 329 330// ListByDataBoxEdgeDevicePreparer prepares the ListByDataBoxEdgeDevice request. 331func (client OrdersClient) ListByDataBoxEdgeDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string) (*http.Request, error) { 332 pathParameters := map[string]interface{}{ 333 "deviceName": autorest.Encode("path", deviceName), 334 "resourceGroupName": autorest.Encode("path", resourceGroupName), 335 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 336 } 337 338 const APIVersion = "2019-07-01" 339 queryParameters := map[string]interface{}{ 340 "api-version": APIVersion, 341 } 342 343 preparer := autorest.CreatePreparer( 344 autorest.AsGet(), 345 autorest.WithBaseURL(client.BaseURI), 346 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders", pathParameters), 347 autorest.WithQueryParameters(queryParameters)) 348 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 349} 350 351// ListByDataBoxEdgeDeviceSender sends the ListByDataBoxEdgeDevice request. The method will close the 352// http.Response Body if it receives an error. 353func (client OrdersClient) ListByDataBoxEdgeDeviceSender(req *http.Request) (*http.Response, error) { 354 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 355} 356 357// ListByDataBoxEdgeDeviceResponder handles the response to the ListByDataBoxEdgeDevice request. The method always 358// closes the http.Response Body. 359func (client OrdersClient) ListByDataBoxEdgeDeviceResponder(resp *http.Response) (result OrderList, err error) { 360 err = autorest.Respond( 361 resp, 362 azure.WithErrorUnlessStatusCode(http.StatusOK), 363 autorest.ByUnmarshallingJSON(&result), 364 autorest.ByClosing()) 365 result.Response = autorest.Response{Response: resp} 366 return 367} 368 369// listByDataBoxEdgeDeviceNextResults retrieves the next set of results, if any. 370func (client OrdersClient) listByDataBoxEdgeDeviceNextResults(ctx context.Context, lastResults OrderList) (result OrderList, err error) { 371 req, err := lastResults.orderListPreparer(ctx) 372 if err != nil { 373 return result, autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "listByDataBoxEdgeDeviceNextResults", nil, "Failure preparing next results request") 374 } 375 if req == nil { 376 return 377 } 378 resp, err := client.ListByDataBoxEdgeDeviceSender(req) 379 if err != nil { 380 result.Response = autorest.Response{Response: resp} 381 return result, autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "listByDataBoxEdgeDeviceNextResults", resp, "Failure sending next results request") 382 } 383 result, err = client.ListByDataBoxEdgeDeviceResponder(resp) 384 if err != nil { 385 err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "listByDataBoxEdgeDeviceNextResults", resp, "Failure responding to next results request") 386 } 387 return 388} 389 390// ListByDataBoxEdgeDeviceComplete enumerates all values, automatically crossing page boundaries as required. 391func (client OrdersClient) ListByDataBoxEdgeDeviceComplete(ctx context.Context, deviceName string, resourceGroupName string) (result OrderListIterator, err error) { 392 if tracing.IsEnabled() { 393 ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.ListByDataBoxEdgeDevice") 394 defer func() { 395 sc := -1 396 if result.Response().Response.Response != nil { 397 sc = result.page.Response().Response.Response.StatusCode 398 } 399 tracing.EndSpan(ctx, sc, err) 400 }() 401 } 402 result.page, err = client.ListByDataBoxEdgeDevice(ctx, deviceName, resourceGroupName) 403 return 404} 405