1package media 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// TransformsClient is the client for the Transforms methods of the Media service. 19type TransformsClient struct { 20 BaseClient 21} 22 23// NewTransformsClient creates an instance of the TransformsClient client. 24func NewTransformsClient(subscriptionID string) TransformsClient { 25 return NewTransformsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewTransformsClientWithBaseURI creates an instance of the TransformsClient client using a custom endpoint. Use this 29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewTransformsClientWithBaseURI(baseURI string, subscriptionID string) TransformsClient { 31 return TransformsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate creates or updates a new Transform. 35// Parameters: 36// resourceGroupName - the name of the resource group within the Azure subscription. 37// accountName - the Media Services account name. 38// transformName - the Transform name. 39// parameters - the request parameters 40func (client TransformsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, accountName string, transformName string, parameters Transform) (result Transform, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/TransformsClient.CreateOrUpdate") 43 defer func() { 44 sc := -1 45 if result.Response.Response != nil { 46 sc = result.Response.Response.StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: parameters, 53 Constraints: []validation.Constraint{{Target: "parameters.TransformProperties", Name: validation.Null, Rule: false, 54 Chain: []validation.Constraint{{Target: "parameters.TransformProperties.Outputs", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 55 return result, validation.NewError("media.TransformsClient", "CreateOrUpdate", err.Error()) 56 } 57 58 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, accountName, transformName, parameters) 59 if err != nil { 60 err = autorest.NewErrorWithError(err, "media.TransformsClient", "CreateOrUpdate", nil, "Failure preparing request") 61 return 62 } 63 64 resp, err := client.CreateOrUpdateSender(req) 65 if err != nil { 66 result.Response = autorest.Response{Response: resp} 67 err = autorest.NewErrorWithError(err, "media.TransformsClient", "CreateOrUpdate", resp, "Failure sending request") 68 return 69 } 70 71 result, err = client.CreateOrUpdateResponder(resp) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "media.TransformsClient", "CreateOrUpdate", resp, "Failure responding to request") 74 return 75 } 76 77 return 78} 79 80// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 81func (client TransformsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, parameters Transform) (*http.Request, error) { 82 pathParameters := map[string]interface{}{ 83 "accountName": autorest.Encode("path", accountName), 84 "resourceGroupName": autorest.Encode("path", resourceGroupName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 "transformName": autorest.Encode("path", transformName), 87 } 88 89 const APIVersion = "2018-06-01-preview" 90 queryParameters := map[string]interface{}{ 91 "api-version": APIVersion, 92 } 93 94 preparer := autorest.CreatePreparer( 95 autorest.AsContentType("application/json; charset=utf-8"), 96 autorest.AsPut(), 97 autorest.WithBaseURL(client.BaseURI), 98 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}", pathParameters), 99 autorest.WithJSON(parameters), 100 autorest.WithQueryParameters(queryParameters)) 101 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 102} 103 104// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 105// http.Response Body if it receives an error. 106func (client TransformsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 107 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 108} 109 110// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 111// closes the http.Response Body. 112func (client TransformsClient) CreateOrUpdateResponder(resp *http.Response) (result Transform, err error) { 113 err = autorest.Respond( 114 resp, 115 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 116 autorest.ByUnmarshallingJSON(&result), 117 autorest.ByClosing()) 118 result.Response = autorest.Response{Response: resp} 119 return 120} 121 122// Delete deletes a Transform. 123// Parameters: 124// resourceGroupName - the name of the resource group within the Azure subscription. 125// accountName - the Media Services account name. 126// transformName - the Transform name. 127func (client TransformsClient) Delete(ctx context.Context, resourceGroupName string, accountName string, transformName string) (result autorest.Response, err error) { 128 if tracing.IsEnabled() { 129 ctx = tracing.StartSpan(ctx, fqdn+"/TransformsClient.Delete") 130 defer func() { 131 sc := -1 132 if result.Response != nil { 133 sc = result.Response.StatusCode 134 } 135 tracing.EndSpan(ctx, sc, err) 136 }() 137 } 138 req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, transformName) 139 if err != nil { 140 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Delete", nil, "Failure preparing request") 141 return 142 } 143 144 resp, err := client.DeleteSender(req) 145 if err != nil { 146 result.Response = resp 147 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Delete", resp, "Failure sending request") 148 return 149 } 150 151 result, err = client.DeleteResponder(resp) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Delete", resp, "Failure responding to request") 154 return 155 } 156 157 return 158} 159 160// DeletePreparer prepares the Delete request. 161func (client TransformsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string) (*http.Request, error) { 162 pathParameters := map[string]interface{}{ 163 "accountName": autorest.Encode("path", accountName), 164 "resourceGroupName": autorest.Encode("path", resourceGroupName), 165 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 166 "transformName": autorest.Encode("path", transformName), 167 } 168 169 const APIVersion = "2018-06-01-preview" 170 queryParameters := map[string]interface{}{ 171 "api-version": APIVersion, 172 } 173 174 preparer := autorest.CreatePreparer( 175 autorest.AsDelete(), 176 autorest.WithBaseURL(client.BaseURI), 177 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}", pathParameters), 178 autorest.WithQueryParameters(queryParameters)) 179 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 180} 181 182// DeleteSender sends the Delete request. The method will close the 183// http.Response Body if it receives an error. 184func (client TransformsClient) DeleteSender(req *http.Request) (*http.Response, error) { 185 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 186} 187 188// DeleteResponder handles the response to the Delete request. The method always 189// closes the http.Response Body. 190func (client TransformsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 191 err = autorest.Respond( 192 resp, 193 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 194 autorest.ByClosing()) 195 result.Response = resp 196 return 197} 198 199// Get gets a Transform. 200// Parameters: 201// resourceGroupName - the name of the resource group within the Azure subscription. 202// accountName - the Media Services account name. 203// transformName - the Transform name. 204func (client TransformsClient) Get(ctx context.Context, resourceGroupName string, accountName string, transformName string) (result Transform, err error) { 205 if tracing.IsEnabled() { 206 ctx = tracing.StartSpan(ctx, fqdn+"/TransformsClient.Get") 207 defer func() { 208 sc := -1 209 if result.Response.Response != nil { 210 sc = result.Response.Response.StatusCode 211 } 212 tracing.EndSpan(ctx, sc, err) 213 }() 214 } 215 req, err := client.GetPreparer(ctx, resourceGroupName, accountName, transformName) 216 if err != nil { 217 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Get", nil, "Failure preparing request") 218 return 219 } 220 221 resp, err := client.GetSender(req) 222 if err != nil { 223 result.Response = autorest.Response{Response: resp} 224 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Get", resp, "Failure sending request") 225 return 226 } 227 228 result, err = client.GetResponder(resp) 229 if err != nil { 230 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Get", resp, "Failure responding to request") 231 return 232 } 233 234 return 235} 236 237// GetPreparer prepares the Get request. 238func (client TransformsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string) (*http.Request, error) { 239 pathParameters := map[string]interface{}{ 240 "accountName": autorest.Encode("path", accountName), 241 "resourceGroupName": autorest.Encode("path", resourceGroupName), 242 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 243 "transformName": autorest.Encode("path", transformName), 244 } 245 246 const APIVersion = "2018-06-01-preview" 247 queryParameters := map[string]interface{}{ 248 "api-version": APIVersion, 249 } 250 251 preparer := autorest.CreatePreparer( 252 autorest.AsGet(), 253 autorest.WithBaseURL(client.BaseURI), 254 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}", pathParameters), 255 autorest.WithQueryParameters(queryParameters)) 256 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 257} 258 259// GetSender sends the Get request. The method will close the 260// http.Response Body if it receives an error. 261func (client TransformsClient) GetSender(req *http.Request) (*http.Response, error) { 262 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 263} 264 265// GetResponder handles the response to the Get request. The method always 266// closes the http.Response Body. 267func (client TransformsClient) GetResponder(resp *http.Response) (result Transform, err error) { 268 err = autorest.Respond( 269 resp, 270 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound), 271 autorest.ByUnmarshallingJSON(&result), 272 autorest.ByClosing()) 273 result.Response = autorest.Response{Response: resp} 274 return 275} 276 277// List lists the Transforms in the account. 278// Parameters: 279// resourceGroupName - the name of the resource group within the Azure subscription. 280// accountName - the Media Services account name. 281// filter - restricts the set of items returned. 282// top - specifies a non-negative integer n that limits the number of items returned from a collection. The 283// service returns the number of available items up to but not greater than the specified value n. 284// skip - specifies a non-negative integer n that excludes the first n items of the queried collection from the 285// result. The service returns items starting at position n+1. 286func (client TransformsClient) List(ctx context.Context, resourceGroupName string, accountName string, filter string, top *int32, skip *int32) (result TransformCollectionPage, err error) { 287 if tracing.IsEnabled() { 288 ctx = tracing.StartSpan(ctx, fqdn+"/TransformsClient.List") 289 defer func() { 290 sc := -1 291 if result.tc.Response.Response != nil { 292 sc = result.tc.Response.Response.StatusCode 293 } 294 tracing.EndSpan(ctx, sc, err) 295 }() 296 } 297 result.fn = client.listNextResults 298 req, err := client.ListPreparer(ctx, resourceGroupName, accountName, filter, top, skip) 299 if err != nil { 300 err = autorest.NewErrorWithError(err, "media.TransformsClient", "List", nil, "Failure preparing request") 301 return 302 } 303 304 resp, err := client.ListSender(req) 305 if err != nil { 306 result.tc.Response = autorest.Response{Response: resp} 307 err = autorest.NewErrorWithError(err, "media.TransformsClient", "List", resp, "Failure sending request") 308 return 309 } 310 311 result.tc, err = client.ListResponder(resp) 312 if err != nil { 313 err = autorest.NewErrorWithError(err, "media.TransformsClient", "List", resp, "Failure responding to request") 314 return 315 } 316 if result.tc.hasNextLink() && result.tc.IsEmpty() { 317 err = result.NextWithContext(ctx) 318 return 319 } 320 321 return 322} 323 324// ListPreparer prepares the List request. 325func (client TransformsClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string, filter string, top *int32, skip *int32) (*http.Request, error) { 326 pathParameters := map[string]interface{}{ 327 "accountName": autorest.Encode("path", accountName), 328 "resourceGroupName": autorest.Encode("path", resourceGroupName), 329 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 330 } 331 332 const APIVersion = "2018-06-01-preview" 333 queryParameters := map[string]interface{}{ 334 "api-version": APIVersion, 335 } 336 if len(filter) > 0 { 337 queryParameters["$filter"] = autorest.Encode("query", filter) 338 } 339 if top != nil { 340 queryParameters["$top"] = autorest.Encode("query", *top) 341 } 342 if skip != nil { 343 queryParameters["$skip"] = autorest.Encode("query", *skip) 344 } 345 346 preparer := autorest.CreatePreparer( 347 autorest.AsGet(), 348 autorest.WithBaseURL(client.BaseURI), 349 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms", pathParameters), 350 autorest.WithQueryParameters(queryParameters)) 351 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 352} 353 354// ListSender sends the List request. The method will close the 355// http.Response Body if it receives an error. 356func (client TransformsClient) ListSender(req *http.Request) (*http.Response, error) { 357 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 358} 359 360// ListResponder handles the response to the List request. The method always 361// closes the http.Response Body. 362func (client TransformsClient) ListResponder(resp *http.Response) (result TransformCollection, err error) { 363 err = autorest.Respond( 364 resp, 365 azure.WithErrorUnlessStatusCode(http.StatusOK), 366 autorest.ByUnmarshallingJSON(&result), 367 autorest.ByClosing()) 368 result.Response = autorest.Response{Response: resp} 369 return 370} 371 372// listNextResults retrieves the next set of results, if any. 373func (client TransformsClient) listNextResults(ctx context.Context, lastResults TransformCollection) (result TransformCollection, err error) { 374 req, err := lastResults.transformCollectionPreparer(ctx) 375 if err != nil { 376 return result, autorest.NewErrorWithError(err, "media.TransformsClient", "listNextResults", nil, "Failure preparing next results request") 377 } 378 if req == nil { 379 return 380 } 381 resp, err := client.ListSender(req) 382 if err != nil { 383 result.Response = autorest.Response{Response: resp} 384 return result, autorest.NewErrorWithError(err, "media.TransformsClient", "listNextResults", resp, "Failure sending next results request") 385 } 386 result, err = client.ListResponder(resp) 387 if err != nil { 388 err = autorest.NewErrorWithError(err, "media.TransformsClient", "listNextResults", resp, "Failure responding to next results request") 389 } 390 return 391} 392 393// ListComplete enumerates all values, automatically crossing page boundaries as required. 394func (client TransformsClient) ListComplete(ctx context.Context, resourceGroupName string, accountName string, filter string, top *int32, skip *int32) (result TransformCollectionIterator, err error) { 395 if tracing.IsEnabled() { 396 ctx = tracing.StartSpan(ctx, fqdn+"/TransformsClient.List") 397 defer func() { 398 sc := -1 399 if result.Response().Response.Response != nil { 400 sc = result.page.Response().Response.Response.StatusCode 401 } 402 tracing.EndSpan(ctx, sc, err) 403 }() 404 } 405 result.page, err = client.List(ctx, resourceGroupName, accountName, filter, top, skip) 406 return 407} 408 409// Update updates a Transform. 410// Parameters: 411// resourceGroupName - the name of the resource group within the Azure subscription. 412// accountName - the Media Services account name. 413// transformName - the Transform name. 414// parameters - the request parameters 415func (client TransformsClient) Update(ctx context.Context, resourceGroupName string, accountName string, transformName string, parameters Transform) (result Transform, err error) { 416 if tracing.IsEnabled() { 417 ctx = tracing.StartSpan(ctx, fqdn+"/TransformsClient.Update") 418 defer func() { 419 sc := -1 420 if result.Response.Response != nil { 421 sc = result.Response.Response.StatusCode 422 } 423 tracing.EndSpan(ctx, sc, err) 424 }() 425 } 426 req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, transformName, parameters) 427 if err != nil { 428 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Update", nil, "Failure preparing request") 429 return 430 } 431 432 resp, err := client.UpdateSender(req) 433 if err != nil { 434 result.Response = autorest.Response{Response: resp} 435 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Update", resp, "Failure sending request") 436 return 437 } 438 439 result, err = client.UpdateResponder(resp) 440 if err != nil { 441 err = autorest.NewErrorWithError(err, "media.TransformsClient", "Update", resp, "Failure responding to request") 442 return 443 } 444 445 return 446} 447 448// UpdatePreparer prepares the Update request. 449func (client TransformsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, transformName string, parameters Transform) (*http.Request, error) { 450 pathParameters := map[string]interface{}{ 451 "accountName": autorest.Encode("path", accountName), 452 "resourceGroupName": autorest.Encode("path", resourceGroupName), 453 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 454 "transformName": autorest.Encode("path", transformName), 455 } 456 457 const APIVersion = "2018-06-01-preview" 458 queryParameters := map[string]interface{}{ 459 "api-version": APIVersion, 460 } 461 462 preparer := autorest.CreatePreparer( 463 autorest.AsContentType("application/json; charset=utf-8"), 464 autorest.AsPatch(), 465 autorest.WithBaseURL(client.BaseURI), 466 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/transforms/{transformName}", pathParameters), 467 autorest.WithJSON(parameters), 468 autorest.WithQueryParameters(queryParameters)) 469 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 470} 471 472// UpdateSender sends the Update request. The method will close the 473// http.Response Body if it receives an error. 474func (client TransformsClient) UpdateSender(req *http.Request) (*http.Response, error) { 475 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 476} 477 478// UpdateResponder handles the response to the Update request. The method always 479// closes the http.Response Body. 480func (client TransformsClient) UpdateResponder(resp *http.Response) (result Transform, err error) { 481 err = autorest.Respond( 482 resp, 483 azure.WithErrorUnlessStatusCode(http.StatusOK), 484 autorest.ByUnmarshallingJSON(&result), 485 autorest.ByClosing()) 486 result.Response = autorest.Response{Response: resp} 487 return 488} 489