...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.0/luis/authoring/versions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.0/luis/authoring

     1  package authoring
     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  	"github.com/gofrs/uuid"
    16  	"net/http"
    17  )
    18  
    19  // VersionsClient is the client for the Versions methods of the Authoring service.
    20  type VersionsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewVersionsClient creates an instance of the VersionsClient client.
    25  func NewVersionsClient(endpoint string) VersionsClient {
    26  	return VersionsClient{New(endpoint)}
    27  }
    28  
    29  // Clone creates a new version from the selected version.
    30  // Parameters:
    31  // appID - the application ID.
    32  // versionID - the version ID.
    33  // versionCloneObject - a model containing the new version ID.
    34  func (client VersionsClient) Clone(ctx context.Context, appID uuid.UUID, versionID string, versionCloneObject TaskUpdateObject) (result String, err error) {
    35  	if tracing.IsEnabled() {
    36  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Clone")
    37  		defer func() {
    38  			sc := -1
    39  			if result.Response.Response != nil {
    40  				sc = result.Response.Response.StatusCode
    41  			}
    42  			tracing.EndSpan(ctx, sc, err)
    43  		}()
    44  	}
    45  	req, err := client.ClonePreparer(ctx, appID, versionID, versionCloneObject)
    46  	if err != nil {
    47  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Clone", nil, "Failure preparing request")
    48  		return
    49  	}
    50  
    51  	resp, err := client.CloneSender(req)
    52  	if err != nil {
    53  		result.Response = autorest.Response{Response: resp}
    54  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Clone", resp, "Failure sending request")
    55  		return
    56  	}
    57  
    58  	result, err = client.CloneResponder(resp)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Clone", resp, "Failure responding to request")
    61  		return
    62  	}
    63  
    64  	return
    65  }
    66  
    67  // ClonePreparer prepares the Clone request.
    68  func (client VersionsClient) ClonePreparer(ctx context.Context, appID uuid.UUID, versionID string, versionCloneObject TaskUpdateObject) (*http.Request, error) {
    69  	urlParameters := map[string]interface{}{
    70  		"Endpoint": client.Endpoint,
    71  	}
    72  
    73  	pathParameters := map[string]interface{}{
    74  		"appId":     autorest.Encode("path", appID),
    75  		"versionId": autorest.Encode("path", versionID),
    76  	}
    77  
    78  	preparer := autorest.CreatePreparer(
    79  		autorest.AsContentType("application/json; charset=utf-8"),
    80  		autorest.AsPost(),
    81  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
    82  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/clone", pathParameters),
    83  		autorest.WithJSON(versionCloneObject))
    84  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    85  }
    86  
    87  // CloneSender sends the Clone request. The method will close the
    88  // http.Response Body if it receives an error.
    89  func (client VersionsClient) CloneSender(req *http.Request) (*http.Response, error) {
    90  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    91  }
    92  
    93  // CloneResponder handles the response to the Clone request. The method always
    94  // closes the http.Response Body.
    95  func (client VersionsClient) CloneResponder(resp *http.Response) (result String, err error) {
    96  	err = autorest.Respond(
    97  		resp,
    98  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
    99  		autorest.ByUnmarshallingJSON(&result.Value),
   100  		autorest.ByClosing())
   101  	result.Response = autorest.Response{Response: resp}
   102  	return
   103  }
   104  
   105  // Delete deletes an application version.
   106  // Parameters:
   107  // appID - the application ID.
   108  // versionID - the version ID.
   109  func (client VersionsClient) Delete(ctx context.Context, appID uuid.UUID, versionID string) (result OperationStatus, err error) {
   110  	if tracing.IsEnabled() {
   111  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Delete")
   112  		defer func() {
   113  			sc := -1
   114  			if result.Response.Response != nil {
   115  				sc = result.Response.Response.StatusCode
   116  			}
   117  			tracing.EndSpan(ctx, sc, err)
   118  		}()
   119  	}
   120  	req, err := client.DeletePreparer(ctx, appID, versionID)
   121  	if err != nil {
   122  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Delete", nil, "Failure preparing request")
   123  		return
   124  	}
   125  
   126  	resp, err := client.DeleteSender(req)
   127  	if err != nil {
   128  		result.Response = autorest.Response{Response: resp}
   129  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Delete", resp, "Failure sending request")
   130  		return
   131  	}
   132  
   133  	result, err = client.DeleteResponder(resp)
   134  	if err != nil {
   135  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Delete", resp, "Failure responding to request")
   136  		return
   137  	}
   138  
   139  	return
   140  }
   141  
   142  // DeletePreparer prepares the Delete request.
   143  func (client VersionsClient) DeletePreparer(ctx context.Context, appID uuid.UUID, versionID string) (*http.Request, error) {
   144  	urlParameters := map[string]interface{}{
   145  		"Endpoint": client.Endpoint,
   146  	}
   147  
   148  	pathParameters := map[string]interface{}{
   149  		"appId":     autorest.Encode("path", appID),
   150  		"versionId": autorest.Encode("path", versionID),
   151  	}
   152  
   153  	preparer := autorest.CreatePreparer(
   154  		autorest.AsDelete(),
   155  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   156  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/", pathParameters))
   157  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   158  }
   159  
   160  // DeleteSender sends the Delete request. The method will close the
   161  // http.Response Body if it receives an error.
   162  func (client VersionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   163  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   164  }
   165  
   166  // DeleteResponder handles the response to the Delete request. The method always
   167  // closes the http.Response Body.
   168  func (client VersionsClient) DeleteResponder(resp *http.Response) (result OperationStatus, err error) {
   169  	err = autorest.Respond(
   170  		resp,
   171  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   172  		autorest.ByUnmarshallingJSON(&result),
   173  		autorest.ByClosing())
   174  	result.Response = autorest.Response{Response: resp}
   175  	return
   176  }
   177  
   178  // DeleteUnlabelledUtterance deleted an unlabelled utterance in a version of the application.
   179  // Parameters:
   180  // appID - the application ID.
   181  // versionID - the version ID.
   182  // utterance - the utterance text to delete.
   183  func (client VersionsClient) DeleteUnlabelledUtterance(ctx context.Context, appID uuid.UUID, versionID string, utterance string) (result OperationStatus, err error) {
   184  	if tracing.IsEnabled() {
   185  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.DeleteUnlabelledUtterance")
   186  		defer func() {
   187  			sc := -1
   188  			if result.Response.Response != nil {
   189  				sc = result.Response.Response.StatusCode
   190  			}
   191  			tracing.EndSpan(ctx, sc, err)
   192  		}()
   193  	}
   194  	req, err := client.DeleteUnlabelledUtterancePreparer(ctx, appID, versionID, utterance)
   195  	if err != nil {
   196  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "DeleteUnlabelledUtterance", nil, "Failure preparing request")
   197  		return
   198  	}
   199  
   200  	resp, err := client.DeleteUnlabelledUtteranceSender(req)
   201  	if err != nil {
   202  		result.Response = autorest.Response{Response: resp}
   203  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "DeleteUnlabelledUtterance", resp, "Failure sending request")
   204  		return
   205  	}
   206  
   207  	result, err = client.DeleteUnlabelledUtteranceResponder(resp)
   208  	if err != nil {
   209  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "DeleteUnlabelledUtterance", resp, "Failure responding to request")
   210  		return
   211  	}
   212  
   213  	return
   214  }
   215  
   216  // DeleteUnlabelledUtterancePreparer prepares the DeleteUnlabelledUtterance request.
   217  func (client VersionsClient) DeleteUnlabelledUtterancePreparer(ctx context.Context, appID uuid.UUID, versionID string, utterance string) (*http.Request, error) {
   218  	urlParameters := map[string]interface{}{
   219  		"Endpoint": client.Endpoint,
   220  	}
   221  
   222  	pathParameters := map[string]interface{}{
   223  		"appId":     autorest.Encode("path", appID),
   224  		"versionId": autorest.Encode("path", versionID),
   225  	}
   226  
   227  	preparer := autorest.CreatePreparer(
   228  		autorest.AsContentType("application/json; charset=utf-8"),
   229  		autorest.AsDelete(),
   230  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   231  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/suggest", pathParameters),
   232  		autorest.WithJSON(utterance))
   233  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   234  }
   235  
   236  // DeleteUnlabelledUtteranceSender sends the DeleteUnlabelledUtterance request. The method will close the
   237  // http.Response Body if it receives an error.
   238  func (client VersionsClient) DeleteUnlabelledUtteranceSender(req *http.Request) (*http.Response, error) {
   239  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   240  }
   241  
   242  // DeleteUnlabelledUtteranceResponder handles the response to the DeleteUnlabelledUtterance request. The method always
   243  // closes the http.Response Body.
   244  func (client VersionsClient) DeleteUnlabelledUtteranceResponder(resp *http.Response) (result OperationStatus, err error) {
   245  	err = autorest.Respond(
   246  		resp,
   247  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   248  		autorest.ByUnmarshallingJSON(&result),
   249  		autorest.ByClosing())
   250  	result.Response = autorest.Response{Response: resp}
   251  	return
   252  }
   253  
   254  // Export exports a LUIS application to JSON format.
   255  // Parameters:
   256  // appID - the application ID.
   257  // versionID - the version ID.
   258  func (client VersionsClient) Export(ctx context.Context, appID uuid.UUID, versionID string) (result LuisApp, err error) {
   259  	if tracing.IsEnabled() {
   260  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Export")
   261  		defer func() {
   262  			sc := -1
   263  			if result.Response.Response != nil {
   264  				sc = result.Response.Response.StatusCode
   265  			}
   266  			tracing.EndSpan(ctx, sc, err)
   267  		}()
   268  	}
   269  	req, err := client.ExportPreparer(ctx, appID, versionID)
   270  	if err != nil {
   271  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Export", nil, "Failure preparing request")
   272  		return
   273  	}
   274  
   275  	resp, err := client.ExportSender(req)
   276  	if err != nil {
   277  		result.Response = autorest.Response{Response: resp}
   278  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Export", resp, "Failure sending request")
   279  		return
   280  	}
   281  
   282  	result, err = client.ExportResponder(resp)
   283  	if err != nil {
   284  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Export", resp, "Failure responding to request")
   285  		return
   286  	}
   287  
   288  	return
   289  }
   290  
   291  // ExportPreparer prepares the Export request.
   292  func (client VersionsClient) ExportPreparer(ctx context.Context, appID uuid.UUID, versionID string) (*http.Request, error) {
   293  	urlParameters := map[string]interface{}{
   294  		"Endpoint": client.Endpoint,
   295  	}
   296  
   297  	pathParameters := map[string]interface{}{
   298  		"appId":     autorest.Encode("path", appID),
   299  		"versionId": autorest.Encode("path", versionID),
   300  	}
   301  
   302  	preparer := autorest.CreatePreparer(
   303  		autorest.AsGet(),
   304  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   305  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/export", pathParameters))
   306  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   307  }
   308  
   309  // ExportSender sends the Export request. The method will close the
   310  // http.Response Body if it receives an error.
   311  func (client VersionsClient) ExportSender(req *http.Request) (*http.Response, error) {
   312  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   313  }
   314  
   315  // ExportResponder handles the response to the Export request. The method always
   316  // closes the http.Response Body.
   317  func (client VersionsClient) ExportResponder(resp *http.Response) (result LuisApp, err error) {
   318  	err = autorest.Respond(
   319  		resp,
   320  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   321  		autorest.ByUnmarshallingJSON(&result),
   322  		autorest.ByClosing())
   323  	result.Response = autorest.Response{Response: resp}
   324  	return
   325  }
   326  
   327  // Get gets the version information such as date created, last modified date, endpoint URL, count of intents and
   328  // entities, training and publishing status.
   329  // Parameters:
   330  // appID - the application ID.
   331  // versionID - the version ID.
   332  func (client VersionsClient) Get(ctx context.Context, appID uuid.UUID, versionID string) (result VersionInfo, err error) {
   333  	if tracing.IsEnabled() {
   334  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Get")
   335  		defer func() {
   336  			sc := -1
   337  			if result.Response.Response != nil {
   338  				sc = result.Response.Response.StatusCode
   339  			}
   340  			tracing.EndSpan(ctx, sc, err)
   341  		}()
   342  	}
   343  	req, err := client.GetPreparer(ctx, appID, versionID)
   344  	if err != nil {
   345  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Get", nil, "Failure preparing request")
   346  		return
   347  	}
   348  
   349  	resp, err := client.GetSender(req)
   350  	if err != nil {
   351  		result.Response = autorest.Response{Response: resp}
   352  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Get", resp, "Failure sending request")
   353  		return
   354  	}
   355  
   356  	result, err = client.GetResponder(resp)
   357  	if err != nil {
   358  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Get", resp, "Failure responding to request")
   359  		return
   360  	}
   361  
   362  	return
   363  }
   364  
   365  // GetPreparer prepares the Get request.
   366  func (client VersionsClient) GetPreparer(ctx context.Context, appID uuid.UUID, versionID string) (*http.Request, error) {
   367  	urlParameters := map[string]interface{}{
   368  		"Endpoint": client.Endpoint,
   369  	}
   370  
   371  	pathParameters := map[string]interface{}{
   372  		"appId":     autorest.Encode("path", appID),
   373  		"versionId": autorest.Encode("path", versionID),
   374  	}
   375  
   376  	preparer := autorest.CreatePreparer(
   377  		autorest.AsGet(),
   378  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   379  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/", pathParameters))
   380  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   381  }
   382  
   383  // GetSender sends the Get request. The method will close the
   384  // http.Response Body if it receives an error.
   385  func (client VersionsClient) GetSender(req *http.Request) (*http.Response, error) {
   386  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   387  }
   388  
   389  // GetResponder handles the response to the Get request. The method always
   390  // closes the http.Response Body.
   391  func (client VersionsClient) GetResponder(resp *http.Response) (result VersionInfo, err error) {
   392  	err = autorest.Respond(
   393  		resp,
   394  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   395  		autorest.ByUnmarshallingJSON(&result),
   396  		autorest.ByClosing())
   397  	result.Response = autorest.Response{Response: resp}
   398  	return
   399  }
   400  
   401  // Import imports a new version into a LUIS application.
   402  // Parameters:
   403  // appID - the application ID.
   404  // luisApp - a LUIS application structure.
   405  // versionID - the new versionId to import. If not specified, the versionId will be read from the imported
   406  // object.
   407  func (client VersionsClient) Import(ctx context.Context, appID uuid.UUID, luisApp LuisApp, versionID string) (result String, err error) {
   408  	if tracing.IsEnabled() {
   409  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Import")
   410  		defer func() {
   411  			sc := -1
   412  			if result.Response.Response != nil {
   413  				sc = result.Response.Response.StatusCode
   414  			}
   415  			tracing.EndSpan(ctx, sc, err)
   416  		}()
   417  	}
   418  	req, err := client.ImportPreparer(ctx, appID, luisApp, versionID)
   419  	if err != nil {
   420  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Import", nil, "Failure preparing request")
   421  		return
   422  	}
   423  
   424  	resp, err := client.ImportSender(req)
   425  	if err != nil {
   426  		result.Response = autorest.Response{Response: resp}
   427  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Import", resp, "Failure sending request")
   428  		return
   429  	}
   430  
   431  	result, err = client.ImportResponder(resp)
   432  	if err != nil {
   433  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Import", resp, "Failure responding to request")
   434  		return
   435  	}
   436  
   437  	return
   438  }
   439  
   440  // ImportPreparer prepares the Import request.
   441  func (client VersionsClient) ImportPreparer(ctx context.Context, appID uuid.UUID, luisApp LuisApp, versionID string) (*http.Request, error) {
   442  	urlParameters := map[string]interface{}{
   443  		"Endpoint": client.Endpoint,
   444  	}
   445  
   446  	pathParameters := map[string]interface{}{
   447  		"appId": autorest.Encode("path", appID),
   448  	}
   449  
   450  	queryParameters := map[string]interface{}{}
   451  	if len(versionID) > 0 {
   452  		queryParameters["versionId"] = autorest.Encode("query", versionID)
   453  	}
   454  
   455  	preparer := autorest.CreatePreparer(
   456  		autorest.AsContentType("application/json; charset=utf-8"),
   457  		autorest.AsPost(),
   458  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   459  		autorest.WithPathParameters("/apps/{appId}/versions/import", pathParameters),
   460  		autorest.WithJSON(luisApp),
   461  		autorest.WithQueryParameters(queryParameters))
   462  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   463  }
   464  
   465  // ImportSender sends the Import request. The method will close the
   466  // http.Response Body if it receives an error.
   467  func (client VersionsClient) ImportSender(req *http.Request) (*http.Response, error) {
   468  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   469  }
   470  
   471  // ImportResponder handles the response to the Import request. The method always
   472  // closes the http.Response Body.
   473  func (client VersionsClient) ImportResponder(resp *http.Response) (result String, err error) {
   474  	err = autorest.Respond(
   475  		resp,
   476  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   477  		autorest.ByUnmarshallingJSON(&result.Value),
   478  		autorest.ByClosing())
   479  	result.Response = autorest.Response{Response: resp}
   480  	return
   481  }
   482  
   483  // List gets a list of versions for this application ID.
   484  // Parameters:
   485  // appID - the application ID.
   486  // skip - the number of entries to skip. Default value is 0.
   487  // take - the number of entries to return. Maximum page size is 500. Default is 100.
   488  func (client VersionsClient) List(ctx context.Context, appID uuid.UUID, skip *int32, take *int32) (result ListVersionInfo, err error) {
   489  	if tracing.IsEnabled() {
   490  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.List")
   491  		defer func() {
   492  			sc := -1
   493  			if result.Response.Response != nil {
   494  				sc = result.Response.Response.StatusCode
   495  			}
   496  			tracing.EndSpan(ctx, sc, err)
   497  		}()
   498  	}
   499  	if err := validation.Validate([]validation.Validation{
   500  		{TargetValue: skip,
   501  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
   502  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}},
   503  		{TargetValue: take,
   504  			Constraints: []validation.Constraint{{Target: "take", Name: validation.Null, Rule: false,
   505  				Chain: []validation.Constraint{{Target: "take", Name: validation.InclusiveMaximum, Rule: int64(500), Chain: nil},
   506  					{Target: "take", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
   507  				}}}}}); err != nil {
   508  		return result, validation.NewError("authoring.VersionsClient", "List", err.Error())
   509  	}
   510  
   511  	req, err := client.ListPreparer(ctx, appID, skip, take)
   512  	if err != nil {
   513  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "List", nil, "Failure preparing request")
   514  		return
   515  	}
   516  
   517  	resp, err := client.ListSender(req)
   518  	if err != nil {
   519  		result.Response = autorest.Response{Response: resp}
   520  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "List", resp, "Failure sending request")
   521  		return
   522  	}
   523  
   524  	result, err = client.ListResponder(resp)
   525  	if err != nil {
   526  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "List", resp, "Failure responding to request")
   527  		return
   528  	}
   529  
   530  	return
   531  }
   532  
   533  // ListPreparer prepares the List request.
   534  func (client VersionsClient) ListPreparer(ctx context.Context, appID uuid.UUID, skip *int32, take *int32) (*http.Request, error) {
   535  	urlParameters := map[string]interface{}{
   536  		"Endpoint": client.Endpoint,
   537  	}
   538  
   539  	pathParameters := map[string]interface{}{
   540  		"appId": autorest.Encode("path", appID),
   541  	}
   542  
   543  	queryParameters := map[string]interface{}{}
   544  	if skip != nil {
   545  		queryParameters["skip"] = autorest.Encode("query", *skip)
   546  	} else {
   547  		queryParameters["skip"] = autorest.Encode("query", 0)
   548  	}
   549  	if take != nil {
   550  		queryParameters["take"] = autorest.Encode("query", *take)
   551  	} else {
   552  		queryParameters["take"] = autorest.Encode("query", 100)
   553  	}
   554  
   555  	preparer := autorest.CreatePreparer(
   556  		autorest.AsGet(),
   557  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   558  		autorest.WithPathParameters("/apps/{appId}/versions", pathParameters),
   559  		autorest.WithQueryParameters(queryParameters))
   560  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   561  }
   562  
   563  // ListSender sends the List request. The method will close the
   564  // http.Response Body if it receives an error.
   565  func (client VersionsClient) ListSender(req *http.Request) (*http.Response, error) {
   566  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   567  }
   568  
   569  // ListResponder handles the response to the List request. The method always
   570  // closes the http.Response Body.
   571  func (client VersionsClient) ListResponder(resp *http.Response) (result ListVersionInfo, err error) {
   572  	err = autorest.Respond(
   573  		resp,
   574  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   575  		autorest.ByUnmarshallingJSON(&result.Value),
   576  		autorest.ByClosing())
   577  	result.Response = autorest.Response{Response: resp}
   578  	return
   579  }
   580  
   581  // Update updates the name or description of the application version.
   582  // Parameters:
   583  // appID - the application ID.
   584  // versionID - the version ID.
   585  // versionUpdateObject - a model containing Name and Description of the application.
   586  func (client VersionsClient) Update(ctx context.Context, appID uuid.UUID, versionID string, versionUpdateObject TaskUpdateObject) (result OperationStatus, err error) {
   587  	if tracing.IsEnabled() {
   588  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Update")
   589  		defer func() {
   590  			sc := -1
   591  			if result.Response.Response != nil {
   592  				sc = result.Response.Response.StatusCode
   593  			}
   594  			tracing.EndSpan(ctx, sc, err)
   595  		}()
   596  	}
   597  	req, err := client.UpdatePreparer(ctx, appID, versionID, versionUpdateObject)
   598  	if err != nil {
   599  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Update", nil, "Failure preparing request")
   600  		return
   601  	}
   602  
   603  	resp, err := client.UpdateSender(req)
   604  	if err != nil {
   605  		result.Response = autorest.Response{Response: resp}
   606  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Update", resp, "Failure sending request")
   607  		return
   608  	}
   609  
   610  	result, err = client.UpdateResponder(resp)
   611  	if err != nil {
   612  		err = autorest.NewErrorWithError(err, "authoring.VersionsClient", "Update", resp, "Failure responding to request")
   613  		return
   614  	}
   615  
   616  	return
   617  }
   618  
   619  // UpdatePreparer prepares the Update request.
   620  func (client VersionsClient) UpdatePreparer(ctx context.Context, appID uuid.UUID, versionID string, versionUpdateObject TaskUpdateObject) (*http.Request, error) {
   621  	urlParameters := map[string]interface{}{
   622  		"Endpoint": client.Endpoint,
   623  	}
   624  
   625  	pathParameters := map[string]interface{}{
   626  		"appId":     autorest.Encode("path", appID),
   627  		"versionId": autorest.Encode("path", versionID),
   628  	}
   629  
   630  	preparer := autorest.CreatePreparer(
   631  		autorest.AsContentType("application/json; charset=utf-8"),
   632  		autorest.AsPut(),
   633  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   634  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/", pathParameters),
   635  		autorest.WithJSON(versionUpdateObject))
   636  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   637  }
   638  
   639  // UpdateSender sends the Update request. The method will close the
   640  // http.Response Body if it receives an error.
   641  func (client VersionsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   642  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   643  }
   644  
   645  // UpdateResponder handles the response to the Update request. The method always
   646  // closes the http.Response Body.
   647  func (client VersionsClient) UpdateResponder(resp *http.Response) (result OperationStatus, err error) {
   648  	err = autorest.Respond(
   649  		resp,
   650  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   651  		autorest.ByUnmarshallingJSON(&result),
   652  		autorest.ByClosing())
   653  	result.Response = autorest.Response{Response: resp}
   654  	return
   655  }
   656  

View as plain text