...

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

View as plain text