...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v3.0/translatortext/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v3.0/translatortext

     1  // Package translatortext implements the Azure ARM Translatortext service API version 3.0.
     2  //
     3  // # Introduction
     4  //
     5  // The Microsoft Translator Text API provides a JSON-based Web API. It provides:
     6  //
     7  // * Translation between any supported languages to any other supported language.
     8  // * Translation to multiple languages in one request.
     9  // * Transliteration to convert text from one script to another script of the same language.
    10  // * Language detection, translation, and transliteration in one request.
    11  // * Dictionary to lookup alternative translations of a term, to find back-translations and examples showing terms used
    12  // in context.
    13  // * Rich language detection.
    14  // # Base URLs
    15  //
    16  // The Translator Text API is available in the following clouds:
    17  //
    18  // | Description | Region    | Base URL                                |
    19  // | -------     | --------  | -------                                 |
    20  // | Azure       | Global    | api.cognitive.microsofttranslator.com   |
    21  // | Azure       | Europe    | api-eur.cognitive.microsofttranslator.com |
    22  //
    23  //
    24  // # Authentication
    25  //
    26  // Subscribe to the Translator Text API, part of Azure Cognitive Services, and use your subscription key from the Azure
    27  // portal to authenticate. You can follow the steps in
    28  // https://docs.microsoft.com/en-us/azure/cognitive-services/translator/translator-text-how-to-signup.
    29  //
    30  //
    31  // The simplest way is to pass your Azure secret key to the Translator service using the http request header
    32  // `Ocp-Apim-Subscription-Key`.
    33  //
    34  // If you prefer using a short-lived authentication, you may use your secret key to obtain an authorization token from
    35  // the token service. In that case you pass the authorization token to the Translator service using the `Authorization`
    36  // request header. To obtain an authorization token, make a `POST` request to the following URL:
    37  //
    38  // | Environment | Authentication service URL                                |
    39  // | ----------  | ----------                                                |
    40  // | Azure       | `https://api.cognitive.microsoft.com/sts/v1.0/issueToken` |
    41  //
    42  // Here are example requests to obtain a token with a lifetime of 10 minutes, given a secret key:
    43  //
    44  // ```python
    45  // // Pass secret key using header
    46  // curl --header 'Ocp-Apim-Subscription-Key: <your-key>' --data ""
    47  // 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken'
    48  // // Pass secret key using query string parameter
    49  // curl --data "" 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken?Subscription-Key=<your-key>'
    50  // ```
    51  //
    52  // A successful request returns the encoded access token as plain text in the response body. The valid token is passed
    53  // to the Translator service as a bearer token in the Authorization.
    54  //
    55  // ```
    56  // Authorization: Bearer <Base64-access_token>
    57  // ```
    58  //
    59  // An authentication token is valid for 10 minutes. The token should be re-used when making multiple calls to the
    60  // Translator APIs. If you make requests to the Translator API over an extended period of time,  you  must request a
    61  // new access token at regular intervals before the token expires, for instance every 9 minutes.
    62  //
    63  // To summarize, a client request to the Translator API will include one authorization header taken from the following
    64  // table:
    65  //
    66  // | Headers       | Description  |
    67  // | ----------    | ----------   |
    68  // | Ocp-Apim-Subscription-key    | Use with Cognitive Services subscription if you are passing your secret key.
    69  // The value is the Azure secret key for your subscription to Translator Text API.                         |
    70  // | Authorization                | Use with Cognitive Services subscription if you are passing an authentication
    71  // token. The value is the Bearer token: `Bearer <token>`.       |
    72  //
    73  // ## All-in-one subscription
    74  // The last authentication option is to use a Cognitive Service’s all-in-one subscription. This allows you to use a
    75  // single secret key to authenticate requests for multiple services.
    76  // When you use an all-in-one secret key, you must include two authentication headers with your request. The first
    77  // passes the secret key, the second specifies the region associated with your subscription.
    78  // `Ocp-Api-Subscription-Key` `Ocp-Apim-Subscription-Region`
    79  // If you pass the secret key in the query string with the parameter `Subscription-Key`, then you must specify the
    80  // region with query parameter `Subscription-Region`.
    81  // If you use a bearer token, you must obtain the token from the region endpoint:
    82  // `https://<your-region>.api.cognitive.microsoft.com/sts/v1.0/issueToken`.
    83  //
    84  // Available regions are: `australiaeast`, `brazilsouth`, `canadacentral`, `centralindia`, `centraluseuap`, `eastasia`,
    85  // `eastus`, `eastus2`, `japaneast`, `northeurope`, `southcentralus`, `southeastasia`, `uksouth`, `westcentralus`,
    86  // `westeurope`, `westus`, and `westus2`.
    87  //
    88  // Region is required for the all-in-one Text API subscription.
    89  //
    90  //
    91  // # Errors
    92  //
    93  // A standard error response is a JSON object with name/value pair named `error`. The value is also a JSON object with
    94  // properties:
    95  // * `code`: A server-defined error code.
    96  // * `message`: A string giving a human-readable representation of the error.
    97  //
    98  // For example, a customer with a free trial subscription receives the following error once the free quota is
    99  // exhausted:
   100  //
   101  // ```json
   102  // {
   103  // "error": {
   104  // "code":403000,
   105  // "message":"The subscription has exceeded its free quota."
   106  // }
   107  // }
   108  // ```
   109  // # Enter your subscription keys to try out Microsoft Translator.
   110  // Select the `Authorize` button and enter your Microsoft Translator subscription key, OR your `all in one Cognitive
   111  // Services` subscription key. If you are using the all in one Cognitive Services key you will need to also enter your
   112  // subscription region.
   113  // ## Available regions are:
   114  //
   115  // `australiaeast`, `brazilsouth`, `canadacentral`, `centralindia`, `centraluseuap`, `eastasia`, `eastus`, `eastus2`,
   116  // `japaneast`, `northeurope`, `southcentralus`, `southeastasia`, `uksouth`, `westcentralus`, `westeurope`, `westus`,
   117  // `westus2`.
   118  //
   119  package translatortext
   120  
   121  // Copyright (c) Microsoft Corporation. All rights reserved.
   122  // Licensed under the MIT License. See License.txt in the project root for license information.
   123  //
   124  // Code generated by Microsoft (R) AutoRest Code Generator.
   125  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
   126  
   127  import (
   128  	"github.com/Azure/go-autorest/autorest"
   129  )
   130  
   131  // BaseClient is the base client for Translatortext.
   132  type BaseClient struct {
   133  	autorest.Client
   134  	Endpoint string
   135  }
   136  
   137  // New creates an instance of the BaseClient client.
   138  func New(endpoint string) BaseClient {
   139  	return NewWithoutDefaults(endpoint)
   140  }
   141  
   142  // NewWithoutDefaults creates an instance of the BaseClient client.
   143  func NewWithoutDefaults(endpoint string) BaseClient {
   144  	return BaseClient{
   145  		Client:   autorest.NewClientWithUserAgent(UserAgent()),
   146  		Endpoint: endpoint,
   147  	}
   148  }
   149  

View as plain text