...

Source file src/github.com/Azure/azure-sdk-for-go/services/mediaservices/mgmt/2020-05-01/media/liveoutputs.go

Documentation: github.com/Azure/azure-sdk-for-go/services/mediaservices/mgmt/2020-05-01/media

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

View as plain text