From 26ea89da46a412fd7b42d2fd0640dacb7c9ec5a5 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Fri, 27 Nov 2020 03:26:44 +0000 Subject: [PATCH] CodeGen from PR 11826 in Azure/azure-rest-api-specs Fix errors in various of readme files encountered in the recent go SDK release (#11826) * Fix an issue on windows * Fix cdn * Fix cognitiveservices/customVision * Fix cognitiveservices/personalizer * Fix cognitiveservices/translatorText * Fix data plane digitaltwins * Remove problematic tag from release - no impact on sdk, this has never been released * amend Fix cognitiveservices/translatorText * Fix imds * Fix migrate readme that are mistakenly damaged in #10305 * add one api-version back * Fix digtaltwins data plane again * Fix hybridnetwork * Fix streamanlytics * Revert some changes of digitaltwins * Revert imds * Fix migrate * Fix migrate again --- .../v1.0_preview.1/translatortext/client.go | 42 + .../v1.0_preview.1/translatortext/enums.go | 130 +++ .../v1.0_preview.1/translatortext/models.go | 250 ++++++ .../translatortext/translation.go | 792 ++++++++++++++++++ .../translatortextapi/interfaces.go | 39 + .../v1.0_preview.1/translatortext/version.go | 30 + 6 files changed, 1283 insertions(+) create mode 100644 services/preview/cognitiveservices/v1.0_preview.1/translatortext/client.go create mode 100644 services/preview/cognitiveservices/v1.0_preview.1/translatortext/enums.go create mode 100644 services/preview/cognitiveservices/v1.0_preview.1/translatortext/models.go create mode 100644 services/preview/cognitiveservices/v1.0_preview.1/translatortext/translation.go create mode 100644 services/preview/cognitiveservices/v1.0_preview.1/translatortext/translatortextapi/interfaces.go create mode 100644 services/preview/cognitiveservices/v1.0_preview.1/translatortext/version.go diff --git a/services/preview/cognitiveservices/v1.0_preview.1/translatortext/client.go b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/client.go new file mode 100644 index 000000000000..c5f9cc4d1ec5 --- /dev/null +++ b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/client.go @@ -0,0 +1,42 @@ +// Package translatortext implements the Azure ARM Translatortext service API version v1.0-preview.1. +// +// +package translatortext + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +// BaseClient is the base client for Translatortext. +type BaseClient struct { + autorest.Client +} + +// New creates an instance of the BaseClient client. +func New() BaseClient { + return NewWithoutDefaults() +} + +// NewWithoutDefaults creates an instance of the BaseClient client. +func NewWithoutDefaults() BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + } +} diff --git a/services/preview/cognitiveservices/v1.0_preview.1/translatortext/enums.go b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/enums.go new file mode 100644 index 000000000000..c0ac6942456d --- /dev/null +++ b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/enums.go @@ -0,0 +1,130 @@ +package translatortext + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// Code enumerates the values for code. +type Code string + +const ( + // InternalServerError ... + InternalServerError Code = "InternalServerError" + // InvalidArgument ... + InvalidArgument Code = "InvalidArgument" + // InvalidRequest ... + InvalidRequest Code = "InvalidRequest" + // RequestRateTooHigh ... + RequestRateTooHigh Code = "RequestRateTooHigh" + // ResourceNotFound ... + ResourceNotFound Code = "ResourceNotFound" + // ServiceUnavailable ... + ServiceUnavailable Code = "ServiceUnavailable" + // Unauthorized ... + Unauthorized Code = "Unauthorized" +) + +// PossibleCodeValues returns an array of possible values for the Code const type. +func PossibleCodeValues() []Code { + return []Code{InternalServerError, InvalidArgument, InvalidRequest, RequestRateTooHigh, ResourceNotFound, ServiceUnavailable, Unauthorized} +} + +// Status enumerates the values for status. +type Status string + +const ( + // Cancelled ... + Cancelled Status = "Cancelled" + // Cancelling ... + Cancelling Status = "Cancelling" + // Failed ... + Failed Status = "Failed" + // NotStarted ... + NotStarted Status = "NotStarted" + // Running ... + Running Status = "Running" + // Succeeded ... + Succeeded Status = "Succeeded" +) + +// PossibleStatusValues returns an array of possible values for the Status const type. +func PossibleStatusValues() []Status { + return []Status{Cancelled, Cancelling, Failed, NotStarted, Running, Succeeded} +} + +// Status1 enumerates the values for status 1. +type Status1 string + +const ( + // Status1Cancelled ... + Status1Cancelled Status1 = "Cancelled" + // Status1Cancelling ... + Status1Cancelling Status1 = "Cancelling" + // Status1Failed ... + Status1Failed Status1 = "Failed" + // Status1NotStarted ... + Status1NotStarted Status1 = "NotStarted" + // Status1Running ... + Status1Running Status1 = "Running" + // Status1Succeeded ... + Status1Succeeded Status1 = "Succeeded" +) + +// PossibleStatus1Values returns an array of possible values for the Status1 const type. +func PossibleStatus1Values() []Status1 { + return []Status1{Status1Cancelled, Status1Cancelling, Status1Failed, Status1NotStarted, Status1Running, Status1Succeeded} +} + +// StorageSource enumerates the values for storage source. +type StorageSource string + +const ( + // AzureBlob ... + AzureBlob StorageSource = "AzureBlob" +) + +// PossibleStorageSourceValues returns an array of possible values for the StorageSource const type. +func PossibleStorageSourceValues() []StorageSource { + return []StorageSource{AzureBlob} +} + +// StorageSource1 enumerates the values for storage source 1. +type StorageSource1 string + +const ( + // StorageSource1AzureBlob ... + StorageSource1AzureBlob StorageSource1 = "AzureBlob" +) + +// PossibleStorageSource1Values returns an array of possible values for the StorageSource1 const type. +func PossibleStorageSource1Values() []StorageSource1 { + return []StorageSource1{StorageSource1AzureBlob} +} + +// StorageType enumerates the values for storage type. +type StorageType string + +const ( + // File ... + File StorageType = "File" + // Folder ... + Folder StorageType = "Folder" +) + +// PossibleStorageTypeValues returns an array of possible values for the StorageType const type. +func PossibleStorageTypeValues() []StorageType { + return []StorageType{File, Folder} +} diff --git a/services/preview/cognitiveservices/v1.0_preview.1/translatortext/models.go b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/models.go new file mode 100644 index 000000000000..e93a9505c0fb --- /dev/null +++ b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/models.go @@ -0,0 +1,250 @@ +package translatortext + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" + "github.com/satori/go.uuid" +) + +// The package's fully qualified name. +const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v1.0_preview.1/translatortext" + +// BatchRequest definition for the input batch translation request +type BatchRequest struct { + Source *SourceInput `json:"source,omitempty"` + // Targets - Location of the destination for the output + Targets *[]TargetInput `json:"targets,omitempty"` + // StorageType - Possible values include: 'Folder', 'File' + StorageType StorageType `json:"storageType,omitempty"` +} + +// BatchStatusDetail job status response +type BatchStatusDetail struct { + // ID - Id of the operation. + ID *uuid.UUID `json:"id,omitempty"` + // CreatedDateTimeUtc - Operation created date time + CreatedDateTimeUtc *date.Time `json:"createdDateTimeUtc,omitempty"` + // LastActionDateTimeUtc - Date time in which the operation's status has been updated + LastActionDateTimeUtc *date.Time `json:"lastActionDateTimeUtc,omitempty"` + // Status - Possible values include: 'NotStarted', 'Running', 'Succeeded', 'Failed', 'Cancelled', 'Cancelling' + Status Status `json:"status,omitempty"` + Summary *StatusSummary `json:"summary,omitempty"` +} + +// BatchStatusResponse document Status Response +type BatchStatusResponse struct { + // Value - The summary status of individual operation + Value *[]BatchStatusDetail `json:"value,omitempty"` + // NextLink - Url for the next page. Null if no more pages available + NextLink *string `json:"@nextLink,omitempty"` +} + +// BatchSubmissionRequest job submission batch request +type BatchSubmissionRequest struct { + // Inputs - The input list of documents or folders containing documents + Inputs *[]BatchRequest `json:"inputs,omitempty"` +} + +// DocumentFilter ... +type DocumentFilter struct { + // Prefix - A case-sensitive prefix string to filter documents in the source path for translation. + // For example, when using a Azure storage blob Uri, use the prefix to restrict sub folders for translation. + Prefix *string `json:"prefix,omitempty"` + // Suffix - A case-sensitive suffix string to filter documents in the source path for translation. + // This is most often use for file extensions + Suffix *string `json:"suffix,omitempty"` +} + +// DocumentStatusDetail ... +type DocumentStatusDetail struct { + // Path - Location of the document or folder + Path *string `json:"path,omitempty"` + // CreatedDateTimeUtc - Operation created date time + CreatedDateTimeUtc *date.Time `json:"createdDateTimeUtc,omitempty"` + // LastActionDateTimeUtc - Date time in which the operation's status has been updated + LastActionDateTimeUtc *date.Time `json:"lastActionDateTimeUtc,omitempty"` + // Status - Possible values include: 'Status1NotStarted', 'Status1Running', 'Status1Succeeded', 'Status1Failed', 'Status1Cancelled', 'Status1Cancelling' + Status Status1 `json:"status,omitempty"` + // DetectedLanguage - Detected language of the original document (to be implemented) + DetectedLanguage *string `json:"detectedLanguage,omitempty"` + // To - To language + To *string `json:"to,omitempty"` + Error *ErrorV2 `json:"error,omitempty"` + // Progress - Progress of the translation if available + Progress *float64 `json:"progress,omitempty"` + // ID - Document Id + ID *uuid.UUID `json:"id,omitempty"` +} + +// DocumentStatusResponse document Status Response +type DocumentStatusResponse struct { + // Value - The detail status of individual documents + Value *[]DocumentStatusDetail `json:"value,omitempty"` + // NextLink - Url for the next page. Null if no more pages available + NextLink *string `json:"@nextLink,omitempty"` +} + +// ErrorResponseV2 contains unified error information used for HTTP responses across any Cognitive Service. +// Instances +// can be created either through Microsoft.CloudAI.Containers.HttpStatusExceptionV2 or by returning it +// directly from +// a controller. +type ErrorResponseV2 struct { + autorest.Response `json:"-"` + Error *ErrorV2 `json:"error,omitempty"` +} + +// ErrorV2 this contains an outer error with error code, message, details, target and an inner error with +// more descriptive details. +type ErrorV2 struct { + // Code - Possible values include: 'InvalidRequest', 'InvalidArgument', 'InternalServerError', 'ServiceUnavailable', 'ResourceNotFound', 'Unauthorized', 'RequestRateTooHigh' + Code Code `json:"code,omitempty"` + // Message - READ-ONLY; Gets high level error message. + Message *string `json:"message,omitempty"` + // Target - READ-ONLY; Gets the source of the error. + // For example it would be "documents" or "document id" in case of invalid document. + Target *string `json:"target,omitempty"` + InnerError *InnerErrorV2 `json:"innerError,omitempty"` +} + +// MarshalJSON is the custom marshaler for ErrorV2. +func (ev ErrorV2) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ev.Code != "" { + objectMap["code"] = ev.Code + } + if ev.InnerError != nil { + objectMap["innerError"] = ev.InnerError + } + return json.Marshal(objectMap) +} + +// FileFormat ... +type FileFormat struct { + // Format - Name of the format + Format *string `json:"format,omitempty"` + // FileExtensions - Supported file extension for this format + FileExtensions *[]string `json:"fileExtensions,omitempty"` + // ContentTypes - Supported Content-Types for this format + ContentTypes *[]string `json:"contentTypes,omitempty"` + // Versions - Supported Version + Versions *[]string `json:"versions,omitempty"` +} + +// FileFormatListResult base type for List return in our api +type FileFormatListResult struct { + // Value - list of objects + Value *[]FileFormat `json:"value,omitempty"` +} + +// Glossary glossary / translation memory for the request +type Glossary struct { + // GlossaryURL - Location of the glossary. + // We will use the file extension to extract the formating if the format parameter is not supplied. + // + // If the translation language pair is not present in the glossary, it will not be applied + GlossaryURL *string `json:"glossaryUrl,omitempty"` + // Format - Format + Format *string `json:"format,omitempty"` + // Version - Version + Version *string `json:"version,omitempty"` +} + +// InnerErrorV2 new Inner Error format which conforms to Cognitive Services API Guidelines which is +// available at +// https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow. +// This contains required properties ErrorCode, message and optional properties target, details(key value +// pair), inner error(this can be nested). +type InnerErrorV2 struct { + // Code - READ-ONLY; Gets detailed error code. + Code *int32 `json:"code,omitempty"` + // Error - READ-ONLY; Gets detailed error string. + Error *string `json:"error,omitempty"` + // Message - READ-ONLY; Gets high level error message. + Message *string `json:"message,omitempty"` + // Target - READ-ONLY; Gets the source of the error. + // For example it would be "documents" or "document id" in case of invalid document. + Target *string `json:"target,omitempty"` + InnerError *InnerErrorV2 `json:"innerError,omitempty"` +} + +// MarshalJSON is the custom marshaler for InnerErrorV2. +func (iev InnerErrorV2) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if iev.InnerError != nil { + objectMap["innerError"] = iev.InnerError + } + return json.Marshal(objectMap) +} + +// SetObject ... +type SetObject struct { + autorest.Response `json:"-"` + Value interface{} `json:"value,omitempty"` +} + +// SourceInput source of the input documents +type SourceInput struct { + // SourceURL - Location of the folder / container or single file with your documents + SourceURL *string `json:"sourceUrl,omitempty"` + Filter *DocumentFilter `json:"filter,omitempty"` + // Language - Language code + // If none is specified, we will perform auto detect on the document + Language *string `json:"language,omitempty"` + // StorageSource - Possible values include: 'AzureBlob' + StorageSource StorageSource `json:"storageSource,omitempty"` +} + +// StatusSummary ... +type StatusSummary struct { + // Total - Total count + Total *int32 `json:"total,omitempty"` + // Failed - Failed count + Failed *int32 `json:"failed,omitempty"` + // Success - Number of Success + Success *int32 `json:"success,omitempty"` + // InProgress - Number of in progress + InProgress *int32 `json:"inProgress,omitempty"` + // NotYetStarted - Count of not yet started + NotYetStarted *int32 `json:"notYetStarted,omitempty"` + // Cancelled - Number of cancelled + Cancelled *int32 `json:"cancelled,omitempty"` +} + +// StorageSourceListResult base type for List return in our api +type StorageSourceListResult struct { + // Value - list of objects + Value *[]string `json:"value,omitempty"` +} + +// TargetInput destination for the finished translated documents +type TargetInput struct { + // TargetURL - Location of the folder / container with your documents + TargetURL *string `json:"targetUrl,omitempty"` + // Category - Category / custom system for translation request + Category *string `json:"category,omitempty"` + // Language - Target Language + Language *string `json:"language,omitempty"` + // Glossaries - List of Glossary + Glossaries *[]Glossary `json:"glossaries,omitempty"` + // StorageSource - Possible values include: 'StorageSource1AzureBlob' + StorageSource StorageSource1 `json:"storageSource,omitempty"` +} diff --git a/services/preview/cognitiveservices/v1.0_preview.1/translatortext/translation.go b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/translation.go new file mode 100644 index 000000000000..866faa7f2694 --- /dev/null +++ b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/translation.go @@ -0,0 +1,792 @@ +package translatortext + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// 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/satori/go.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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusUnauthorized, http.StatusNotFound, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusUnauthorized, http.StatusNotFound, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusBadRequest, http.StatusUnauthorized, http.StatusNotFound, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusBadRequest, http.StatusUnauthorized, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 SetObject, 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 +} + +// 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 SetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusUnauthorized, http.StatusNotFound, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result.Value), + 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 ErrorResponseV2, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/TranslationClient.SubmitBatchRequest") + 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: 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 = autorest.Response{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 +} + +// 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 ErrorResponseV2, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusBadRequest, http.StatusUnauthorized, http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/cognitiveservices/v1.0_preview.1/translatortext/translatortextapi/interfaces.go b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/translatortextapi/interfaces.go new file mode 100644 index 000000000000..29bd036d8c45 --- /dev/null +++ b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/translatortextapi/interfaces.go @@ -0,0 +1,39 @@ +package translatortextapi + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// 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/azure-sdk-for-go/services/preview/cognitiveservices/v1.0_preview.1/translatortext" + "github.com/satori/go.uuid" +) + +// TranslationClientAPI contains the set of methods on the TranslationClient type. +type TranslationClientAPI interface { + CancelOperation(ctx context.Context, endpoint string, ID uuid.UUID) (result translatortext.SetObject, err error) + GetDocumentFormats(ctx context.Context, endpoint string) (result translatortext.SetObject, err error) + GetDocumentStatus(ctx context.Context, endpoint string, ID uuid.UUID, documentID uuid.UUID) (result translatortext.SetObject, err error) + GetDocumentStorageSource(ctx context.Context, endpoint string) (result translatortext.SetObject, err error) + GetGlossaryFormats(ctx context.Context, endpoint string) (result translatortext.SetObject, err error) + GetOperationDocumentsStatus(ctx context.Context, endpoint string, ID uuid.UUID, top *int32, skip *int32) (result translatortext.SetObject, err error) + GetOperations(ctx context.Context, endpoint string, top *int32, skip *int32) (result translatortext.SetObject, err error) + GetOperationStatus(ctx context.Context, endpoint string, ID uuid.UUID) (result translatortext.SetObject, err error) + SubmitBatchRequest(ctx context.Context, endpoint string, body *translatortext.BatchSubmissionRequest) (result translatortext.ErrorResponseV2, err error) +} + +var _ TranslationClientAPI = (*translatortext.TranslationClient)(nil) diff --git a/services/preview/cognitiveservices/v1.0_preview.1/translatortext/version.go b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/version.go new file mode 100644 index 000000000000..ad65d9b47745 --- /dev/null +++ b/services/preview/cognitiveservices/v1.0_preview.1/translatortext/version.go @@ -0,0 +1,30 @@ +package translatortext + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + Version() + " translatortext/v1.0-preview.1" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +}