...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v1.0/formrecognizer/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v1.0/formrecognizer

     1  // Package formrecognizer implements the Azure ARM Formrecognizer service API version 1.0-preview.
     2  //
     3  //
     4  package formrecognizer
     5  
     6  // Copyright (c) Microsoft Corporation. All rights reserved.
     7  // Licensed under the MIT License. See License.txt in the project root for license information.
     8  //
     9  // Code generated by Microsoft (R) AutoRest Code Generator.
    10  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    11  
    12  import (
    13  	"context"
    14  	"github.com/Azure/go-autorest/autorest"
    15  	"github.com/Azure/go-autorest/autorest/azure"
    16  	"github.com/Azure/go-autorest/autorest/validation"
    17  	"github.com/Azure/go-autorest/tracing"
    18  	"github.com/gofrs/uuid"
    19  	"io"
    20  	"net/http"
    21  )
    22  
    23  // BaseClient is the base client for Formrecognizer.
    24  type BaseClient struct {
    25  	autorest.Client
    26  	Endpoint string
    27  }
    28  
    29  // New creates an instance of the BaseClient client.
    30  func New(endpoint string) BaseClient {
    31  	return NewWithoutDefaults(endpoint)
    32  }
    33  
    34  // NewWithoutDefaults creates an instance of the BaseClient client.
    35  func NewWithoutDefaults(endpoint string) BaseClient {
    36  	return BaseClient{
    37  		Client:   autorest.NewClientWithUserAgent(UserAgent()),
    38  		Endpoint: endpoint,
    39  	}
    40  }
    41  
    42  // AnalyzeWithCustomModel extract key-value pairs from a given document. The input document must be of one of the
    43  // supported content types - 'application/pdf', 'image/jpeg' or 'image/png'. A success response is returned in JSON.
    44  // Parameters:
    45  // ID - model Identifier to analyze the document with.
    46  // formStream - a pdf document or image (jpg,png) file to analyze.
    47  // keys - an optional list of known keys to extract the values for.
    48  func (client BaseClient) AnalyzeWithCustomModel(ctx context.Context, ID uuid.UUID, formStream io.ReadCloser, keys []string) (result AnalyzeResult, err error) {
    49  	if tracing.IsEnabled() {
    50  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.AnalyzeWithCustomModel")
    51  		defer func() {
    52  			sc := -1
    53  			if result.Response.Response != nil {
    54  				sc = result.Response.Response.StatusCode
    55  			}
    56  			tracing.EndSpan(ctx, sc, err)
    57  		}()
    58  	}
    59  	req, err := client.AnalyzeWithCustomModelPreparer(ctx, ID, formStream, keys)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "AnalyzeWithCustomModel", nil, "Failure preparing request")
    62  		return
    63  	}
    64  
    65  	resp, err := client.AnalyzeWithCustomModelSender(req)
    66  	if err != nil {
    67  		result.Response = autorest.Response{Response: resp}
    68  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "AnalyzeWithCustomModel", resp, "Failure sending request")
    69  		return
    70  	}
    71  
    72  	result, err = client.AnalyzeWithCustomModelResponder(resp)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "AnalyzeWithCustomModel", resp, "Failure responding to request")
    75  		return
    76  	}
    77  
    78  	return
    79  }
    80  
    81  // AnalyzeWithCustomModelPreparer prepares the AnalyzeWithCustomModel request.
    82  func (client BaseClient) AnalyzeWithCustomModelPreparer(ctx context.Context, ID uuid.UUID, formStream io.ReadCloser, keys []string) (*http.Request, error) {
    83  	urlParameters := map[string]interface{}{
    84  		"Endpoint": client.Endpoint,
    85  	}
    86  
    87  	pathParameters := map[string]interface{}{
    88  		"id": autorest.Encode("path", ID),
    89  	}
    90  
    91  	queryParameters := map[string]interface{}{}
    92  	if keys != nil && len(keys) > 0 {
    93  		queryParameters["keys"] = autorest.Encode("query", keys, ",")
    94  	}
    95  
    96  	formDataParameters := map[string]interface{}{
    97  		"form_stream": formStream,
    98  	}
    99  
   100  	preparer := autorest.CreatePreparer(
   101  		autorest.AsPost(),
   102  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   103  		autorest.WithPathParameters("/custom/models/{id}/analyze", pathParameters),
   104  		autorest.WithQueryParameters(queryParameters),
   105  		autorest.WithMultiPartFormData(formDataParameters))
   106  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   107  }
   108  
   109  // AnalyzeWithCustomModelSender sends the AnalyzeWithCustomModel request. The method will close the
   110  // http.Response Body if it receives an error.
   111  func (client BaseClient) AnalyzeWithCustomModelSender(req *http.Request) (*http.Response, error) {
   112  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   113  }
   114  
   115  // AnalyzeWithCustomModelResponder handles the response to the AnalyzeWithCustomModel request. The method always
   116  // closes the http.Response Body.
   117  func (client BaseClient) AnalyzeWithCustomModelResponder(resp *http.Response) (result AnalyzeResult, err error) {
   118  	err = autorest.Respond(
   119  		resp,
   120  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   121  		autorest.ByUnmarshallingJSON(&result),
   122  		autorest.ByClosing())
   123  	result.Response = autorest.Response{Response: resp}
   124  	return
   125  }
   126  
   127  // BatchReadReceipt batch Read Receipt operation. The response contains a field called 'Operation-Location', which
   128  // contains the URL that you must use for your 'Get Read Receipt Result' operation.
   129  // Parameters:
   130  // imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
   131  func (client BaseClient) BatchReadReceipt(ctx context.Context, imageURL ImageURL) (result autorest.Response, err error) {
   132  	if tracing.IsEnabled() {
   133  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadReceipt")
   134  		defer func() {
   135  			sc := -1
   136  			if result.Response != nil {
   137  				sc = result.Response.StatusCode
   138  			}
   139  			tracing.EndSpan(ctx, sc, err)
   140  		}()
   141  	}
   142  	if err := validation.Validate([]validation.Validation{
   143  		{TargetValue: imageURL,
   144  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   145  		return result, validation.NewError("formrecognizer.BaseClient", "BatchReadReceipt", err.Error())
   146  	}
   147  
   148  	req, err := client.BatchReadReceiptPreparer(ctx, imageURL)
   149  	if err != nil {
   150  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", nil, "Failure preparing request")
   151  		return
   152  	}
   153  
   154  	resp, err := client.BatchReadReceiptSender(req)
   155  	if err != nil {
   156  		result.Response = resp
   157  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", resp, "Failure sending request")
   158  		return
   159  	}
   160  
   161  	result, err = client.BatchReadReceiptResponder(resp)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", resp, "Failure responding to request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // BatchReadReceiptPreparer prepares the BatchReadReceipt request.
   171  func (client BaseClient) BatchReadReceiptPreparer(ctx context.Context, imageURL ImageURL) (*http.Request, error) {
   172  	urlParameters := map[string]interface{}{
   173  		"Endpoint": client.Endpoint,
   174  	}
   175  
   176  	preparer := autorest.CreatePreparer(
   177  		autorest.AsContentType("application/json; charset=utf-8"),
   178  		autorest.AsPost(),
   179  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   180  		autorest.WithPath("/prebuilt/receipt/asyncBatchAnalyze"),
   181  		autorest.WithJSON(imageURL))
   182  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   183  }
   184  
   185  // BatchReadReceiptSender sends the BatchReadReceipt request. The method will close the
   186  // http.Response Body if it receives an error.
   187  func (client BaseClient) BatchReadReceiptSender(req *http.Request) (*http.Response, error) {
   188  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   189  }
   190  
   191  // BatchReadReceiptResponder handles the response to the BatchReadReceipt request. The method always
   192  // closes the http.Response Body.
   193  func (client BaseClient) BatchReadReceiptResponder(resp *http.Response) (result autorest.Response, err error) {
   194  	err = autorest.Respond(
   195  		resp,
   196  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   197  		autorest.ByClosing())
   198  	result.Response = resp
   199  	return
   200  }
   201  
   202  // BatchReadReceiptInStream read Receipt operation. When you use the 'Batch Read Receipt' interface, the response
   203  // contains a field called 'Operation-Location'. The 'Operation-Location' field contains the URL that you must use for
   204  // your 'Get Read Receipt Result' operation.
   205  // Parameters:
   206  // imageParameter - an image stream.
   207  func (client BaseClient) BatchReadReceiptInStream(ctx context.Context, imageParameter io.ReadCloser) (result autorest.Response, err error) {
   208  	if tracing.IsEnabled() {
   209  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadReceiptInStream")
   210  		defer func() {
   211  			sc := -1
   212  			if result.Response != nil {
   213  				sc = result.Response.StatusCode
   214  			}
   215  			tracing.EndSpan(ctx, sc, err)
   216  		}()
   217  	}
   218  	req, err := client.BatchReadReceiptInStreamPreparer(ctx, imageParameter)
   219  	if err != nil {
   220  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", nil, "Failure preparing request")
   221  		return
   222  	}
   223  
   224  	resp, err := client.BatchReadReceiptInStreamSender(req)
   225  	if err != nil {
   226  		result.Response = resp
   227  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", resp, "Failure sending request")
   228  		return
   229  	}
   230  
   231  	result, err = client.BatchReadReceiptInStreamResponder(resp)
   232  	if err != nil {
   233  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", resp, "Failure responding to request")
   234  		return
   235  	}
   236  
   237  	return
   238  }
   239  
   240  // BatchReadReceiptInStreamPreparer prepares the BatchReadReceiptInStream request.
   241  func (client BaseClient) BatchReadReceiptInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser) (*http.Request, error) {
   242  	urlParameters := map[string]interface{}{
   243  		"Endpoint": client.Endpoint,
   244  	}
   245  
   246  	preparer := autorest.CreatePreparer(
   247  		autorest.AsContentType("application/octet-stream"),
   248  		autorest.AsPost(),
   249  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   250  		autorest.WithPath("/prebuilt/receipt/asyncBatchAnalyze"),
   251  		autorest.WithFile(imageParameter))
   252  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   253  }
   254  
   255  // BatchReadReceiptInStreamSender sends the BatchReadReceiptInStream request. The method will close the
   256  // http.Response Body if it receives an error.
   257  func (client BaseClient) BatchReadReceiptInStreamSender(req *http.Request) (*http.Response, error) {
   258  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   259  }
   260  
   261  // BatchReadReceiptInStreamResponder handles the response to the BatchReadReceiptInStream request. The method always
   262  // closes the http.Response Body.
   263  func (client BaseClient) BatchReadReceiptInStreamResponder(resp *http.Response) (result autorest.Response, err error) {
   264  	err = autorest.Respond(
   265  		resp,
   266  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   267  		autorest.ByClosing())
   268  	result.Response = resp
   269  	return
   270  }
   271  
   272  // DeleteCustomModel delete model artifacts.
   273  // Parameters:
   274  // ID - the identifier of the model to delete.
   275  func (client BaseClient) DeleteCustomModel(ctx context.Context, ID uuid.UUID) (result autorest.Response, err error) {
   276  	if tracing.IsEnabled() {
   277  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DeleteCustomModel")
   278  		defer func() {
   279  			sc := -1
   280  			if result.Response != nil {
   281  				sc = result.Response.StatusCode
   282  			}
   283  			tracing.EndSpan(ctx, sc, err)
   284  		}()
   285  	}
   286  	req, err := client.DeleteCustomModelPreparer(ctx, ID)
   287  	if err != nil {
   288  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "DeleteCustomModel", nil, "Failure preparing request")
   289  		return
   290  	}
   291  
   292  	resp, err := client.DeleteCustomModelSender(req)
   293  	if err != nil {
   294  		result.Response = resp
   295  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "DeleteCustomModel", resp, "Failure sending request")
   296  		return
   297  	}
   298  
   299  	result, err = client.DeleteCustomModelResponder(resp)
   300  	if err != nil {
   301  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "DeleteCustomModel", resp, "Failure responding to request")
   302  		return
   303  	}
   304  
   305  	return
   306  }
   307  
   308  // DeleteCustomModelPreparer prepares the DeleteCustomModel request.
   309  func (client BaseClient) DeleteCustomModelPreparer(ctx context.Context, ID uuid.UUID) (*http.Request, error) {
   310  	urlParameters := map[string]interface{}{
   311  		"Endpoint": client.Endpoint,
   312  	}
   313  
   314  	pathParameters := map[string]interface{}{
   315  		"id": autorest.Encode("path", ID),
   316  	}
   317  
   318  	preparer := autorest.CreatePreparer(
   319  		autorest.AsDelete(),
   320  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   321  		autorest.WithPathParameters("/custom/models/{id}", pathParameters))
   322  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   323  }
   324  
   325  // DeleteCustomModelSender sends the DeleteCustomModel request. The method will close the
   326  // http.Response Body if it receives an error.
   327  func (client BaseClient) DeleteCustomModelSender(req *http.Request) (*http.Response, error) {
   328  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   329  }
   330  
   331  // DeleteCustomModelResponder handles the response to the DeleteCustomModel request. The method always
   332  // closes the http.Response Body.
   333  func (client BaseClient) DeleteCustomModelResponder(resp *http.Response) (result autorest.Response, err error) {
   334  	err = autorest.Respond(
   335  		resp,
   336  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   337  		autorest.ByClosing())
   338  	result.Response = resp
   339  	return
   340  }
   341  
   342  // GetCustomModel get information about a model.
   343  // Parameters:
   344  // ID - model identifier.
   345  func (client BaseClient) GetCustomModel(ctx context.Context, ID uuid.UUID) (result ModelResult, err error) {
   346  	if tracing.IsEnabled() {
   347  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetCustomModel")
   348  		defer func() {
   349  			sc := -1
   350  			if result.Response.Response != nil {
   351  				sc = result.Response.Response.StatusCode
   352  			}
   353  			tracing.EndSpan(ctx, sc, err)
   354  		}()
   355  	}
   356  	req, err := client.GetCustomModelPreparer(ctx, ID)
   357  	if err != nil {
   358  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModel", nil, "Failure preparing request")
   359  		return
   360  	}
   361  
   362  	resp, err := client.GetCustomModelSender(req)
   363  	if err != nil {
   364  		result.Response = autorest.Response{Response: resp}
   365  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModel", resp, "Failure sending request")
   366  		return
   367  	}
   368  
   369  	result, err = client.GetCustomModelResponder(resp)
   370  	if err != nil {
   371  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModel", resp, "Failure responding to request")
   372  		return
   373  	}
   374  
   375  	return
   376  }
   377  
   378  // GetCustomModelPreparer prepares the GetCustomModel request.
   379  func (client BaseClient) GetCustomModelPreparer(ctx context.Context, ID uuid.UUID) (*http.Request, error) {
   380  	urlParameters := map[string]interface{}{
   381  		"Endpoint": client.Endpoint,
   382  	}
   383  
   384  	pathParameters := map[string]interface{}{
   385  		"id": autorest.Encode("path", ID),
   386  	}
   387  
   388  	preparer := autorest.CreatePreparer(
   389  		autorest.AsGet(),
   390  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   391  		autorest.WithPathParameters("/custom/models/{id}", pathParameters))
   392  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   393  }
   394  
   395  // GetCustomModelSender sends the GetCustomModel request. The method will close the
   396  // http.Response Body if it receives an error.
   397  func (client BaseClient) GetCustomModelSender(req *http.Request) (*http.Response, error) {
   398  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   399  }
   400  
   401  // GetCustomModelResponder handles the response to the GetCustomModel request. The method always
   402  // closes the http.Response Body.
   403  func (client BaseClient) GetCustomModelResponder(resp *http.Response) (result ModelResult, err error) {
   404  	err = autorest.Respond(
   405  		resp,
   406  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   407  		autorest.ByUnmarshallingJSON(&result),
   408  		autorest.ByClosing())
   409  	result.Response = autorest.Response{Response: resp}
   410  	return
   411  }
   412  
   413  // GetCustomModels get information about all trained custom models
   414  func (client BaseClient) GetCustomModels(ctx context.Context) (result ModelsResult, err error) {
   415  	if tracing.IsEnabled() {
   416  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetCustomModels")
   417  		defer func() {
   418  			sc := -1
   419  			if result.Response.Response != nil {
   420  				sc = result.Response.Response.StatusCode
   421  			}
   422  			tracing.EndSpan(ctx, sc, err)
   423  		}()
   424  	}
   425  	req, err := client.GetCustomModelsPreparer(ctx)
   426  	if err != nil {
   427  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModels", nil, "Failure preparing request")
   428  		return
   429  	}
   430  
   431  	resp, err := client.GetCustomModelsSender(req)
   432  	if err != nil {
   433  		result.Response = autorest.Response{Response: resp}
   434  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModels", resp, "Failure sending request")
   435  		return
   436  	}
   437  
   438  	result, err = client.GetCustomModelsResponder(resp)
   439  	if err != nil {
   440  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModels", resp, "Failure responding to request")
   441  		return
   442  	}
   443  
   444  	return
   445  }
   446  
   447  // GetCustomModelsPreparer prepares the GetCustomModels request.
   448  func (client BaseClient) GetCustomModelsPreparer(ctx context.Context) (*http.Request, error) {
   449  	urlParameters := map[string]interface{}{
   450  		"Endpoint": client.Endpoint,
   451  	}
   452  
   453  	preparer := autorest.CreatePreparer(
   454  		autorest.AsGet(),
   455  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   456  		autorest.WithPath("/custom/models"))
   457  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   458  }
   459  
   460  // GetCustomModelsSender sends the GetCustomModels request. The method will close the
   461  // http.Response Body if it receives an error.
   462  func (client BaseClient) GetCustomModelsSender(req *http.Request) (*http.Response, error) {
   463  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   464  }
   465  
   466  // GetCustomModelsResponder handles the response to the GetCustomModels request. The method always
   467  // closes the http.Response Body.
   468  func (client BaseClient) GetCustomModelsResponder(resp *http.Response) (result ModelsResult, err error) {
   469  	err = autorest.Respond(
   470  		resp,
   471  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   472  		autorest.ByUnmarshallingJSON(&result),
   473  		autorest.ByClosing())
   474  	result.Response = autorest.Response{Response: resp}
   475  	return
   476  }
   477  
   478  // GetExtractedKeys retrieve the keys that were
   479  // extracted during the training of the specified model.
   480  // Parameters:
   481  // ID - model identifier.
   482  func (client BaseClient) GetExtractedKeys(ctx context.Context, ID uuid.UUID) (result KeysResult, err error) {
   483  	if tracing.IsEnabled() {
   484  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetExtractedKeys")
   485  		defer func() {
   486  			sc := -1
   487  			if result.Response.Response != nil {
   488  				sc = result.Response.Response.StatusCode
   489  			}
   490  			tracing.EndSpan(ctx, sc, err)
   491  		}()
   492  	}
   493  	req, err := client.GetExtractedKeysPreparer(ctx, ID)
   494  	if err != nil {
   495  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetExtractedKeys", nil, "Failure preparing request")
   496  		return
   497  	}
   498  
   499  	resp, err := client.GetExtractedKeysSender(req)
   500  	if err != nil {
   501  		result.Response = autorest.Response{Response: resp}
   502  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetExtractedKeys", resp, "Failure sending request")
   503  		return
   504  	}
   505  
   506  	result, err = client.GetExtractedKeysResponder(resp)
   507  	if err != nil {
   508  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetExtractedKeys", resp, "Failure responding to request")
   509  		return
   510  	}
   511  
   512  	return
   513  }
   514  
   515  // GetExtractedKeysPreparer prepares the GetExtractedKeys request.
   516  func (client BaseClient) GetExtractedKeysPreparer(ctx context.Context, ID uuid.UUID) (*http.Request, error) {
   517  	urlParameters := map[string]interface{}{
   518  		"Endpoint": client.Endpoint,
   519  	}
   520  
   521  	pathParameters := map[string]interface{}{
   522  		"id": autorest.Encode("path", ID),
   523  	}
   524  
   525  	preparer := autorest.CreatePreparer(
   526  		autorest.AsGet(),
   527  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   528  		autorest.WithPathParameters("/custom/models/{id}/keys", pathParameters))
   529  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   530  }
   531  
   532  // GetExtractedKeysSender sends the GetExtractedKeys request. The method will close the
   533  // http.Response Body if it receives an error.
   534  func (client BaseClient) GetExtractedKeysSender(req *http.Request) (*http.Response, error) {
   535  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   536  }
   537  
   538  // GetExtractedKeysResponder handles the response to the GetExtractedKeys request. The method always
   539  // closes the http.Response Body.
   540  func (client BaseClient) GetExtractedKeysResponder(resp *http.Response) (result KeysResult, err error) {
   541  	err = autorest.Respond(
   542  		resp,
   543  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   544  		autorest.ByUnmarshallingJSON(&result),
   545  		autorest.ByClosing())
   546  	result.Response = autorest.Response{Response: resp}
   547  	return
   548  }
   549  
   550  // GetReadReceiptResult this interface is used for getting the analysis results of a 'Batch Read Receipt' operation.
   551  // The URL to this interface should be retrieved from the 'Operation-Location' field returned from the 'Batch Read
   552  // Receipt' operation.
   553  // Parameters:
   554  // operationID - id of read operation returned in the response of a 'Batch Read Receipt' operation.
   555  func (client BaseClient) GetReadReceiptResult(ctx context.Context, operationID string) (result ReadReceiptResult, err error) {
   556  	if tracing.IsEnabled() {
   557  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetReadReceiptResult")
   558  		defer func() {
   559  			sc := -1
   560  			if result.Response.Response != nil {
   561  				sc = result.Response.Response.StatusCode
   562  			}
   563  			tracing.EndSpan(ctx, sc, err)
   564  		}()
   565  	}
   566  	req, err := client.GetReadReceiptResultPreparer(ctx, operationID)
   567  	if err != nil {
   568  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", nil, "Failure preparing request")
   569  		return
   570  	}
   571  
   572  	resp, err := client.GetReadReceiptResultSender(req)
   573  	if err != nil {
   574  		result.Response = autorest.Response{Response: resp}
   575  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", resp, "Failure sending request")
   576  		return
   577  	}
   578  
   579  	result, err = client.GetReadReceiptResultResponder(resp)
   580  	if err != nil {
   581  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", resp, "Failure responding to request")
   582  		return
   583  	}
   584  
   585  	return
   586  }
   587  
   588  // GetReadReceiptResultPreparer prepares the GetReadReceiptResult request.
   589  func (client BaseClient) GetReadReceiptResultPreparer(ctx context.Context, operationID string) (*http.Request, error) {
   590  	urlParameters := map[string]interface{}{
   591  		"Endpoint": client.Endpoint,
   592  	}
   593  
   594  	pathParameters := map[string]interface{}{
   595  		"operationId": autorest.Encode("path", operationID),
   596  	}
   597  
   598  	preparer := autorest.CreatePreparer(
   599  		autorest.AsGet(),
   600  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   601  		autorest.WithPathParameters("/prebuilt/receipt/operations/{operationId}", pathParameters))
   602  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   603  }
   604  
   605  // GetReadReceiptResultSender sends the GetReadReceiptResult request. The method will close the
   606  // http.Response Body if it receives an error.
   607  func (client BaseClient) GetReadReceiptResultSender(req *http.Request) (*http.Response, error) {
   608  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   609  }
   610  
   611  // GetReadReceiptResultResponder handles the response to the GetReadReceiptResult request. The method always
   612  // closes the http.Response Body.
   613  func (client BaseClient) GetReadReceiptResultResponder(resp *http.Response) (result ReadReceiptResult, err error) {
   614  	err = autorest.Respond(
   615  		resp,
   616  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   617  		autorest.ByUnmarshallingJSON(&result),
   618  		autorest.ByClosing())
   619  	result.Response = autorest.Response{Response: resp}
   620  	return
   621  }
   622  
   623  // TrainCustomModel create and train a custom model. The train request must include a source parameter that is either
   624  // an externally accessible Azure Storage blob container Uri (preferably a Shared Access Signature Uri) or valid path
   625  // to a data folder in a locally mounted drive. When local paths are specified, they must follow the Linux/Unix path
   626  // format and be an absolute path rooted to the input mount configuration
   627  // setting value e.g., if '{Mounts:Input}' configuration setting value is '/input' then a valid source path would be
   628  // '/input/contosodataset'. All data to be trained is expected to be directly under the source folder. Subfolders are
   629  // not supported. Models are trained using documents that are of the following content type - 'application/pdf',
   630  // 'image/jpeg' and 'image/png'."
   631  // Other type of content is ignored.
   632  // Parameters:
   633  // trainRequest - request object for training.
   634  func (client BaseClient) TrainCustomModel(ctx context.Context, trainRequest TrainRequest) (result TrainResult, err error) {
   635  	if tracing.IsEnabled() {
   636  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.TrainCustomModel")
   637  		defer func() {
   638  			sc := -1
   639  			if result.Response.Response != nil {
   640  				sc = result.Response.Response.StatusCode
   641  			}
   642  			tracing.EndSpan(ctx, sc, err)
   643  		}()
   644  	}
   645  	if err := validation.Validate([]validation.Validation{
   646  		{TargetValue: trainRequest,
   647  			Constraints: []validation.Constraint{{Target: "trainRequest.Source", Name: validation.Null, Rule: true,
   648  				Chain: []validation.Constraint{{Target: "trainRequest.Source", Name: validation.MaxLength, Rule: 2048, Chain: nil},
   649  					{Target: "trainRequest.Source", Name: validation.MinLength, Rule: 0, Chain: nil},
   650  				}},
   651  				{Target: "trainRequest.SourceFilter", Name: validation.Null, Rule: false,
   652  					Chain: []validation.Constraint{{Target: "trainRequest.SourceFilter.Prefix", Name: validation.Null, Rule: false,
   653  						Chain: []validation.Constraint{{Target: "trainRequest.SourceFilter.Prefix", Name: validation.MaxLength, Rule: 128, Chain: nil},
   654  							{Target: "trainRequest.SourceFilter.Prefix", Name: validation.MinLength, Rule: 0, Chain: nil},
   655  						}},
   656  					}}}}}); err != nil {
   657  		return result, validation.NewError("formrecognizer.BaseClient", "TrainCustomModel", err.Error())
   658  	}
   659  
   660  	req, err := client.TrainCustomModelPreparer(ctx, trainRequest)
   661  	if err != nil {
   662  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "TrainCustomModel", nil, "Failure preparing request")
   663  		return
   664  	}
   665  
   666  	resp, err := client.TrainCustomModelSender(req)
   667  	if err != nil {
   668  		result.Response = autorest.Response{Response: resp}
   669  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "TrainCustomModel", resp, "Failure sending request")
   670  		return
   671  	}
   672  
   673  	result, err = client.TrainCustomModelResponder(resp)
   674  	if err != nil {
   675  		err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "TrainCustomModel", resp, "Failure responding to request")
   676  		return
   677  	}
   678  
   679  	return
   680  }
   681  
   682  // TrainCustomModelPreparer prepares the TrainCustomModel request.
   683  func (client BaseClient) TrainCustomModelPreparer(ctx context.Context, trainRequest TrainRequest) (*http.Request, error) {
   684  	urlParameters := map[string]interface{}{
   685  		"Endpoint": client.Endpoint,
   686  	}
   687  
   688  	preparer := autorest.CreatePreparer(
   689  		autorest.AsContentType("application/json; charset=utf-8"),
   690  		autorest.AsPost(),
   691  		autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
   692  		autorest.WithPath("/custom/train"),
   693  		autorest.WithJSON(trainRequest))
   694  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   695  }
   696  
   697  // TrainCustomModelSender sends the TrainCustomModel request. The method will close the
   698  // http.Response Body if it receives an error.
   699  func (client BaseClient) TrainCustomModelSender(req *http.Request) (*http.Response, error) {
   700  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   701  }
   702  
   703  // TrainCustomModelResponder handles the response to the TrainCustomModel request. The method always
   704  // closes the http.Response Body.
   705  func (client BaseClient) TrainCustomModelResponder(resp *http.Response) (result TrainResult, err error) {
   706  	err = autorest.Respond(
   707  		resp,
   708  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   709  		autorest.ByUnmarshallingJSON(&result),
   710  		autorest.ByClosing())
   711  	result.Response = autorest.Response{Response: resp}
   712  	return
   713  }
   714  

View as plain text