...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v1.0_preview.1/translatortext/translation.go

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

     1  package translatortext
     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  // TranslationClient is the client for the Translation methods of the Translatortext service.
    20  type TranslationClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewTranslationClient creates an instance of the TranslationClient client.
    25  func NewTranslationClient() TranslationClient {
    26  	return TranslationClient{New()}
    27  }
    28  
    29  // CancelOperation cancel a currently processing or queued operation.
    30  // An operation will not be cancelled if it is already completed or failed or cancelling.  A bad request will be
    31  // returned.
    32  // All documents that have completed translation will not be cancelled and will be charged.
    33  // All pending documents will be cancelled if possible.
    34  // Parameters:
    35  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
    36  // https://westus.api.cognitive.microsoft.com).
    37  // ID - format - uuid.  The operation-id
    38  func (client TranslationClient) CancelOperation(ctx context.Context, endpoint string, ID uuid.UUID) (result BatchStatusDetail, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.CancelOperation")
    41  		defer func() {
    42  			sc := -1
    43  			if result.Response.Response != nil {
    44  				sc = result.Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.CancelOperationPreparer(ctx, endpoint, ID)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "CancelOperation", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	resp, err := client.CancelOperationSender(req)
    56  	if err != nil {
    57  		result.Response = autorest.Response{Response: resp}
    58  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "CancelOperation", resp, "Failure sending request")
    59  		return
    60  	}
    61  
    62  	result, err = client.CancelOperationResponder(resp)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "CancelOperation", resp, "Failure responding to request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // CancelOperationPreparer prepares the CancelOperation request.
    72  func (client TranslationClient) CancelOperationPreparer(ctx context.Context, endpoint string, ID uuid.UUID) (*http.Request, error) {
    73  	urlParameters := map[string]interface{}{
    74  		"endpoint": endpoint,
    75  	}
    76  
    77  	pathParameters := map[string]interface{}{
    78  		"id": autorest.Encode("path", ID),
    79  	}
    80  
    81  	preparer := autorest.CreatePreparer(
    82  		autorest.AsDelete(),
    83  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
    84  		autorest.WithPathParameters("/batches/{id}", pathParameters))
    85  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    86  }
    87  
    88  // CancelOperationSender sends the CancelOperation request. The method will close the
    89  // http.Response Body if it receives an error.
    90  func (client TranslationClient) CancelOperationSender(req *http.Request) (*http.Response, error) {
    91  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    92  }
    93  
    94  // CancelOperationResponder handles the response to the CancelOperation request. The method always
    95  // closes the http.Response Body.
    96  func (client TranslationClient) CancelOperationResponder(resp *http.Response) (result BatchStatusDetail, err error) {
    97  	err = autorest.Respond(
    98  		resp,
    99  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   100  		autorest.ByUnmarshallingJSON(&result),
   101  		autorest.ByClosing())
   102  	result.Response = autorest.Response{Response: resp}
   103  	return
   104  }
   105  
   106  // GetDocumentFormats the list of supported document formats supported by our service.
   107  // The list will include the common file extension used and supported as well as the content-type if using the upload
   108  // API.
   109  // Parameters:
   110  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   111  // https://westus.api.cognitive.microsoft.com).
   112  func (client TranslationClient) GetDocumentFormats(ctx context.Context, endpoint string) (result FileFormatListResult, err error) {
   113  	if tracing.IsEnabled() {
   114  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.GetDocumentFormats")
   115  		defer func() {
   116  			sc := -1
   117  			if result.Response.Response != nil {
   118  				sc = result.Response.Response.StatusCode
   119  			}
   120  			tracing.EndSpan(ctx, sc, err)
   121  		}()
   122  	}
   123  	req, err := client.GetDocumentFormatsPreparer(ctx, endpoint)
   124  	if err != nil {
   125  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentFormats", nil, "Failure preparing request")
   126  		return
   127  	}
   128  
   129  	resp, err := client.GetDocumentFormatsSender(req)
   130  	if err != nil {
   131  		result.Response = autorest.Response{Response: resp}
   132  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentFormats", resp, "Failure sending request")
   133  		return
   134  	}
   135  
   136  	result, err = client.GetDocumentFormatsResponder(resp)
   137  	if err != nil {
   138  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentFormats", resp, "Failure responding to request")
   139  		return
   140  	}
   141  
   142  	return
   143  }
   144  
   145  // GetDocumentFormatsPreparer prepares the GetDocumentFormats request.
   146  func (client TranslationClient) GetDocumentFormatsPreparer(ctx context.Context, endpoint string) (*http.Request, error) {
   147  	urlParameters := map[string]interface{}{
   148  		"endpoint": endpoint,
   149  	}
   150  
   151  	preparer := autorest.CreatePreparer(
   152  		autorest.AsGet(),
   153  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   154  		autorest.WithPath("/documents/formats"))
   155  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   156  }
   157  
   158  // GetDocumentFormatsSender sends the GetDocumentFormats request. The method will close the
   159  // http.Response Body if it receives an error.
   160  func (client TranslationClient) GetDocumentFormatsSender(req *http.Request) (*http.Response, error) {
   161  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   162  }
   163  
   164  // GetDocumentFormatsResponder handles the response to the GetDocumentFormats request. The method always
   165  // closes the http.Response Body.
   166  func (client TranslationClient) GetDocumentFormatsResponder(resp *http.Response) (result FileFormatListResult, err error) {
   167  	err = autorest.Respond(
   168  		resp,
   169  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   170  		autorest.ByUnmarshallingJSON(&result),
   171  		autorest.ByClosing())
   172  	result.Response = autorest.Response{Response: resp}
   173  	return
   174  }
   175  
   176  // GetDocumentStatus returns the status of the translation of the document.
   177  // Parameters:
   178  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   179  // https://westus.api.cognitive.microsoft.com).
   180  // ID - format - uuid.  The batch id
   181  // documentID - format - uuid.  The document id
   182  func (client TranslationClient) GetDocumentStatus(ctx context.Context, endpoint string, ID uuid.UUID, documentID uuid.UUID) (result DocumentStatusDetail, err error) {
   183  	if tracing.IsEnabled() {
   184  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.GetDocumentStatus")
   185  		defer func() {
   186  			sc := -1
   187  			if result.Response.Response != nil {
   188  				sc = result.Response.Response.StatusCode
   189  			}
   190  			tracing.EndSpan(ctx, sc, err)
   191  		}()
   192  	}
   193  	req, err := client.GetDocumentStatusPreparer(ctx, endpoint, ID, documentID)
   194  	if err != nil {
   195  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentStatus", nil, "Failure preparing request")
   196  		return
   197  	}
   198  
   199  	resp, err := client.GetDocumentStatusSender(req)
   200  	if err != nil {
   201  		result.Response = autorest.Response{Response: resp}
   202  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentStatus", resp, "Failure sending request")
   203  		return
   204  	}
   205  
   206  	result, err = client.GetDocumentStatusResponder(resp)
   207  	if err != nil {
   208  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentStatus", resp, "Failure responding to request")
   209  		return
   210  	}
   211  
   212  	return
   213  }
   214  
   215  // GetDocumentStatusPreparer prepares the GetDocumentStatus request.
   216  func (client TranslationClient) GetDocumentStatusPreparer(ctx context.Context, endpoint string, ID uuid.UUID, documentID uuid.UUID) (*http.Request, error) {
   217  	urlParameters := map[string]interface{}{
   218  		"endpoint": endpoint,
   219  	}
   220  
   221  	pathParameters := map[string]interface{}{
   222  		"documentId": autorest.Encode("path", documentID),
   223  		"id":         autorest.Encode("path", ID),
   224  	}
   225  
   226  	preparer := autorest.CreatePreparer(
   227  		autorest.AsGet(),
   228  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   229  		autorest.WithPathParameters("/batches/{id}/documents/{documentId}", pathParameters))
   230  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   231  }
   232  
   233  // GetDocumentStatusSender sends the GetDocumentStatus request. The method will close the
   234  // http.Response Body if it receives an error.
   235  func (client TranslationClient) GetDocumentStatusSender(req *http.Request) (*http.Response, error) {
   236  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   237  }
   238  
   239  // GetDocumentStatusResponder handles the response to the GetDocumentStatus request. The method always
   240  // closes the http.Response Body.
   241  func (client TranslationClient) GetDocumentStatusResponder(resp *http.Response) (result DocumentStatusDetail, err error) {
   242  	err = autorest.Respond(
   243  		resp,
   244  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   245  		autorest.ByUnmarshallingJSON(&result),
   246  		autorest.ByClosing())
   247  	result.Response = autorest.Response{Response: resp}
   248  	return
   249  }
   250  
   251  // GetDocumentStorageSource the list of storage sources supported by our service.
   252  // Parameters:
   253  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   254  // https://westus.api.cognitive.microsoft.com).
   255  func (client TranslationClient) GetDocumentStorageSource(ctx context.Context, endpoint string) (result StorageSourceListResult, err error) {
   256  	if tracing.IsEnabled() {
   257  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.GetDocumentStorageSource")
   258  		defer func() {
   259  			sc := -1
   260  			if result.Response.Response != nil {
   261  				sc = result.Response.Response.StatusCode
   262  			}
   263  			tracing.EndSpan(ctx, sc, err)
   264  		}()
   265  	}
   266  	req, err := client.GetDocumentStorageSourcePreparer(ctx, endpoint)
   267  	if err != nil {
   268  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentStorageSource", nil, "Failure preparing request")
   269  		return
   270  	}
   271  
   272  	resp, err := client.GetDocumentStorageSourceSender(req)
   273  	if err != nil {
   274  		result.Response = autorest.Response{Response: resp}
   275  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentStorageSource", resp, "Failure sending request")
   276  		return
   277  	}
   278  
   279  	result, err = client.GetDocumentStorageSourceResponder(resp)
   280  	if err != nil {
   281  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetDocumentStorageSource", resp, "Failure responding to request")
   282  		return
   283  	}
   284  
   285  	return
   286  }
   287  
   288  // GetDocumentStorageSourcePreparer prepares the GetDocumentStorageSource request.
   289  func (client TranslationClient) GetDocumentStorageSourcePreparer(ctx context.Context, endpoint string) (*http.Request, error) {
   290  	urlParameters := map[string]interface{}{
   291  		"endpoint": endpoint,
   292  	}
   293  
   294  	preparer := autorest.CreatePreparer(
   295  		autorest.AsGet(),
   296  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   297  		autorest.WithPath("/storagesources"))
   298  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   299  }
   300  
   301  // GetDocumentStorageSourceSender sends the GetDocumentStorageSource request. The method will close the
   302  // http.Response Body if it receives an error.
   303  func (client TranslationClient) GetDocumentStorageSourceSender(req *http.Request) (*http.Response, error) {
   304  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   305  }
   306  
   307  // GetDocumentStorageSourceResponder handles the response to the GetDocumentStorageSource request. The method always
   308  // closes the http.Response Body.
   309  func (client TranslationClient) GetDocumentStorageSourceResponder(resp *http.Response) (result StorageSourceListResult, err error) {
   310  	err = autorest.Respond(
   311  		resp,
   312  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   313  		autorest.ByUnmarshallingJSON(&result),
   314  		autorest.ByClosing())
   315  	result.Response = autorest.Response{Response: resp}
   316  	return
   317  }
   318  
   319  // GetGlossaryFormats the list of supported glossary formats supported by our service.
   320  // The list will include the common file extension used.
   321  // Parameters:
   322  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   323  // https://westus.api.cognitive.microsoft.com).
   324  func (client TranslationClient) GetGlossaryFormats(ctx context.Context, endpoint string) (result FileFormatListResult, err error) {
   325  	if tracing.IsEnabled() {
   326  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.GetGlossaryFormats")
   327  		defer func() {
   328  			sc := -1
   329  			if result.Response.Response != nil {
   330  				sc = result.Response.Response.StatusCode
   331  			}
   332  			tracing.EndSpan(ctx, sc, err)
   333  		}()
   334  	}
   335  	req, err := client.GetGlossaryFormatsPreparer(ctx, endpoint)
   336  	if err != nil {
   337  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetGlossaryFormats", nil, "Failure preparing request")
   338  		return
   339  	}
   340  
   341  	resp, err := client.GetGlossaryFormatsSender(req)
   342  	if err != nil {
   343  		result.Response = autorest.Response{Response: resp}
   344  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetGlossaryFormats", resp, "Failure sending request")
   345  		return
   346  	}
   347  
   348  	result, err = client.GetGlossaryFormatsResponder(resp)
   349  	if err != nil {
   350  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetGlossaryFormats", resp, "Failure responding to request")
   351  		return
   352  	}
   353  
   354  	return
   355  }
   356  
   357  // GetGlossaryFormatsPreparer prepares the GetGlossaryFormats request.
   358  func (client TranslationClient) GetGlossaryFormatsPreparer(ctx context.Context, endpoint string) (*http.Request, error) {
   359  	urlParameters := map[string]interface{}{
   360  		"endpoint": endpoint,
   361  	}
   362  
   363  	preparer := autorest.CreatePreparer(
   364  		autorest.AsGet(),
   365  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   366  		autorest.WithPath("/glossaries/formats"))
   367  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   368  }
   369  
   370  // GetGlossaryFormatsSender sends the GetGlossaryFormats request. The method will close the
   371  // http.Response Body if it receives an error.
   372  func (client TranslationClient) GetGlossaryFormatsSender(req *http.Request) (*http.Response, error) {
   373  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   374  }
   375  
   376  // GetGlossaryFormatsResponder handles the response to the GetGlossaryFormats request. The method always
   377  // closes the http.Response Body.
   378  func (client TranslationClient) GetGlossaryFormatsResponder(resp *http.Response) (result FileFormatListResult, err error) {
   379  	err = autorest.Respond(
   380  		resp,
   381  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   382  		autorest.ByUnmarshallingJSON(&result),
   383  		autorest.ByClosing())
   384  	result.Response = autorest.Response{Response: resp}
   385  	return
   386  }
   387  
   388  // GetOperationDocumentsStatus returns the status of the list of documents translation operation by a given operation
   389  // id.
   390  //
   391  // The documents are sorted by the document Id
   392  //
   393  // If the number of documents exceed our paging limit, server side paging will be used.
   394  // Paginated responses will indicate a partial result by including a continuation token in the response. The absence of
   395  // a continuation token means that no additional pages are available.
   396  //
   397  // Clients MAY use $top and $skip query parameters to specify a number of results to return and an offset into the
   398  // collection.
   399  // The server will honor the values specified by the client; however, clients MUST be prepared to handle responses that
   400  // contain a different page size or contain a continuation token.
   401  // When both $top and $skip are given by a client, the server SHOULD first apply $skip and then $top on the collection.
   402  // Note: If the server can't honor $top and/or $skip, the server MUST return an error to the client informing about it
   403  // instead of just ignoring the query options. This will avoid the risk of the client making assumptions about the data
   404  // returned.
   405  // Parameters:
   406  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   407  // https://westus.api.cognitive.microsoft.com).
   408  // ID - format - uuid.  The operation id
   409  // top - take the $top entries in the collection
   410  // When both $top and $skip are supplied, $skip is applied first
   411  // skip - skip the $skip entries in the collection
   412  // When both $top and $skip are supplied, $skip is applied first
   413  func (client TranslationClient) GetOperationDocumentsStatus(ctx context.Context, endpoint string, ID uuid.UUID, top *int32, skip *int32) (result DocumentStatusResponse, err error) {
   414  	if tracing.IsEnabled() {
   415  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.GetOperationDocumentsStatus")
   416  		defer func() {
   417  			sc := -1
   418  			if result.Response.Response != nil {
   419  				sc = result.Response.Response.StatusCode
   420  			}
   421  			tracing.EndSpan(ctx, sc, err)
   422  		}()
   423  	}
   424  	if err := validation.Validate([]validation.Validation{
   425  		{TargetValue: top,
   426  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   427  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil},
   428  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
   429  				}}}},
   430  		{TargetValue: skip,
   431  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
   432  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMaximum, Rule: int64(2147483647), Chain: nil},
   433  					{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
   434  				}}}}}); err != nil {
   435  		return result, validation.NewError("translatortext.TranslationClient", "GetOperationDocumentsStatus", err.Error())
   436  	}
   437  
   438  	req, err := client.GetOperationDocumentsStatusPreparer(ctx, endpoint, ID, top, skip)
   439  	if err != nil {
   440  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperationDocumentsStatus", nil, "Failure preparing request")
   441  		return
   442  	}
   443  
   444  	resp, err := client.GetOperationDocumentsStatusSender(req)
   445  	if err != nil {
   446  		result.Response = autorest.Response{Response: resp}
   447  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperationDocumentsStatus", resp, "Failure sending request")
   448  		return
   449  	}
   450  
   451  	result, err = client.GetOperationDocumentsStatusResponder(resp)
   452  	if err != nil {
   453  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperationDocumentsStatus", resp, "Failure responding to request")
   454  		return
   455  	}
   456  
   457  	return
   458  }
   459  
   460  // GetOperationDocumentsStatusPreparer prepares the GetOperationDocumentsStatus request.
   461  func (client TranslationClient) GetOperationDocumentsStatusPreparer(ctx context.Context, endpoint string, ID uuid.UUID, top *int32, skip *int32) (*http.Request, error) {
   462  	urlParameters := map[string]interface{}{
   463  		"endpoint": endpoint,
   464  	}
   465  
   466  	pathParameters := map[string]interface{}{
   467  		"id": autorest.Encode("path", ID),
   468  	}
   469  
   470  	queryParameters := map[string]interface{}{}
   471  	if top != nil {
   472  		queryParameters["$top"] = autorest.Encode("query", *top)
   473  	} else {
   474  		queryParameters["$top"] = autorest.Encode("query", 50)
   475  	}
   476  	if skip != nil {
   477  		queryParameters["$skip"] = autorest.Encode("query", *skip)
   478  	} else {
   479  		queryParameters["$skip"] = autorest.Encode("query", 0)
   480  	}
   481  
   482  	preparer := autorest.CreatePreparer(
   483  		autorest.AsGet(),
   484  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   485  		autorest.WithPathParameters("/batches/{id}/documents", pathParameters),
   486  		autorest.WithQueryParameters(queryParameters))
   487  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   488  }
   489  
   490  // GetOperationDocumentsStatusSender sends the GetOperationDocumentsStatus request. The method will close the
   491  // http.Response Body if it receives an error.
   492  func (client TranslationClient) GetOperationDocumentsStatusSender(req *http.Request) (*http.Response, error) {
   493  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   494  }
   495  
   496  // GetOperationDocumentsStatusResponder handles the response to the GetOperationDocumentsStatus request. The method always
   497  // closes the http.Response Body.
   498  func (client TranslationClient) GetOperationDocumentsStatusResponder(resp *http.Response) (result DocumentStatusResponse, err error) {
   499  	err = autorest.Respond(
   500  		resp,
   501  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   502  		autorest.ByUnmarshallingJSON(&result),
   503  		autorest.ByClosing())
   504  	result.Response = autorest.Response{Response: resp}
   505  	return
   506  }
   507  
   508  // GetOperations returns the list of status of the translation batch operation.
   509  // The list will consist only of the batch request submitted by the user (based on their subscription)
   510  //
   511  // The operation status are sorted by the operation Id
   512  //
   513  // If the number of operations exceed our paging limit, server side paging will be used.
   514  // Paginated responses will indicate a partial result by including a continuation token in the response. The absence of
   515  // a continuation token means that no additional pages are available.
   516  //
   517  // Clients MAY use $top and $skip query parameters to specify a number of results to return and an offset into the
   518  // collection.
   519  // The server will honor the values specified by the client; however, clients MUST be prepared to handle responses that
   520  // contain a different page size or contain a continuation token.
   521  // When both $top and $skip are given by a client, the server SHOULD first apply $skip and then $top on the collection.
   522  // Note: If the server can't honor $top and/or $skip, the server MUST return an error to the client informing about it
   523  // instead of just ignoring the query options. This will avoid the risk of the client making assumptions about the data
   524  // returned.
   525  // Parameters:
   526  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   527  // https://westus.api.cognitive.microsoft.com).
   528  // top - take the $top entries in the collection
   529  // When both $top and $skip are supplied, $skip is applied first
   530  // skip - skip the $skip entries in the collection
   531  // When both $top and $skip are supplied, $skip is applied first
   532  func (client TranslationClient) GetOperations(ctx context.Context, endpoint string, top *int32, skip *int32) (result BatchStatusResponse, err error) {
   533  	if tracing.IsEnabled() {
   534  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.GetOperations")
   535  		defer func() {
   536  			sc := -1
   537  			if result.Response.Response != nil {
   538  				sc = result.Response.Response.StatusCode
   539  			}
   540  			tracing.EndSpan(ctx, sc, err)
   541  		}()
   542  	}
   543  	if err := validation.Validate([]validation.Validation{
   544  		{TargetValue: top,
   545  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   546  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil},
   547  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
   548  				}}}},
   549  		{TargetValue: skip,
   550  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
   551  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMaximum, Rule: int64(2147483647), Chain: nil},
   552  					{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
   553  				}}}}}); err != nil {
   554  		return result, validation.NewError("translatortext.TranslationClient", "GetOperations", err.Error())
   555  	}
   556  
   557  	req, err := client.GetOperationsPreparer(ctx, endpoint, top, skip)
   558  	if err != nil {
   559  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperations", nil, "Failure preparing request")
   560  		return
   561  	}
   562  
   563  	resp, err := client.GetOperationsSender(req)
   564  	if err != nil {
   565  		result.Response = autorest.Response{Response: resp}
   566  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperations", resp, "Failure sending request")
   567  		return
   568  	}
   569  
   570  	result, err = client.GetOperationsResponder(resp)
   571  	if err != nil {
   572  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperations", resp, "Failure responding to request")
   573  		return
   574  	}
   575  
   576  	return
   577  }
   578  
   579  // GetOperationsPreparer prepares the GetOperations request.
   580  func (client TranslationClient) GetOperationsPreparer(ctx context.Context, endpoint string, top *int32, skip *int32) (*http.Request, error) {
   581  	urlParameters := map[string]interface{}{
   582  		"endpoint": endpoint,
   583  	}
   584  
   585  	queryParameters := map[string]interface{}{}
   586  	if top != nil {
   587  		queryParameters["$top"] = autorest.Encode("query", *top)
   588  	} else {
   589  		queryParameters["$top"] = autorest.Encode("query", 50)
   590  	}
   591  	if skip != nil {
   592  		queryParameters["$skip"] = autorest.Encode("query", *skip)
   593  	} else {
   594  		queryParameters["$skip"] = autorest.Encode("query", 0)
   595  	}
   596  
   597  	preparer := autorest.CreatePreparer(
   598  		autorest.AsGet(),
   599  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   600  		autorest.WithPath("/batches"),
   601  		autorest.WithQueryParameters(queryParameters))
   602  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   603  }
   604  
   605  // GetOperationsSender sends the GetOperations request. The method will close the
   606  // http.Response Body if it receives an error.
   607  func (client TranslationClient) GetOperationsSender(req *http.Request) (*http.Response, error) {
   608  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   609  }
   610  
   611  // GetOperationsResponder handles the response to the GetOperations request. The method always
   612  // closes the http.Response Body.
   613  func (client TranslationClient) GetOperationsResponder(resp *http.Response) (result BatchStatusResponse, 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  // GetOperationStatus returns the status of the translation batch operation.
   624  // The status will include the overall job status as well as a summary of the current progress of all the documents
   625  // being translated.
   626  // Parameters:
   627  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   628  // https://westus.api.cognitive.microsoft.com).
   629  // ID - format - uuid.  The operation id
   630  func (client TranslationClient) GetOperationStatus(ctx context.Context, endpoint string, ID uuid.UUID) (result BatchStatusDetail, err error) {
   631  	if tracing.IsEnabled() {
   632  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.GetOperationStatus")
   633  		defer func() {
   634  			sc := -1
   635  			if result.Response.Response != nil {
   636  				sc = result.Response.Response.StatusCode
   637  			}
   638  			tracing.EndSpan(ctx, sc, err)
   639  		}()
   640  	}
   641  	req, err := client.GetOperationStatusPreparer(ctx, endpoint, ID)
   642  	if err != nil {
   643  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperationStatus", nil, "Failure preparing request")
   644  		return
   645  	}
   646  
   647  	resp, err := client.GetOperationStatusSender(req)
   648  	if err != nil {
   649  		result.Response = autorest.Response{Response: resp}
   650  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperationStatus", resp, "Failure sending request")
   651  		return
   652  	}
   653  
   654  	result, err = client.GetOperationStatusResponder(resp)
   655  	if err != nil {
   656  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "GetOperationStatus", resp, "Failure responding to request")
   657  		return
   658  	}
   659  
   660  	return
   661  }
   662  
   663  // GetOperationStatusPreparer prepares the GetOperationStatus request.
   664  func (client TranslationClient) GetOperationStatusPreparer(ctx context.Context, endpoint string, ID uuid.UUID) (*http.Request, error) {
   665  	urlParameters := map[string]interface{}{
   666  		"endpoint": endpoint,
   667  	}
   668  
   669  	pathParameters := map[string]interface{}{
   670  		"id": autorest.Encode("path", ID),
   671  	}
   672  
   673  	preparer := autorest.CreatePreparer(
   674  		autorest.AsGet(),
   675  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   676  		autorest.WithPathParameters("/batches/{id}", pathParameters))
   677  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   678  }
   679  
   680  // GetOperationStatusSender sends the GetOperationStatus request. The method will close the
   681  // http.Response Body if it receives an error.
   682  func (client TranslationClient) GetOperationStatusSender(req *http.Request) (*http.Response, error) {
   683  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   684  }
   685  
   686  // GetOperationStatusResponder handles the response to the GetOperationStatus request. The method always
   687  // closes the http.Response Body.
   688  func (client TranslationClient) GetOperationStatusResponder(resp *http.Response) (result BatchStatusDetail, err error) {
   689  	err = autorest.Respond(
   690  		resp,
   691  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   692  		autorest.ByUnmarshallingJSON(&result),
   693  		autorest.ByClosing())
   694  	result.Response = autorest.Response{Response: resp}
   695  	return
   696  }
   697  
   698  // SubmitBatchRequest submit a batch request to the document translation service.
   699  //
   700  // Each request can consists of multiple inputs.
   701  // Each input will contains both a source and destination container for source and target language pair.
   702  //
   703  // The prefix and suffix filter (if supplied) will be used to filter the folders.
   704  // The prefix will be applied to the subpath after the container name
   705  //
   706  // Glossaries / Translation memory can be supplied and will be applied when the document is being translated.
   707  // If the glossary is invalid or unreachable during translation time.  An error will be indicated in the document
   708  // status.
   709  //
   710  // If the file with the same name already exists in the destination, it will be overwritten.
   711  // TargetUrl for each target language needs to be unique.
   712  // Parameters:
   713  // endpoint - supported Cognitive Services endpoints (protocol and hostname, for example:
   714  // https://westus.api.cognitive.microsoft.com).
   715  // body - request details
   716  func (client TranslationClient) SubmitBatchRequest(ctx context.Context, endpoint string, body *BatchSubmissionRequest) (result autorest.Response, err error) {
   717  	if tracing.IsEnabled() {
   718  		ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.SubmitBatchRequest")
   719  		defer func() {
   720  			sc := -1
   721  			if result.Response != nil {
   722  				sc = result.Response.StatusCode
   723  			}
   724  			tracing.EndSpan(ctx, sc, err)
   725  		}()
   726  	}
   727  	if err := validation.Validate([]validation.Validation{
   728  		{TargetValue: body,
   729  			Constraints: []validation.Constraint{{Target: "body", Name: validation.Null, Rule: false,
   730  				Chain: []validation.Constraint{{Target: "body.Inputs", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
   731  		return result, validation.NewError("translatortext.TranslationClient", "SubmitBatchRequest", err.Error())
   732  	}
   733  
   734  	req, err := client.SubmitBatchRequestPreparer(ctx, endpoint, body)
   735  	if err != nil {
   736  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "SubmitBatchRequest", nil, "Failure preparing request")
   737  		return
   738  	}
   739  
   740  	resp, err := client.SubmitBatchRequestSender(req)
   741  	if err != nil {
   742  		result.Response = resp
   743  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "SubmitBatchRequest", resp, "Failure sending request")
   744  		return
   745  	}
   746  
   747  	result, err = client.SubmitBatchRequestResponder(resp)
   748  	if err != nil {
   749  		err = autorest.NewErrorWithError(err, "translatortext.TranslationClient", "SubmitBatchRequest", resp, "Failure responding to request")
   750  		return
   751  	}
   752  
   753  	return
   754  }
   755  
   756  // SubmitBatchRequestPreparer prepares the SubmitBatchRequest request.
   757  func (client TranslationClient) SubmitBatchRequestPreparer(ctx context.Context, endpoint string, body *BatchSubmissionRequest) (*http.Request, error) {
   758  	urlParameters := map[string]interface{}{
   759  		"endpoint": endpoint,
   760  	}
   761  
   762  	preparer := autorest.CreatePreparer(
   763  		autorest.AsContentType("application/json; charset=utf-8"),
   764  		autorest.AsPost(),
   765  		autorest.WithCustomBaseURL("{endpoint}/translator/text/batch/v1.0-preview.1", urlParameters),
   766  		autorest.WithPath("/batches"))
   767  	if body != nil {
   768  		preparer = autorest.DecoratePreparer(preparer,
   769  			autorest.WithJSON(body))
   770  	}
   771  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   772  }
   773  
   774  // SubmitBatchRequestSender sends the SubmitBatchRequest request. The method will close the
   775  // http.Response Body if it receives an error.
   776  func (client TranslationClient) SubmitBatchRequestSender(req *http.Request) (*http.Response, error) {
   777  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   778  }
   779  
   780  // SubmitBatchRequestResponder handles the response to the SubmitBatchRequest request. The method always
   781  // closes the http.Response Body.
   782  func (client TranslationClient) SubmitBatchRequestResponder(resp *http.Response) (result autorest.Response, err error) {
   783  	err = autorest.Respond(
   784  		resp,
   785  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   786  		autorest.ByClosing())
   787  	result.Response = resp
   788  	return
   789  }
   790  

View as plain text