...

Source file src/google.golang.org/api/translate/v2/translate-gen.go

Documentation: google.golang.org/api/translate/v2

     1  // Copyright 2024 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Code generated file. DO NOT EDIT.
     6  
     7  // Package translate provides access to the Google Cloud Translation API.
     8  //
     9  // This package is DEPRECATED. Use package cloud.google.com/go/translate instead.
    10  //
    11  // For product documentation, see: https://code.google.com/apis/language/translate/v2/getting_started.html
    12  //
    13  // # Library status
    14  //
    15  // These client libraries are officially supported by Google. However, this
    16  // library is considered complete and is in maintenance mode. This means
    17  // that we will address critical bugs and security issues but will not add
    18  // any new features.
    19  //
    20  // When possible, we recommend using our newer
    21  // [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
    22  // that are still actively being worked and iterated on.
    23  //
    24  // # Creating a client
    25  //
    26  // Usage example:
    27  //
    28  //	import "google.golang.org/api/translate/v2"
    29  //	...
    30  //	ctx := context.Background()
    31  //	translateService, err := translate.NewService(ctx)
    32  //
    33  // In this example, Google Application Default Credentials are used for
    34  // authentication. For information on how to create and obtain Application
    35  // Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    36  //
    37  // # Other authentication options
    38  //
    39  // By default, all available scopes (see "Constants") are used to authenticate.
    40  // To restrict scopes, use [google.golang.org/api/option.WithScopes]:
    41  //
    42  //	translateService, err := translate.NewService(ctx, option.WithScopes(translate.CloudTranslationScope))
    43  //
    44  // To use an API key for authentication (note: some APIs do not support API
    45  // keys), use [google.golang.org/api/option.WithAPIKey]:
    46  //
    47  //	translateService, err := translate.NewService(ctx, option.WithAPIKey("AIza..."))
    48  //
    49  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    50  // flow, use [google.golang.org/api/option.WithTokenSource]:
    51  //
    52  //	config := &oauth2.Config{...}
    53  //	// ...
    54  //	token, err := config.Exchange(ctx, ...)
    55  //	translateService, err := translate.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    56  //
    57  // See [google.golang.org/api/option.ClientOption] for details on options.
    58  package translate // import "google.golang.org/api/translate/v2"
    59  
    60  import (
    61  	"bytes"
    62  	"context"
    63  	"encoding/json"
    64  	"errors"
    65  	"fmt"
    66  	"io"
    67  	"net/http"
    68  	"net/url"
    69  	"strconv"
    70  	"strings"
    71  
    72  	googleapi "google.golang.org/api/googleapi"
    73  	internal "google.golang.org/api/internal"
    74  	gensupport "google.golang.org/api/internal/gensupport"
    75  	option "google.golang.org/api/option"
    76  	internaloption "google.golang.org/api/option/internaloption"
    77  	htransport "google.golang.org/api/transport/http"
    78  )
    79  
    80  // Always reference these packages, just in case the auto-generated code
    81  // below doesn't.
    82  var _ = bytes.NewBuffer
    83  var _ = strconv.Itoa
    84  var _ = fmt.Sprintf
    85  var _ = json.NewDecoder
    86  var _ = io.Copy
    87  var _ = url.Parse
    88  var _ = gensupport.MarshalJSON
    89  var _ = googleapi.Version
    90  var _ = errors.New
    91  var _ = strings.Replace
    92  var _ = context.Canceled
    93  var _ = internaloption.WithDefaultEndpoint
    94  var _ = internal.Version
    95  
    96  const apiId = "translate:v2"
    97  const apiName = "translate"
    98  const apiVersion = "v2"
    99  const basePath = "https://translation.googleapis.com/language/translate/"
   100  const basePathTemplate = "https://translation.UNIVERSE_DOMAIN/language/translate/"
   101  
   102  // OAuth2 scopes used by this API.
   103  const (
   104  	// View and manage your data across Google Cloud Platform services
   105  	CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
   106  
   107  	// Translate text from one language to another using Google Translate
   108  	CloudTranslationScope = "https://www.googleapis.com/auth/cloud-translation"
   109  )
   110  
   111  // NewService creates a new Service.
   112  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
   113  	scopesOption := internaloption.WithDefaultScopes(
   114  		"https://www.googleapis.com/auth/cloud-platform",
   115  		"https://www.googleapis.com/auth/cloud-translation",
   116  	)
   117  	// NOTE: prepend, so we don't override user-specified scopes.
   118  	opts = append([]option.ClientOption{scopesOption}, opts...)
   119  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   120  	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   121  	opts = append(opts, internaloption.EnableNewAuthLibrary())
   122  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   123  	if err != nil {
   124  		return nil, err
   125  	}
   126  	s, err := New(client)
   127  	if err != nil {
   128  		return nil, err
   129  	}
   130  	if endpoint != "" {
   131  		s.BasePath = endpoint
   132  	}
   133  	return s, nil
   134  }
   135  
   136  // New creates a new Service. It uses the provided http.Client for requests.
   137  //
   138  // Deprecated: please use NewService instead.
   139  // To provide a custom HTTP client, use option.WithHTTPClient.
   140  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   141  func New(client *http.Client) (*Service, error) {
   142  	if client == nil {
   143  		return nil, errors.New("client is nil")
   144  	}
   145  	s := &Service{client: client, BasePath: basePath}
   146  	s.Detections = NewDetectionsService(s)
   147  	s.Languages = NewLanguagesService(s)
   148  	s.Translations = NewTranslationsService(s)
   149  	return s, nil
   150  }
   151  
   152  type Service struct {
   153  	client    *http.Client
   154  	BasePath  string // API endpoint base URL
   155  	UserAgent string // optional additional User-Agent fragment
   156  
   157  	Detections *DetectionsService
   158  
   159  	Languages *LanguagesService
   160  
   161  	Translations *TranslationsService
   162  }
   163  
   164  func (s *Service) userAgent() string {
   165  	if s.UserAgent == "" {
   166  		return googleapi.UserAgent
   167  	}
   168  	return googleapi.UserAgent + " " + s.UserAgent
   169  }
   170  
   171  func NewDetectionsService(s *Service) *DetectionsService {
   172  	rs := &DetectionsService{s: s}
   173  	return rs
   174  }
   175  
   176  type DetectionsService struct {
   177  	s *Service
   178  }
   179  
   180  func NewLanguagesService(s *Service) *LanguagesService {
   181  	rs := &LanguagesService{s: s}
   182  	return rs
   183  }
   184  
   185  type LanguagesService struct {
   186  	s *Service
   187  }
   188  
   189  func NewTranslationsService(s *Service) *TranslationsService {
   190  	rs := &TranslationsService{s: s}
   191  	return rs
   192  }
   193  
   194  type TranslationsService struct {
   195  	s *Service
   196  }
   197  
   198  // DetectLanguageRequest: The request message for language detection.
   199  type DetectLanguageRequest struct {
   200  	// Q: The input text upon which to perform language detection. Repeat
   201  	// this
   202  	// parameter to perform language detection on multiple text inputs.
   203  	Q []string `json:"q,omitempty"`
   204  	// ForceSendFields is a list of field names (e.g. "Q") to unconditionally
   205  	// include in API requests. By default, fields with empty or default values are
   206  	// omitted from API requests. See
   207  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   208  	// details.
   209  	ForceSendFields []string `json:"-"`
   210  	// NullFields is a list of field names (e.g. "Q") to include in API requests
   211  	// with the JSON null value. By default, fields with empty values are omitted
   212  	// from API requests. See
   213  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   214  	NullFields []string `json:"-"`
   215  }
   216  
   217  func (s *DetectLanguageRequest) MarshalJSON() ([]byte, error) {
   218  	type NoMethod DetectLanguageRequest
   219  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   220  }
   221  
   222  type DetectionsListResponse struct {
   223  	// Detections: A detections contains detection results of several text
   224  	Detections [][]*DetectionsResourceItem `json:"detections,omitempty"`
   225  
   226  	// ServerResponse contains the HTTP response code and headers from the server.
   227  	googleapi.ServerResponse `json:"-"`
   228  	// ForceSendFields is a list of field names (e.g. "Detections") to
   229  	// unconditionally include in API requests. By default, fields with empty or
   230  	// default values are omitted from API requests. See
   231  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   232  	// details.
   233  	ForceSendFields []string `json:"-"`
   234  	// NullFields is a list of field names (e.g. "Detections") to include in API
   235  	// requests with the JSON null value. By default, fields with empty values are
   236  	// omitted from API requests. See
   237  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   238  	NullFields []string `json:"-"`
   239  }
   240  
   241  func (s *DetectionsListResponse) MarshalJSON() ([]byte, error) {
   242  	type NoMethod DetectionsListResponse
   243  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   244  }
   245  
   246  type DetectionsResourceItem struct {
   247  	// Confidence: The confidence of the detection result of this language.
   248  	Confidence float64 `json:"confidence,omitempty"`
   249  	// IsReliable: A boolean to indicate is the language detection result reliable.
   250  	IsReliable bool `json:"isReliable,omitempty"`
   251  	// Language: The language we detected.
   252  	Language string `json:"language,omitempty"`
   253  	// ForceSendFields is a list of field names (e.g. "Confidence") to
   254  	// unconditionally include in API requests. By default, fields with empty or
   255  	// default values are omitted from API requests. See
   256  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   257  	// details.
   258  	ForceSendFields []string `json:"-"`
   259  	// NullFields is a list of field names (e.g. "Confidence") to include in API
   260  	// requests with the JSON null value. By default, fields with empty values are
   261  	// omitted from API requests. See
   262  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   263  	NullFields []string `json:"-"`
   264  }
   265  
   266  func (s *DetectionsResourceItem) MarshalJSON() ([]byte, error) {
   267  	type NoMethod DetectionsResourceItem
   268  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   269  }
   270  
   271  func (s *DetectionsResourceItem) UnmarshalJSON(data []byte) error {
   272  	type NoMethod DetectionsResourceItem
   273  	var s1 struct {
   274  		Confidence gensupport.JSONFloat64 `json:"confidence"`
   275  		*NoMethod
   276  	}
   277  	s1.NoMethod = (*NoMethod)(s)
   278  	if err := json.Unmarshal(data, &s1); err != nil {
   279  		return err
   280  	}
   281  	s.Confidence = float64(s1.Confidence)
   282  	return nil
   283  }
   284  
   285  // GetSupportedLanguagesRequest: The request message for discovering supported
   286  // languages.
   287  type GetSupportedLanguagesRequest struct {
   288  	// Target: The language to use to return localized, human readable names of
   289  	// supported
   290  	// languages.
   291  	Target string `json:"target,omitempty"`
   292  	// ForceSendFields is a list of field names (e.g. "Target") to unconditionally
   293  	// include in API requests. By default, fields with empty or default values are
   294  	// omitted from API requests. See
   295  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   296  	// details.
   297  	ForceSendFields []string `json:"-"`
   298  	// NullFields is a list of field names (e.g. "Target") to include in API
   299  	// requests with the JSON null value. By default, fields with empty values are
   300  	// omitted from API requests. See
   301  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   302  	NullFields []string `json:"-"`
   303  }
   304  
   305  func (s *GetSupportedLanguagesRequest) MarshalJSON() ([]byte, error) {
   306  	type NoMethod GetSupportedLanguagesRequest
   307  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   308  }
   309  
   310  type LanguagesListResponse struct {
   311  	// Languages: List of source/target languages supported by the translation API.
   312  	// If target parameter is unspecified, the list is sorted by the ASCII code
   313  	// point order of the language code. If target parameter is specified, the list
   314  	// is sorted by the collation order of the language name in the target
   315  	// language.
   316  	Languages []*LanguagesResource `json:"languages,omitempty"`
   317  
   318  	// ServerResponse contains the HTTP response code and headers from the server.
   319  	googleapi.ServerResponse `json:"-"`
   320  	// ForceSendFields is a list of field names (e.g. "Languages") to
   321  	// unconditionally include in API requests. By default, fields with empty or
   322  	// default values are omitted from API requests. See
   323  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   324  	// details.
   325  	ForceSendFields []string `json:"-"`
   326  	// NullFields is a list of field names (e.g. "Languages") to include in API
   327  	// requests with the JSON null value. By default, fields with empty values are
   328  	// omitted from API requests. See
   329  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   330  	NullFields []string `json:"-"`
   331  }
   332  
   333  func (s *LanguagesListResponse) MarshalJSON() ([]byte, error) {
   334  	type NoMethod LanguagesListResponse
   335  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   336  }
   337  
   338  type LanguagesResource struct {
   339  	// Language: Supported language code, generally consisting of its ISO
   340  	// 639-1
   341  	// identifier. (E.g. 'en', 'ja'). In certain cases, BCP-47 codes
   342  	// including
   343  	// language + region identifiers are returned (e.g. 'zh-TW' and 'zh-CH')
   344  	Language string `json:"language,omitempty"`
   345  	// Name: Human readable name of the language localized to the target language.
   346  	Name string `json:"name,omitempty"`
   347  	// ForceSendFields is a list of field names (e.g. "Language") to
   348  	// unconditionally include in API requests. By default, fields with empty or
   349  	// default values are omitted from API requests. See
   350  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   351  	// details.
   352  	ForceSendFields []string `json:"-"`
   353  	// NullFields is a list of field names (e.g. "Language") to include in API
   354  	// requests with the JSON null value. By default, fields with empty values are
   355  	// omitted from API requests. See
   356  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   357  	NullFields []string `json:"-"`
   358  }
   359  
   360  func (s *LanguagesResource) MarshalJSON() ([]byte, error) {
   361  	type NoMethod LanguagesResource
   362  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   363  }
   364  
   365  // TranslateTextRequest: The main translation request message for the Cloud
   366  // Translation API.
   367  type TranslateTextRequest struct {
   368  	// Format: The format of the source text, in either HTML (default) or
   369  	// plain-text. A
   370  	// value of "html" indicates HTML and a value of "text" indicates plain-text.
   371  	Format string `json:"format,omitempty"`
   372  	// Model: The `model` type requested for this translation. Valid values
   373  	// are
   374  	// listed in public documentation.
   375  	Model string `json:"model,omitempty"`
   376  	// Q: The input text to translate. Repeat this parameter to perform
   377  	// translation
   378  	// operations on multiple text inputs.
   379  	Q []string `json:"q,omitempty"`
   380  	// Source: The language of the source text, set to one of the language codes
   381  	// listed in
   382  	// Language Support. If the source language is not specified, the API
   383  	// will
   384  	// attempt to identify the source language automatically and return it
   385  	// within
   386  	// the response.
   387  	Source string `json:"source,omitempty"`
   388  	// Target: The language to use for translation of the input text, set to one of
   389  	// the
   390  	// language codes listed in Language Support.
   391  	Target string `json:"target,omitempty"`
   392  	// ForceSendFields is a list of field names (e.g. "Format") to unconditionally
   393  	// include in API requests. By default, fields with empty or default values are
   394  	// omitted from API requests. See
   395  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   396  	// details.
   397  	ForceSendFields []string `json:"-"`
   398  	// NullFields is a list of field names (e.g. "Format") to include in API
   399  	// requests with the JSON null value. By default, fields with empty values are
   400  	// omitted from API requests. See
   401  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   402  	NullFields []string `json:"-"`
   403  }
   404  
   405  func (s *TranslateTextRequest) MarshalJSON() ([]byte, error) {
   406  	type NoMethod TranslateTextRequest
   407  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   408  }
   409  
   410  // TranslationsListResponse: The main language translation response message.
   411  type TranslationsListResponse struct {
   412  	// Translations: Translations contains list of translation results of given
   413  	// text
   414  	Translations []*TranslationsResource `json:"translations,omitempty"`
   415  
   416  	// ServerResponse contains the HTTP response code and headers from the server.
   417  	googleapi.ServerResponse `json:"-"`
   418  	// ForceSendFields is a list of field names (e.g. "Translations") to
   419  	// unconditionally include in API requests. By default, fields with empty or
   420  	// default values are omitted from API requests. See
   421  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   422  	// details.
   423  	ForceSendFields []string `json:"-"`
   424  	// NullFields is a list of field names (e.g. "Translations") to include in API
   425  	// requests with the JSON null value. By default, fields with empty values are
   426  	// omitted from API requests. See
   427  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   428  	NullFields []string `json:"-"`
   429  }
   430  
   431  func (s *TranslationsListResponse) MarshalJSON() ([]byte, error) {
   432  	type NoMethod TranslationsListResponse
   433  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   434  }
   435  
   436  type TranslationsResource struct {
   437  	// DetectedSourceLanguage: The source language of the initial request, detected
   438  	// automatically, if
   439  	// no source language was passed within the initial request. If the
   440  	// source language was passed, auto-detection of the language will not
   441  	// occur and this field will be empty.
   442  	DetectedSourceLanguage string `json:"detectedSourceLanguage,omitempty"`
   443  	// Model: The `model` type used for this translation. Valid values are
   444  	// listed in public documentation. Can be different from requested
   445  	// `model`.
   446  	// Present only if specific model type was explicitly requested.
   447  	Model string `json:"model,omitempty"`
   448  	// TranslatedText: Text translated into the target language.
   449  	TranslatedText string `json:"translatedText,omitempty"`
   450  	// ForceSendFields is a list of field names (e.g. "DetectedSourceLanguage") to
   451  	// unconditionally include in API requests. By default, fields with empty or
   452  	// default values are omitted from API requests. See
   453  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   454  	// details.
   455  	ForceSendFields []string `json:"-"`
   456  	// NullFields is a list of field names (e.g. "DetectedSourceLanguage") to
   457  	// include in API requests with the JSON null value. By default, fields with
   458  	// empty values are omitted from API requests. See
   459  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   460  	NullFields []string `json:"-"`
   461  }
   462  
   463  func (s *TranslationsResource) MarshalJSON() ([]byte, error) {
   464  	type NoMethod TranslationsResource
   465  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   466  }
   467  
   468  type DetectionsDetectCall struct {
   469  	s                     *Service
   470  	detectlanguagerequest *DetectLanguageRequest
   471  	urlParams_            gensupport.URLParams
   472  	ctx_                  context.Context
   473  	header_               http.Header
   474  }
   475  
   476  // Detect: Detects the language of text within a request.
   477  func (r *DetectionsService) Detect(detectlanguagerequest *DetectLanguageRequest) *DetectionsDetectCall {
   478  	c := &DetectionsDetectCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   479  	c.detectlanguagerequest = detectlanguagerequest
   480  	return c
   481  }
   482  
   483  // Fields allows partial responses to be retrieved. See
   484  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   485  // details.
   486  func (c *DetectionsDetectCall) Fields(s ...googleapi.Field) *DetectionsDetectCall {
   487  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   488  	return c
   489  }
   490  
   491  // Context sets the context to be used in this call's Do method.
   492  func (c *DetectionsDetectCall) Context(ctx context.Context) *DetectionsDetectCall {
   493  	c.ctx_ = ctx
   494  	return c
   495  }
   496  
   497  // Header returns a http.Header that can be modified by the caller to add
   498  // headers to the request.
   499  func (c *DetectionsDetectCall) Header() http.Header {
   500  	if c.header_ == nil {
   501  		c.header_ = make(http.Header)
   502  	}
   503  	return c.header_
   504  }
   505  
   506  func (c *DetectionsDetectCall) doRequest(alt string) (*http.Response, error) {
   507  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   508  	var body io.Reader = nil
   509  	body, err := googleapi.WithDataWrapper.JSONReader(c.detectlanguagerequest)
   510  	if err != nil {
   511  		return nil, err
   512  	}
   513  	c.urlParams_.Set("alt", alt)
   514  	c.urlParams_.Set("prettyPrint", "false")
   515  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2/detect")
   516  	urls += "?" + c.urlParams_.Encode()
   517  	req, err := http.NewRequest("POST", urls, body)
   518  	if err != nil {
   519  		return nil, err
   520  	}
   521  	req.Header = reqHeaders
   522  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   523  }
   524  
   525  // Do executes the "language.detections.detect" call.
   526  // Any non-2xx status code is an error. Response headers are in either
   527  // *DetectionsListResponse.ServerResponse.Header or (if a response was returned
   528  // at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
   529  // check whether the returned error was because http.StatusNotModified was
   530  // returned.
   531  func (c *DetectionsDetectCall) Do(opts ...googleapi.CallOption) (*DetectionsListResponse, error) {
   532  	gensupport.SetOptions(c.urlParams_, opts...)
   533  	res, err := c.doRequest("json")
   534  	if res != nil && res.StatusCode == http.StatusNotModified {
   535  		if res.Body != nil {
   536  			res.Body.Close()
   537  		}
   538  		return nil, gensupport.WrapError(&googleapi.Error{
   539  			Code:   res.StatusCode,
   540  			Header: res.Header,
   541  		})
   542  	}
   543  	if err != nil {
   544  		return nil, err
   545  	}
   546  	defer googleapi.CloseBody(res)
   547  	if err := googleapi.CheckResponse(res); err != nil {
   548  		return nil, gensupport.WrapError(err)
   549  	}
   550  	ret := &DetectionsListResponse{
   551  		ServerResponse: googleapi.ServerResponse{
   552  			Header:         res.Header,
   553  			HTTPStatusCode: res.StatusCode,
   554  		},
   555  	}
   556  	target := &struct {
   557  		Data *DetectionsListResponse `json:"data"`
   558  	}{ret}
   559  	if err := gensupport.DecodeResponse(target, res); err != nil {
   560  		return nil, err
   561  	}
   562  	return ret, nil
   563  }
   564  
   565  type DetectionsListCall struct {
   566  	s            *Service
   567  	urlParams_   gensupport.URLParams
   568  	ifNoneMatch_ string
   569  	ctx_         context.Context
   570  	header_      http.Header
   571  }
   572  
   573  // List: Detects the language of text within a request.
   574  //
   575  //   - q: The input text upon which to perform language detection. Repeat
   576  //     this
   577  //
   578  // parameter to perform language detection on multiple text inputs.
   579  func (r *DetectionsService) List(q []string) *DetectionsListCall {
   580  	c := &DetectionsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   581  	c.urlParams_.SetMulti("q", append([]string{}, q...))
   582  	return c
   583  }
   584  
   585  // Fields allows partial responses to be retrieved. See
   586  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   587  // details.
   588  func (c *DetectionsListCall) Fields(s ...googleapi.Field) *DetectionsListCall {
   589  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   590  	return c
   591  }
   592  
   593  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   594  // object's ETag matches the given value. This is useful for getting updates
   595  // only after the object has changed since the last request.
   596  func (c *DetectionsListCall) IfNoneMatch(entityTag string) *DetectionsListCall {
   597  	c.ifNoneMatch_ = entityTag
   598  	return c
   599  }
   600  
   601  // Context sets the context to be used in this call's Do method.
   602  func (c *DetectionsListCall) Context(ctx context.Context) *DetectionsListCall {
   603  	c.ctx_ = ctx
   604  	return c
   605  }
   606  
   607  // Header returns a http.Header that can be modified by the caller to add
   608  // headers to the request.
   609  func (c *DetectionsListCall) Header() http.Header {
   610  	if c.header_ == nil {
   611  		c.header_ = make(http.Header)
   612  	}
   613  	return c.header_
   614  }
   615  
   616  func (c *DetectionsListCall) doRequest(alt string) (*http.Response, error) {
   617  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   618  	if c.ifNoneMatch_ != "" {
   619  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   620  	}
   621  	var body io.Reader = nil
   622  	c.urlParams_.Set("alt", alt)
   623  	c.urlParams_.Set("prettyPrint", "false")
   624  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2/detect")
   625  	urls += "?" + c.urlParams_.Encode()
   626  	req, err := http.NewRequest("GET", urls, body)
   627  	if err != nil {
   628  		return nil, err
   629  	}
   630  	req.Header = reqHeaders
   631  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   632  }
   633  
   634  // Do executes the "language.detections.list" call.
   635  // Any non-2xx status code is an error. Response headers are in either
   636  // *DetectionsListResponse.ServerResponse.Header or (if a response was returned
   637  // at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
   638  // check whether the returned error was because http.StatusNotModified was
   639  // returned.
   640  func (c *DetectionsListCall) Do(opts ...googleapi.CallOption) (*DetectionsListResponse, error) {
   641  	gensupport.SetOptions(c.urlParams_, opts...)
   642  	res, err := c.doRequest("json")
   643  	if res != nil && res.StatusCode == http.StatusNotModified {
   644  		if res.Body != nil {
   645  			res.Body.Close()
   646  		}
   647  		return nil, gensupport.WrapError(&googleapi.Error{
   648  			Code:   res.StatusCode,
   649  			Header: res.Header,
   650  		})
   651  	}
   652  	if err != nil {
   653  		return nil, err
   654  	}
   655  	defer googleapi.CloseBody(res)
   656  	if err := googleapi.CheckResponse(res); err != nil {
   657  		return nil, gensupport.WrapError(err)
   658  	}
   659  	ret := &DetectionsListResponse{
   660  		ServerResponse: googleapi.ServerResponse{
   661  			Header:         res.Header,
   662  			HTTPStatusCode: res.StatusCode,
   663  		},
   664  	}
   665  	target := &struct {
   666  		Data *DetectionsListResponse `json:"data"`
   667  	}{ret}
   668  	if err := gensupport.DecodeResponse(target, res); err != nil {
   669  		return nil, err
   670  	}
   671  	return ret, nil
   672  }
   673  
   674  type LanguagesListCall struct {
   675  	s            *Service
   676  	urlParams_   gensupport.URLParams
   677  	ifNoneMatch_ string
   678  	ctx_         context.Context
   679  	header_      http.Header
   680  }
   681  
   682  // List: Returns a list of supported languages for translation.
   683  func (r *LanguagesService) List() *LanguagesListCall {
   684  	c := &LanguagesListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   685  	return c
   686  }
   687  
   688  // Model sets the optional parameter "model": The model type for which
   689  // supported languages should be returned.
   690  func (c *LanguagesListCall) Model(model string) *LanguagesListCall {
   691  	c.urlParams_.Set("model", model)
   692  	return c
   693  }
   694  
   695  // Target sets the optional parameter "target": The language to use to return
   696  // localized, human readable names of supported
   697  // languages.
   698  func (c *LanguagesListCall) Target(target string) *LanguagesListCall {
   699  	c.urlParams_.Set("target", target)
   700  	return c
   701  }
   702  
   703  // Fields allows partial responses to be retrieved. See
   704  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   705  // details.
   706  func (c *LanguagesListCall) Fields(s ...googleapi.Field) *LanguagesListCall {
   707  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   708  	return c
   709  }
   710  
   711  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   712  // object's ETag matches the given value. This is useful for getting updates
   713  // only after the object has changed since the last request.
   714  func (c *LanguagesListCall) IfNoneMatch(entityTag string) *LanguagesListCall {
   715  	c.ifNoneMatch_ = entityTag
   716  	return c
   717  }
   718  
   719  // Context sets the context to be used in this call's Do method.
   720  func (c *LanguagesListCall) Context(ctx context.Context) *LanguagesListCall {
   721  	c.ctx_ = ctx
   722  	return c
   723  }
   724  
   725  // Header returns a http.Header that can be modified by the caller to add
   726  // headers to the request.
   727  func (c *LanguagesListCall) Header() http.Header {
   728  	if c.header_ == nil {
   729  		c.header_ = make(http.Header)
   730  	}
   731  	return c.header_
   732  }
   733  
   734  func (c *LanguagesListCall) doRequest(alt string) (*http.Response, error) {
   735  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   736  	if c.ifNoneMatch_ != "" {
   737  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   738  	}
   739  	var body io.Reader = nil
   740  	c.urlParams_.Set("alt", alt)
   741  	c.urlParams_.Set("prettyPrint", "false")
   742  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2/languages")
   743  	urls += "?" + c.urlParams_.Encode()
   744  	req, err := http.NewRequest("GET", urls, body)
   745  	if err != nil {
   746  		return nil, err
   747  	}
   748  	req.Header = reqHeaders
   749  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   750  }
   751  
   752  // Do executes the "language.languages.list" call.
   753  // Any non-2xx status code is an error. Response headers are in either
   754  // *LanguagesListResponse.ServerResponse.Header or (if a response was returned
   755  // at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
   756  // check whether the returned error was because http.StatusNotModified was
   757  // returned.
   758  func (c *LanguagesListCall) Do(opts ...googleapi.CallOption) (*LanguagesListResponse, error) {
   759  	gensupport.SetOptions(c.urlParams_, opts...)
   760  	res, err := c.doRequest("json")
   761  	if res != nil && res.StatusCode == http.StatusNotModified {
   762  		if res.Body != nil {
   763  			res.Body.Close()
   764  		}
   765  		return nil, gensupport.WrapError(&googleapi.Error{
   766  			Code:   res.StatusCode,
   767  			Header: res.Header,
   768  		})
   769  	}
   770  	if err != nil {
   771  		return nil, err
   772  	}
   773  	defer googleapi.CloseBody(res)
   774  	if err := googleapi.CheckResponse(res); err != nil {
   775  		return nil, gensupport.WrapError(err)
   776  	}
   777  	ret := &LanguagesListResponse{
   778  		ServerResponse: googleapi.ServerResponse{
   779  			Header:         res.Header,
   780  			HTTPStatusCode: res.StatusCode,
   781  		},
   782  	}
   783  	target := &struct {
   784  		Data *LanguagesListResponse `json:"data"`
   785  	}{ret}
   786  	if err := gensupport.DecodeResponse(target, res); err != nil {
   787  		return nil, err
   788  	}
   789  	return ret, nil
   790  }
   791  
   792  type TranslationsListCall struct {
   793  	s            *Service
   794  	urlParams_   gensupport.URLParams
   795  	ifNoneMatch_ string
   796  	ctx_         context.Context
   797  	header_      http.Header
   798  }
   799  
   800  // List: Translates input text, returning translated text.
   801  //
   802  //   - q: The input text to translate. Repeat this parameter to perform
   803  //     translation
   804  //
   805  // operations on multiple text inputs.
   806  //   - target: The language to use for translation of the input text, set to one
   807  //     of the
   808  //
   809  // language codes listed in Language Support.
   810  func (r *TranslationsService) List(q []string, target string) *TranslationsListCall {
   811  	c := &TranslationsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   812  	c.urlParams_.SetMulti("q", append([]string{}, q...))
   813  	c.urlParams_.Set("target", target)
   814  	return c
   815  }
   816  
   817  // Cid sets the optional parameter "cid": The customization id for translate
   818  func (c *TranslationsListCall) Cid(cid ...string) *TranslationsListCall {
   819  	c.urlParams_.SetMulti("cid", append([]string{}, cid...))
   820  	return c
   821  }
   822  
   823  // Format sets the optional parameter "format": The format of the source text,
   824  // in either HTML (default) or plain-text. A
   825  // value of "html" indicates HTML and a value of "text" indicates plain-text.
   826  //
   827  // Possible values:
   828  //
   829  //	"html" - Specifies the input is in HTML
   830  //	"text" - Specifies the input is in plain textual format
   831  func (c *TranslationsListCall) Format(format string) *TranslationsListCall {
   832  	c.urlParams_.Set("format", format)
   833  	return c
   834  }
   835  
   836  // Model sets the optional parameter "model": The `model` type requested for
   837  // this translation. Valid values are
   838  // listed in public documentation.
   839  func (c *TranslationsListCall) Model(model string) *TranslationsListCall {
   840  	c.urlParams_.Set("model", model)
   841  	return c
   842  }
   843  
   844  // Source sets the optional parameter "source": The language of the source
   845  // text, set to one of the language codes listed in
   846  // Language Support. If the source language is not specified, the API
   847  // will
   848  // attempt to identify the source language automatically and return it
   849  // within
   850  // the response.
   851  func (c *TranslationsListCall) Source(source string) *TranslationsListCall {
   852  	c.urlParams_.Set("source", source)
   853  	return c
   854  }
   855  
   856  // Fields allows partial responses to be retrieved. See
   857  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   858  // details.
   859  func (c *TranslationsListCall) Fields(s ...googleapi.Field) *TranslationsListCall {
   860  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   861  	return c
   862  }
   863  
   864  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   865  // object's ETag matches the given value. This is useful for getting updates
   866  // only after the object has changed since the last request.
   867  func (c *TranslationsListCall) IfNoneMatch(entityTag string) *TranslationsListCall {
   868  	c.ifNoneMatch_ = entityTag
   869  	return c
   870  }
   871  
   872  // Context sets the context to be used in this call's Do method.
   873  func (c *TranslationsListCall) Context(ctx context.Context) *TranslationsListCall {
   874  	c.ctx_ = ctx
   875  	return c
   876  }
   877  
   878  // Header returns a http.Header that can be modified by the caller to add
   879  // headers to the request.
   880  func (c *TranslationsListCall) Header() http.Header {
   881  	if c.header_ == nil {
   882  		c.header_ = make(http.Header)
   883  	}
   884  	return c.header_
   885  }
   886  
   887  func (c *TranslationsListCall) doRequest(alt string) (*http.Response, error) {
   888  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   889  	if c.ifNoneMatch_ != "" {
   890  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   891  	}
   892  	var body io.Reader = nil
   893  	c.urlParams_.Set("alt", alt)
   894  	c.urlParams_.Set("prettyPrint", "false")
   895  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2")
   896  	urls += "?" + c.urlParams_.Encode()
   897  	req, err := http.NewRequest("GET", urls, body)
   898  	if err != nil {
   899  		return nil, err
   900  	}
   901  	req.Header = reqHeaders
   902  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   903  }
   904  
   905  // Do executes the "language.translations.list" call.
   906  // Any non-2xx status code is an error. Response headers are in either
   907  // *TranslationsListResponse.ServerResponse.Header or (if a response was
   908  // returned at all) in error.(*googleapi.Error).Header. Use
   909  // googleapi.IsNotModified to check whether the returned error was because
   910  // http.StatusNotModified was returned.
   911  func (c *TranslationsListCall) Do(opts ...googleapi.CallOption) (*TranslationsListResponse, error) {
   912  	gensupport.SetOptions(c.urlParams_, opts...)
   913  	res, err := c.doRequest("json")
   914  	if res != nil && res.StatusCode == http.StatusNotModified {
   915  		if res.Body != nil {
   916  			res.Body.Close()
   917  		}
   918  		return nil, gensupport.WrapError(&googleapi.Error{
   919  			Code:   res.StatusCode,
   920  			Header: res.Header,
   921  		})
   922  	}
   923  	if err != nil {
   924  		return nil, err
   925  	}
   926  	defer googleapi.CloseBody(res)
   927  	if err := googleapi.CheckResponse(res); err != nil {
   928  		return nil, gensupport.WrapError(err)
   929  	}
   930  	ret := &TranslationsListResponse{
   931  		ServerResponse: googleapi.ServerResponse{
   932  			Header:         res.Header,
   933  			HTTPStatusCode: res.StatusCode,
   934  		},
   935  	}
   936  	target := &struct {
   937  		Data *TranslationsListResponse `json:"data"`
   938  	}{ret}
   939  	if err := gensupport.DecodeResponse(target, res); err != nil {
   940  		return nil, err
   941  	}
   942  	return ret, nil
   943  }
   944  
   945  type TranslationsTranslateCall struct {
   946  	s                    *Service
   947  	translatetextrequest *TranslateTextRequest
   948  	urlParams_           gensupport.URLParams
   949  	ctx_                 context.Context
   950  	header_              http.Header
   951  }
   952  
   953  // Translate: Translates input text, returning translated text.
   954  func (r *TranslationsService) Translate(translatetextrequest *TranslateTextRequest) *TranslationsTranslateCall {
   955  	c := &TranslationsTranslateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   956  	c.translatetextrequest = translatetextrequest
   957  	return c
   958  }
   959  
   960  // Fields allows partial responses to be retrieved. See
   961  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   962  // details.
   963  func (c *TranslationsTranslateCall) Fields(s ...googleapi.Field) *TranslationsTranslateCall {
   964  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   965  	return c
   966  }
   967  
   968  // Context sets the context to be used in this call's Do method.
   969  func (c *TranslationsTranslateCall) Context(ctx context.Context) *TranslationsTranslateCall {
   970  	c.ctx_ = ctx
   971  	return c
   972  }
   973  
   974  // Header returns a http.Header that can be modified by the caller to add
   975  // headers to the request.
   976  func (c *TranslationsTranslateCall) Header() http.Header {
   977  	if c.header_ == nil {
   978  		c.header_ = make(http.Header)
   979  	}
   980  	return c.header_
   981  }
   982  
   983  func (c *TranslationsTranslateCall) doRequest(alt string) (*http.Response, error) {
   984  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   985  	var body io.Reader = nil
   986  	body, err := googleapi.WithDataWrapper.JSONReader(c.translatetextrequest)
   987  	if err != nil {
   988  		return nil, err
   989  	}
   990  	c.urlParams_.Set("alt", alt)
   991  	c.urlParams_.Set("prettyPrint", "false")
   992  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2")
   993  	urls += "?" + c.urlParams_.Encode()
   994  	req, err := http.NewRequest("POST", urls, body)
   995  	if err != nil {
   996  		return nil, err
   997  	}
   998  	req.Header = reqHeaders
   999  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
  1000  }
  1001  
  1002  // Do executes the "language.translations.translate" call.
  1003  // Any non-2xx status code is an error. Response headers are in either
  1004  // *TranslationsListResponse.ServerResponse.Header or (if a response was
  1005  // returned at all) in error.(*googleapi.Error).Header. Use
  1006  // googleapi.IsNotModified to check whether the returned error was because
  1007  // http.StatusNotModified was returned.
  1008  func (c *TranslationsTranslateCall) Do(opts ...googleapi.CallOption) (*TranslationsListResponse, error) {
  1009  	gensupport.SetOptions(c.urlParams_, opts...)
  1010  	res, err := c.doRequest("json")
  1011  	if res != nil && res.StatusCode == http.StatusNotModified {
  1012  		if res.Body != nil {
  1013  			res.Body.Close()
  1014  		}
  1015  		return nil, gensupport.WrapError(&googleapi.Error{
  1016  			Code:   res.StatusCode,
  1017  			Header: res.Header,
  1018  		})
  1019  	}
  1020  	if err != nil {
  1021  		return nil, err
  1022  	}
  1023  	defer googleapi.CloseBody(res)
  1024  	if err := googleapi.CheckResponse(res); err != nil {
  1025  		return nil, gensupport.WrapError(err)
  1026  	}
  1027  	ret := &TranslationsListResponse{
  1028  		ServerResponse: googleapi.ServerResponse{
  1029  			Header:         res.Header,
  1030  			HTTPStatusCode: res.StatusCode,
  1031  		},
  1032  	}
  1033  	target := &struct {
  1034  		Data *TranslationsListResponse `json:"data"`
  1035  	}{ret}
  1036  	if err := gensupport.DecodeResponse(target, res); err != nil {
  1037  		return nil, err
  1038  	}
  1039  	return ret, nil
  1040  }
  1041  

View as plain text