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