...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v3.0/luis/authoring/examples.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v3.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  // ExamplesClient is the client for the Examples methods of the Authoring service.
    20  type ExamplesClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewExamplesClient creates an instance of the ExamplesClient client.
    25  func NewExamplesClient(endpoint string) ExamplesClient {
    26  	return ExamplesClient{New(endpoint)}
    27  }
    28  
    29  // Add adds a labeled example utterance in a version of the application.
    30  // Parameters:
    31  // appID - the application ID.
    32  // versionID - the version ID.
    33  // exampleLabelObject - a labeled example utterance with the expected intent and entities.
    34  // enableNestedChildren - toggles nested/flat format
    35  func (client ExamplesClient) Add(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObject ExampleLabelObject, enableNestedChildren *bool) (result LabelExampleResponse, err error) {
    36  	if tracing.IsEnabled() {
    37  		ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.Add")
    38  		defer func() {
    39  			sc := -1
    40  			if result.Response.Response != nil {
    41  				sc = result.Response.Response.StatusCode
    42  			}
    43  			tracing.EndSpan(ctx, sc, err)
    44  		}()
    45  	}
    46  	req, err := client.AddPreparer(ctx, appID, versionID, exampleLabelObject, enableNestedChildren)
    47  	if err != nil {
    48  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Add", nil, "Failure preparing request")
    49  		return
    50  	}
    51  
    52  	resp, err := client.AddSender(req)
    53  	if err != nil {
    54  		result.Response = autorest.Response{Response: resp}
    55  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Add", resp, "Failure sending request")
    56  		return
    57  	}
    58  
    59  	result, err = client.AddResponder(resp)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Add", resp, "Failure responding to request")
    62  		return
    63  	}
    64  
    65  	return
    66  }
    67  
    68  // AddPreparer prepares the Add request.
    69  func (client ExamplesClient) AddPreparer(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObject ExampleLabelObject, enableNestedChildren *bool) (*http.Request, error) {
    70  	urlParameters := map[string]interface{}{
    71  		"Endpoint": client.Endpoint,
    72  	}
    73  
    74  	pathParameters := map[string]interface{}{
    75  		"appId":     autorest.Encode("path", appID),
    76  		"versionId": autorest.Encode("path", versionID),
    77  	}
    78  
    79  	queryParameters := map[string]interface{}{}
    80  	if enableNestedChildren != nil {
    81  		queryParameters["enableNestedChildren"] = autorest.Encode("query", *enableNestedChildren)
    82  	} else {
    83  		queryParameters["enableNestedChildren"] = autorest.Encode("query", false)
    84  	}
    85  
    86  	preparer := autorest.CreatePreparer(
    87  		autorest.AsContentType("application/json; charset=utf-8"),
    88  		autorest.AsPost(),
    89  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
    90  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/example", pathParameters),
    91  		autorest.WithJSON(exampleLabelObject),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // AddSender sends the Add request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client ExamplesClient) AddSender(req *http.Request) (*http.Response, error) {
    99  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   100  }
   101  
   102  // AddResponder handles the response to the Add request. The method always
   103  // closes the http.Response Body.
   104  func (client ExamplesClient) AddResponder(resp *http.Response) (result LabelExampleResponse, err error) {
   105  	err = autorest.Respond(
   106  		resp,
   107  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   108  		autorest.ByUnmarshallingJSON(&result),
   109  		autorest.ByClosing())
   110  	result.Response = autorest.Response{Response: resp}
   111  	return
   112  }
   113  
   114  // Batch adds a batch of labeled example utterances to a version of the application.
   115  // Parameters:
   116  // appID - the application ID.
   117  // versionID - the version ID.
   118  // exampleLabelObjectArray - array of example utterances.
   119  // enableNestedChildren - toggles nested/flat format
   120  func (client ExamplesClient) Batch(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObjectArray []ExampleLabelObject, enableNestedChildren *bool) (result ListBatchLabelExample, err error) {
   121  	if tracing.IsEnabled() {
   122  		ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.Batch")
   123  		defer func() {
   124  			sc := -1
   125  			if result.Response.Response != nil {
   126  				sc = result.Response.Response.StatusCode
   127  			}
   128  			tracing.EndSpan(ctx, sc, err)
   129  		}()
   130  	}
   131  	if err := validation.Validate([]validation.Validation{
   132  		{TargetValue: exampleLabelObjectArray,
   133  			Constraints: []validation.Constraint{{Target: "exampleLabelObjectArray", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   134  		return result, validation.NewError("authoring.ExamplesClient", "Batch", err.Error())
   135  	}
   136  
   137  	req, err := client.BatchPreparer(ctx, appID, versionID, exampleLabelObjectArray, enableNestedChildren)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Batch", nil, "Failure preparing request")
   140  		return
   141  	}
   142  
   143  	resp, err := client.BatchSender(req)
   144  	if err != nil {
   145  		result.Response = autorest.Response{Response: resp}
   146  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Batch", resp, "Failure sending request")
   147  		return
   148  	}
   149  
   150  	result, err = client.BatchResponder(resp)
   151  	if err != nil {
   152  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Batch", resp, "Failure responding to request")
   153  		return
   154  	}
   155  
   156  	return
   157  }
   158  
   159  // BatchPreparer prepares the Batch request.
   160  func (client ExamplesClient) BatchPreparer(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObjectArray []ExampleLabelObject, enableNestedChildren *bool) (*http.Request, error) {
   161  	urlParameters := map[string]interface{}{
   162  		"Endpoint": client.Endpoint,
   163  	}
   164  
   165  	pathParameters := map[string]interface{}{
   166  		"appId":     autorest.Encode("path", appID),
   167  		"versionId": autorest.Encode("path", versionID),
   168  	}
   169  
   170  	queryParameters := map[string]interface{}{}
   171  	if enableNestedChildren != nil {
   172  		queryParameters["enableNestedChildren"] = autorest.Encode("query", *enableNestedChildren)
   173  	} else {
   174  		queryParameters["enableNestedChildren"] = autorest.Encode("query", false)
   175  	}
   176  
   177  	preparer := autorest.CreatePreparer(
   178  		autorest.AsContentType("application/json; charset=utf-8"),
   179  		autorest.AsPost(),
   180  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
   181  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/examples", pathParameters),
   182  		autorest.WithJSON(exampleLabelObjectArray),
   183  		autorest.WithQueryParameters(queryParameters))
   184  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   185  }
   186  
   187  // BatchSender sends the Batch request. The method will close the
   188  // http.Response Body if it receives an error.
   189  func (client ExamplesClient) BatchSender(req *http.Request) (*http.Response, error) {
   190  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   191  }
   192  
   193  // BatchResponder handles the response to the Batch request. The method always
   194  // closes the http.Response Body.
   195  func (client ExamplesClient) BatchResponder(resp *http.Response) (result ListBatchLabelExample, err error) {
   196  	err = autorest.Respond(
   197  		resp,
   198  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusMultiStatus),
   199  		autorest.ByUnmarshallingJSON(&result.Value),
   200  		autorest.ByClosing())
   201  	result.Response = autorest.Response{Response: resp}
   202  	return
   203  }
   204  
   205  // Delete deletes the labeled example utterances with the specified ID from a version of the application.
   206  // Parameters:
   207  // appID - the application ID.
   208  // versionID - the version ID.
   209  // exampleID - the example ID.
   210  func (client ExamplesClient) Delete(ctx context.Context, appID uuid.UUID, versionID string, exampleID int32) (result OperationStatus, err error) {
   211  	if tracing.IsEnabled() {
   212  		ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.Delete")
   213  		defer func() {
   214  			sc := -1
   215  			if result.Response.Response != nil {
   216  				sc = result.Response.Response.StatusCode
   217  			}
   218  			tracing.EndSpan(ctx, sc, err)
   219  		}()
   220  	}
   221  	req, err := client.DeletePreparer(ctx, appID, versionID, exampleID)
   222  	if err != nil {
   223  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Delete", nil, "Failure preparing request")
   224  		return
   225  	}
   226  
   227  	resp, err := client.DeleteSender(req)
   228  	if err != nil {
   229  		result.Response = autorest.Response{Response: resp}
   230  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Delete", resp, "Failure sending request")
   231  		return
   232  	}
   233  
   234  	result, err = client.DeleteResponder(resp)
   235  	if err != nil {
   236  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Delete", resp, "Failure responding to request")
   237  		return
   238  	}
   239  
   240  	return
   241  }
   242  
   243  // DeletePreparer prepares the Delete request.
   244  func (client ExamplesClient) DeletePreparer(ctx context.Context, appID uuid.UUID, versionID string, exampleID int32) (*http.Request, error) {
   245  	urlParameters := map[string]interface{}{
   246  		"Endpoint": client.Endpoint,
   247  	}
   248  
   249  	pathParameters := map[string]interface{}{
   250  		"appId":     autorest.Encode("path", appID),
   251  		"exampleId": autorest.Encode("path", exampleID),
   252  		"versionId": autorest.Encode("path", versionID),
   253  	}
   254  
   255  	preparer := autorest.CreatePreparer(
   256  		autorest.AsDelete(),
   257  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
   258  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/examples/{exampleId}", pathParameters))
   259  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   260  }
   261  
   262  // DeleteSender sends the Delete request. The method will close the
   263  // http.Response Body if it receives an error.
   264  func (client ExamplesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   265  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   266  }
   267  
   268  // DeleteResponder handles the response to the Delete request. The method always
   269  // closes the http.Response Body.
   270  func (client ExamplesClient) DeleteResponder(resp *http.Response) (result OperationStatus, err error) {
   271  	err = autorest.Respond(
   272  		resp,
   273  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   274  		autorest.ByUnmarshallingJSON(&result),
   275  		autorest.ByClosing())
   276  	result.Response = autorest.Response{Response: resp}
   277  	return
   278  }
   279  
   280  // List returns example utterances to be reviewed from a version of the application.
   281  // Parameters:
   282  // appID - the application ID.
   283  // versionID - the version ID.
   284  // skip - the number of entries to skip. Default value is 0.
   285  // take - the number of entries to return. Maximum page size is 500. Default is 100.
   286  // enableNestedChildren - toggles nested/flat format
   287  func (client ExamplesClient) List(ctx context.Context, appID uuid.UUID, versionID string, skip *int32, take *int32, enableNestedChildren *bool) (result ListLabeledUtterance, err error) {
   288  	if tracing.IsEnabled() {
   289  		ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.List")
   290  		defer func() {
   291  			sc := -1
   292  			if result.Response.Response != nil {
   293  				sc = result.Response.Response.StatusCode
   294  			}
   295  			tracing.EndSpan(ctx, sc, err)
   296  		}()
   297  	}
   298  	if err := validation.Validate([]validation.Validation{
   299  		{TargetValue: skip,
   300  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
   301  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}},
   302  		{TargetValue: take,
   303  			Constraints: []validation.Constraint{{Target: "take", Name: validation.Null, Rule: false,
   304  				Chain: []validation.Constraint{{Target: "take", Name: validation.InclusiveMaximum, Rule: int64(500), Chain: nil},
   305  					{Target: "take", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
   306  				}}}}}); err != nil {
   307  		return result, validation.NewError("authoring.ExamplesClient", "List", err.Error())
   308  	}
   309  
   310  	req, err := client.ListPreparer(ctx, appID, versionID, skip, take, enableNestedChildren)
   311  	if err != nil {
   312  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "List", nil, "Failure preparing request")
   313  		return
   314  	}
   315  
   316  	resp, err := client.ListSender(req)
   317  	if err != nil {
   318  		result.Response = autorest.Response{Response: resp}
   319  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "List", resp, "Failure sending request")
   320  		return
   321  	}
   322  
   323  	result, err = client.ListResponder(resp)
   324  	if err != nil {
   325  		err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "List", resp, "Failure responding to request")
   326  		return
   327  	}
   328  
   329  	return
   330  }
   331  
   332  // ListPreparer prepares the List request.
   333  func (client ExamplesClient) ListPreparer(ctx context.Context, appID uuid.UUID, versionID string, skip *int32, take *int32, enableNestedChildren *bool) (*http.Request, error) {
   334  	urlParameters := map[string]interface{}{
   335  		"Endpoint": client.Endpoint,
   336  	}
   337  
   338  	pathParameters := map[string]interface{}{
   339  		"appId":     autorest.Encode("path", appID),
   340  		"versionId": autorest.Encode("path", versionID),
   341  	}
   342  
   343  	queryParameters := map[string]interface{}{}
   344  	if skip != nil {
   345  		queryParameters["skip"] = autorest.Encode("query", *skip)
   346  	} else {
   347  		queryParameters["skip"] = autorest.Encode("query", 0)
   348  	}
   349  	if take != nil {
   350  		queryParameters["take"] = autorest.Encode("query", *take)
   351  	} else {
   352  		queryParameters["take"] = autorest.Encode("query", 100)
   353  	}
   354  	if enableNestedChildren != nil {
   355  		queryParameters["enableNestedChildren"] = autorest.Encode("query", *enableNestedChildren)
   356  	} else {
   357  		queryParameters["enableNestedChildren"] = autorest.Encode("query", false)
   358  	}
   359  
   360  	preparer := autorest.CreatePreparer(
   361  		autorest.AsGet(),
   362  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
   363  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/examples", pathParameters),
   364  		autorest.WithQueryParameters(queryParameters))
   365  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   366  }
   367  
   368  // ListSender sends the List request. The method will close the
   369  // http.Response Body if it receives an error.
   370  func (client ExamplesClient) ListSender(req *http.Request) (*http.Response, error) {
   371  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   372  }
   373  
   374  // ListResponder handles the response to the List request. The method always
   375  // closes the http.Response Body.
   376  func (client ExamplesClient) ListResponder(resp *http.Response) (result ListLabeledUtterance, err error) {
   377  	err = autorest.Respond(
   378  		resp,
   379  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   380  		autorest.ByUnmarshallingJSON(&result.Value),
   381  		autorest.ByClosing())
   382  	result.Response = autorest.Response{Response: resp}
   383  	return
   384  }
   385  

View as plain text