No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

790 líneas
26 KiB

  1. // Copyright 2016 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package translate provides access to the Translate API.
  15. //
  16. // See https://developers.google.com/translate/v2/using_rest
  17. //
  18. // Usage example:
  19. //
  20. // import "cloud.google.com/go/translate/internal/translate/v2"
  21. // ...
  22. // translateService, err := translate.New(oauthHttpClient)
  23. package translate // import "cloud.google.com/go/translate/internal/translate/v2"
  24. import (
  25. "bytes"
  26. "context"
  27. "encoding/json"
  28. "errors"
  29. "fmt"
  30. "io"
  31. "net/http"
  32. "net/url"
  33. "strconv"
  34. "strings"
  35. gensupport "google.golang.org/api/gensupport"
  36. googleapi "google.golang.org/api/googleapi"
  37. )
  38. // Always reference these packages, just in case the auto-generated code
  39. // below doesn't.
  40. var _ = bytes.NewBuffer
  41. var _ = strconv.Itoa
  42. var _ = fmt.Sprintf
  43. var _ = json.NewDecoder
  44. var _ = io.Copy
  45. var _ = url.Parse
  46. var _ = gensupport.MarshalJSON
  47. var _ = googleapi.Version
  48. var _ = errors.New
  49. var _ = strings.Replace
  50. var _ = context.Canceled
  51. const apiId = "translate:v2"
  52. const apiName = "translate"
  53. const apiVersion = "v2"
  54. const basePath = "https://translation.googleapis.com/language/translate/"
  55. // OAuth2 scopes used by this API.
  56. const (
  57. // View and manage your data across Google Cloud Platform services
  58. CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
  59. )
  60. func New(client *http.Client) (*Service, error) {
  61. if client == nil {
  62. return nil, errors.New("client is nil")
  63. }
  64. s := &Service{client: client, BasePath: basePath}
  65. s.Detections = NewDetectionsService(s)
  66. s.Languages = NewLanguagesService(s)
  67. s.Translations = NewTranslationsService(s)
  68. return s, nil
  69. }
  70. type Service struct {
  71. client *http.Client
  72. BasePath string // API endpoint base URL
  73. UserAgent string // optional additional User-Agent fragment
  74. Detections *DetectionsService
  75. Languages *LanguagesService
  76. Translations *TranslationsService
  77. }
  78. func (s *Service) userAgent() string {
  79. if s.UserAgent == "" {
  80. return googleapi.UserAgent
  81. }
  82. return googleapi.UserAgent + " " + s.UserAgent
  83. }
  84. func NewDetectionsService(s *Service) *DetectionsService {
  85. rs := &DetectionsService{s: s}
  86. return rs
  87. }
  88. type DetectionsService struct {
  89. s *Service
  90. }
  91. func NewLanguagesService(s *Service) *LanguagesService {
  92. rs := &LanguagesService{s: s}
  93. return rs
  94. }
  95. type LanguagesService struct {
  96. s *Service
  97. }
  98. func NewTranslationsService(s *Service) *TranslationsService {
  99. rs := &TranslationsService{s: s}
  100. return rs
  101. }
  102. type TranslationsService struct {
  103. s *Service
  104. }
  105. type DetectionsListResponse struct {
  106. // Detections: A detections contains detection results of several text
  107. Detections [][]*DetectionsResourceItem `json:"detections,omitempty"`
  108. // ServerResponse contains the HTTP response code and headers from the
  109. // server.
  110. googleapi.ServerResponse `json:"-"`
  111. // ForceSendFields is a list of field names (e.g. "Detections") to
  112. // unconditionally include in API requests. By default, fields with
  113. // empty values are omitted from API requests. However, any non-pointer,
  114. // non-interface field appearing in ForceSendFields will be sent to the
  115. // server regardless of whether the field is empty or not. This may be
  116. // used to include empty fields in Patch requests.
  117. ForceSendFields []string `json:"-"`
  118. // NullFields is a list of field names (e.g. "Detections") to include in
  119. // API requests with the JSON null value. By default, fields with empty
  120. // values are omitted from API requests. However, any field with an
  121. // empty value appearing in NullFields will be sent to the server as
  122. // null. It is an error if a field in this list has a non-empty value.
  123. // This may be used to include null fields in Patch requests.
  124. NullFields []string `json:"-"`
  125. }
  126. func (s *DetectionsListResponse) MarshalJSON() ([]byte, error) {
  127. type noMethod DetectionsListResponse
  128. raw := noMethod(*s)
  129. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  130. }
  131. type DetectionsResourceItem struct {
  132. // Confidence: The confidence of the detection resul of this language.
  133. Confidence float64 `json:"confidence,omitempty"`
  134. // IsReliable: A boolean to indicate is the language detection result
  135. // reliable.
  136. IsReliable bool `json:"isReliable,omitempty"`
  137. // Language: The language we detect
  138. Language string `json:"language,omitempty"`
  139. // ForceSendFields is a list of field names (e.g. "Confidence") to
  140. // unconditionally include in API requests. By default, fields with
  141. // empty values are omitted from API requests. However, any non-pointer,
  142. // non-interface field appearing in ForceSendFields will be sent to the
  143. // server regardless of whether the field is empty or not. This may be
  144. // used to include empty fields in Patch requests.
  145. ForceSendFields []string `json:"-"`
  146. // NullFields is a list of field names (e.g. "Confidence") to include in
  147. // API requests with the JSON null value. By default, fields with empty
  148. // values are omitted from API requests. However, any field with an
  149. // empty value appearing in NullFields will be sent to the server as
  150. // null. It is an error if a field in this list has a non-empty value.
  151. // This may be used to include null fields in Patch requests.
  152. NullFields []string `json:"-"`
  153. }
  154. func (s *DetectionsResourceItem) MarshalJSON() ([]byte, error) {
  155. type noMethod DetectionsResourceItem
  156. raw := noMethod(*s)
  157. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  158. }
  159. type LanguagesListResponse struct {
  160. // Languages: List of source/target languages supported by the
  161. // translation API. If target parameter is unspecified, the list is
  162. // sorted by the ASCII code point order of the language code. If target
  163. // parameter is specified, the list is sorted by the collation order of
  164. // the language name in the target language.
  165. Languages []*LanguagesResource `json:"languages,omitempty"`
  166. // ServerResponse contains the HTTP response code and headers from the
  167. // server.
  168. googleapi.ServerResponse `json:"-"`
  169. // ForceSendFields is a list of field names (e.g. "Languages") to
  170. // unconditionally include in API requests. By default, fields with
  171. // empty values are omitted from API requests. However, any non-pointer,
  172. // non-interface field appearing in ForceSendFields will be sent to the
  173. // server regardless of whether the field is empty or not. This may be
  174. // used to include empty fields in Patch requests.
  175. ForceSendFields []string `json:"-"`
  176. // NullFields is a list of field names (e.g. "Languages") to include in
  177. // API requests with the JSON null value. By default, fields with empty
  178. // values are omitted from API requests. However, any field with an
  179. // empty value appearing in NullFields will be sent to the server as
  180. // null. It is an error if a field in this list has a non-empty value.
  181. // This may be used to include null fields in Patch requests.
  182. NullFields []string `json:"-"`
  183. }
  184. func (s *LanguagesListResponse) MarshalJSON() ([]byte, error) {
  185. type noMethod LanguagesListResponse
  186. raw := noMethod(*s)
  187. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  188. }
  189. type LanguagesResource struct {
  190. // Language: The language code.
  191. Language string `json:"language,omitempty"`
  192. // Name: The localized name of the language if target parameter is
  193. // given.
  194. Name string `json:"name,omitempty"`
  195. // ForceSendFields is a list of field names (e.g. "Language") to
  196. // unconditionally include in API requests. By default, fields with
  197. // empty values are omitted from API requests. However, any non-pointer,
  198. // non-interface field appearing in ForceSendFields will be sent to the
  199. // server regardless of whether the field is empty or not. This may be
  200. // used to include empty fields in Patch requests.
  201. ForceSendFields []string `json:"-"`
  202. // NullFields is a list of field names (e.g. "Language") to include in
  203. // API requests with the JSON null value. By default, fields with empty
  204. // values are omitted from API requests. However, any field with an
  205. // empty value appearing in NullFields will be sent to the server as
  206. // null. It is an error if a field in this list has a non-empty value.
  207. // This may be used to include null fields in Patch requests.
  208. NullFields []string `json:"-"`
  209. }
  210. func (s *LanguagesResource) MarshalJSON() ([]byte, error) {
  211. type noMethod LanguagesResource
  212. raw := noMethod(*s)
  213. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  214. }
  215. type TranslationsListResponse struct {
  216. // Translations: Translations contains list of translation results of
  217. // given text
  218. Translations []*TranslationsResource `json:"translations,omitempty"`
  219. // ServerResponse contains the HTTP response code and headers from the
  220. // server.
  221. googleapi.ServerResponse `json:"-"`
  222. // ForceSendFields is a list of field names (e.g. "Translations") to
  223. // unconditionally include in API requests. By default, fields with
  224. // empty values are omitted from API requests. However, any non-pointer,
  225. // non-interface field appearing in ForceSendFields will be sent to the
  226. // server regardless of whether the field is empty or not. This may be
  227. // used to include empty fields in Patch requests.
  228. ForceSendFields []string `json:"-"`
  229. // NullFields is a list of field names (e.g. "Translations") to include
  230. // in API requests with the JSON null value. By default, fields with
  231. // empty values are omitted from API requests. However, any field with
  232. // an empty value appearing in NullFields will be sent to the server as
  233. // null. It is an error if a field in this list has a non-empty value.
  234. // This may be used to include null fields in Patch requests.
  235. NullFields []string `json:"-"`
  236. }
  237. func (s *TranslationsListResponse) MarshalJSON() ([]byte, error) {
  238. type noMethod TranslationsListResponse
  239. raw := noMethod(*s)
  240. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  241. }
  242. type TranslationsResource struct {
  243. // DetectedSourceLanguage: Detected source language if source parameter
  244. // is unspecified.
  245. DetectedSourceLanguage string `json:"detectedSourceLanguage,omitempty"`
  246. // Model: Model used for translation.
  247. Model string `json:"model,omitempty"`
  248. // TranslatedText: The translation.
  249. TranslatedText string `json:"translatedText,omitempty"`
  250. // ForceSendFields is a list of field names (e.g.
  251. // "DetectedSourceLanguage") to unconditionally include in API requests.
  252. // By default, fields with empty values are omitted from API requests.
  253. // However, any non-pointer, non-interface field appearing in
  254. // ForceSendFields will be sent to the server regardless of whether the
  255. // field is empty or not. This may be used to include empty fields in
  256. // Patch requests.
  257. ForceSendFields []string `json:"-"`
  258. // NullFields is a list of field names (e.g. "DetectedSourceLanguage")
  259. // to include in API requests with the JSON null value. By default,
  260. // fields with empty values are omitted from API requests. However, any
  261. // field with an empty value appearing in NullFields will be sent to the
  262. // server as null. It is an error if a field in this list has a
  263. // non-empty value. This may be used to include null fields in Patch
  264. // requests.
  265. NullFields []string `json:"-"`
  266. }
  267. func (s *TranslationsResource) MarshalJSON() ([]byte, error) {
  268. type noMethod TranslationsResource
  269. raw := noMethod(*s)
  270. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  271. }
  272. // method id "language.detections.list":
  273. type DetectionsListCall struct {
  274. s *Service
  275. urlParams_ gensupport.URLParams
  276. ifNoneMatch_ string
  277. ctx_ context.Context
  278. header_ http.Header
  279. }
  280. // List: Detect the language of text.
  281. func (r *DetectionsService) List(q []string) *DetectionsListCall {
  282. c := &DetectionsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  283. c.urlParams_.SetMulti("q", append([]string{}, q...))
  284. return c
  285. }
  286. // Fields allows partial responses to be retrieved. See
  287. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  288. // for more information.
  289. func (c *DetectionsListCall) Fields(s ...googleapi.Field) *DetectionsListCall {
  290. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  291. return c
  292. }
  293. // IfNoneMatch sets the optional parameter which makes the operation
  294. // fail if the object's ETag matches the given value. This is useful for
  295. // getting updates only after the object has changed since the last
  296. // request. Use googleapi.IsNotModified to check whether the response
  297. // error from Do is the result of In-None-Match.
  298. func (c *DetectionsListCall) IfNoneMatch(entityTag string) *DetectionsListCall {
  299. c.ifNoneMatch_ = entityTag
  300. return c
  301. }
  302. // Context sets the context to be used in this call's Do method. Any
  303. // pending HTTP request will be aborted if the provided context is
  304. // canceled.
  305. func (c *DetectionsListCall) Context(ctx context.Context) *DetectionsListCall {
  306. c.ctx_ = ctx
  307. return c
  308. }
  309. // Header returns an http.Header that can be modified by the caller to
  310. // add HTTP headers to the request.
  311. func (c *DetectionsListCall) Header() http.Header {
  312. if c.header_ == nil {
  313. c.header_ = make(http.Header)
  314. }
  315. return c.header_
  316. }
  317. func (c *DetectionsListCall) doRequest(alt string) (*http.Response, error) {
  318. reqHeaders := make(http.Header)
  319. for k, v := range c.header_ {
  320. reqHeaders[k] = v
  321. }
  322. reqHeaders.Set("User-Agent", c.s.userAgent())
  323. if c.ifNoneMatch_ != "" {
  324. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  325. }
  326. var body io.Reader = nil
  327. c.urlParams_.Set("alt", alt)
  328. urls := googleapi.ResolveRelative(c.s.BasePath, "v2/detect")
  329. urls += "?" + c.urlParams_.Encode()
  330. req, _ := http.NewRequest("GET", urls, body)
  331. req.Header = reqHeaders
  332. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  333. }
  334. // Do executes the "language.detections.list" call.
  335. // Exactly one of *DetectionsListResponse or error will be non-nil. Any
  336. // non-2xx status code is an error. Response headers are in either
  337. // *DetectionsListResponse.ServerResponse.Header or (if a response was
  338. // returned at all) in error.(*googleapi.Error).Header. Use
  339. // googleapi.IsNotModified to check whether the returned error was
  340. // because http.StatusNotModified was returned.
  341. func (c *DetectionsListCall) Do(opts ...googleapi.CallOption) (*DetectionsListResponse, error) {
  342. gensupport.SetOptions(c.urlParams_, opts...)
  343. res, err := c.doRequest("json")
  344. if res != nil && res.StatusCode == http.StatusNotModified {
  345. if res.Body != nil {
  346. res.Body.Close()
  347. }
  348. return nil, &googleapi.Error{
  349. Code: res.StatusCode,
  350. Header: res.Header,
  351. }
  352. }
  353. if err != nil {
  354. return nil, err
  355. }
  356. defer googleapi.CloseBody(res)
  357. if err := googleapi.CheckResponse(res); err != nil {
  358. return nil, err
  359. }
  360. ret := &DetectionsListResponse{
  361. ServerResponse: googleapi.ServerResponse{
  362. Header: res.Header,
  363. HTTPStatusCode: res.StatusCode,
  364. },
  365. }
  366. target := &struct {
  367. Data *DetectionsListResponse `json:"data"`
  368. }{ret}
  369. if err := json.NewDecoder(res.Body).Decode(target); err != nil {
  370. return nil, err
  371. }
  372. return ret, nil
  373. // {
  374. // "description": "Detect the language of text.",
  375. // "httpMethod": "GET",
  376. // "id": "language.detections.list",
  377. // "parameterOrder": [
  378. // "q"
  379. // ],
  380. // "parameters": {
  381. // "q": {
  382. // "description": "The text to detect",
  383. // "location": "query",
  384. // "repeated": true,
  385. // "required": true,
  386. // "type": "string"
  387. // }
  388. // },
  389. // "path": "v2/detect",
  390. // "response": {
  391. // "$ref": "DetectionsListResponse"
  392. // }
  393. // }
  394. }
  395. // method id "language.languages.list":
  396. type LanguagesListCall struct {
  397. s *Service
  398. urlParams_ gensupport.URLParams
  399. ifNoneMatch_ string
  400. ctx_ context.Context
  401. header_ http.Header
  402. }
  403. // List: List the source/target languages supported by the API
  404. func (r *LanguagesService) List() *LanguagesListCall {
  405. c := &LanguagesListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  406. return c
  407. }
  408. // Target sets the optional parameter "target": the language and
  409. // collation in which the localized results should be returned
  410. func (c *LanguagesListCall) Target(target string) *LanguagesListCall {
  411. c.urlParams_.Set("target", target)
  412. return c
  413. }
  414. // Fields allows partial responses to be retrieved. See
  415. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  416. // for more information.
  417. func (c *LanguagesListCall) Fields(s ...googleapi.Field) *LanguagesListCall {
  418. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  419. return c
  420. }
  421. // IfNoneMatch sets the optional parameter which makes the operation
  422. // fail if the object's ETag matches the given value. This is useful for
  423. // getting updates only after the object has changed since the last
  424. // request. Use googleapi.IsNotModified to check whether the response
  425. // error from Do is the result of In-None-Match.
  426. func (c *LanguagesListCall) IfNoneMatch(entityTag string) *LanguagesListCall {
  427. c.ifNoneMatch_ = entityTag
  428. return c
  429. }
  430. // Context sets the context to be used in this call's Do method. Any
  431. // pending HTTP request will be aborted if the provided context is
  432. // canceled.
  433. func (c *LanguagesListCall) Context(ctx context.Context) *LanguagesListCall {
  434. c.ctx_ = ctx
  435. return c
  436. }
  437. // Header returns an http.Header that can be modified by the caller to
  438. // add HTTP headers to the request.
  439. func (c *LanguagesListCall) Header() http.Header {
  440. if c.header_ == nil {
  441. c.header_ = make(http.Header)
  442. }
  443. return c.header_
  444. }
  445. func (c *LanguagesListCall) doRequest(alt string) (*http.Response, error) {
  446. reqHeaders := make(http.Header)
  447. for k, v := range c.header_ {
  448. reqHeaders[k] = v
  449. }
  450. reqHeaders.Set("User-Agent", c.s.userAgent())
  451. if c.ifNoneMatch_ != "" {
  452. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  453. }
  454. var body io.Reader = nil
  455. c.urlParams_.Set("alt", alt)
  456. urls := googleapi.ResolveRelative(c.s.BasePath, "v2/languages")
  457. urls += "?" + c.urlParams_.Encode()
  458. req, _ := http.NewRequest("GET", urls, body)
  459. req.Header = reqHeaders
  460. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  461. }
  462. // Do executes the "language.languages.list" call.
  463. // Exactly one of *LanguagesListResponse or error will be non-nil. Any
  464. // non-2xx status code is an error. Response headers are in either
  465. // *LanguagesListResponse.ServerResponse.Header or (if a response was
  466. // returned at all) in error.(*googleapi.Error).Header. Use
  467. // googleapi.IsNotModified to check whether the returned error was
  468. // because http.StatusNotModified was returned.
  469. func (c *LanguagesListCall) Do(opts ...googleapi.CallOption) (*LanguagesListResponse, error) {
  470. gensupport.SetOptions(c.urlParams_, opts...)
  471. res, err := c.doRequest("json")
  472. if res != nil && res.StatusCode == http.StatusNotModified {
  473. if res.Body != nil {
  474. res.Body.Close()
  475. }
  476. return nil, &googleapi.Error{
  477. Code: res.StatusCode,
  478. Header: res.Header,
  479. }
  480. }
  481. if err != nil {
  482. return nil, err
  483. }
  484. defer googleapi.CloseBody(res)
  485. if err := googleapi.CheckResponse(res); err != nil {
  486. return nil, err
  487. }
  488. ret := &LanguagesListResponse{
  489. ServerResponse: googleapi.ServerResponse{
  490. Header: res.Header,
  491. HTTPStatusCode: res.StatusCode,
  492. },
  493. }
  494. target := &struct {
  495. Data *LanguagesListResponse `json:"data"`
  496. }{ret}
  497. if err := json.NewDecoder(res.Body).Decode(target); err != nil {
  498. return nil, err
  499. }
  500. return ret, nil
  501. // {
  502. // "description": "List the source/target languages supported by the API",
  503. // "httpMethod": "GET",
  504. // "id": "language.languages.list",
  505. // "parameters": {
  506. // "target": {
  507. // "description": "the language and collation in which the localized results should be returned",
  508. // "location": "query",
  509. // "type": "string"
  510. // }
  511. // },
  512. // "path": "v2/languages",
  513. // "response": {
  514. // "$ref": "LanguagesListResponse"
  515. // }
  516. // }
  517. }
  518. // method id "language.translations.list":
  519. type TranslationsListCall struct {
  520. s *Service
  521. urlParams_ gensupport.URLParams
  522. ifNoneMatch_ string
  523. ctx_ context.Context
  524. header_ http.Header
  525. }
  526. // List: Returns text translations from one language to another.
  527. func (r *TranslationsService) List(q []string, target string) *TranslationsListCall {
  528. c := &TranslationsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  529. c.urlParams_.SetMulti("q", append([]string{}, q...))
  530. c.urlParams_.Set("target", target)
  531. return c
  532. }
  533. // Cid sets the optional parameter "cid": The customization id for
  534. // translate
  535. func (c *TranslationsListCall) Cid(cid ...string) *TranslationsListCall {
  536. c.urlParams_.SetMulti("cid", append([]string{}, cid...))
  537. return c
  538. }
  539. // Format sets the optional parameter "format": The format of the text
  540. //
  541. // Possible values:
  542. // "html" - Specifies the input is in HTML
  543. // "text" - Specifies the input is in plain textual format
  544. func (c *TranslationsListCall) Format(format string) *TranslationsListCall {
  545. c.urlParams_.Set("format", format)
  546. return c
  547. }
  548. // Model sets the optional parameter "model": the model to use for
  549. // translation
  550. func (c *TranslationsListCall) Model(model string) *TranslationsListCall {
  551. c.urlParams_.Set("model", model)
  552. return c
  553. }
  554. // Source sets the optional parameter "source": The source language of
  555. // the text
  556. func (c *TranslationsListCall) Source(source string) *TranslationsListCall {
  557. c.urlParams_.Set("source", source)
  558. return c
  559. }
  560. // Fields allows partial responses to be retrieved. See
  561. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  562. // for more information.
  563. func (c *TranslationsListCall) Fields(s ...googleapi.Field) *TranslationsListCall {
  564. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  565. return c
  566. }
  567. // IfNoneMatch sets the optional parameter which makes the operation
  568. // fail if the object's ETag matches the given value. This is useful for
  569. // getting updates only after the object has changed since the last
  570. // request. Use googleapi.IsNotModified to check whether the response
  571. // error from Do is the result of In-None-Match.
  572. func (c *TranslationsListCall) IfNoneMatch(entityTag string) *TranslationsListCall {
  573. c.ifNoneMatch_ = entityTag
  574. return c
  575. }
  576. // Context sets the context to be used in this call's Do method. Any
  577. // pending HTTP request will be aborted if the provided context is
  578. // canceled.
  579. func (c *TranslationsListCall) Context(ctx context.Context) *TranslationsListCall {
  580. c.ctx_ = ctx
  581. return c
  582. }
  583. // Header returns an http.Header that can be modified by the caller to
  584. // add HTTP headers to the request.
  585. func (c *TranslationsListCall) Header() http.Header {
  586. if c.header_ == nil {
  587. c.header_ = make(http.Header)
  588. }
  589. return c.header_
  590. }
  591. func (c *TranslationsListCall) doRequest(alt string) (*http.Response, error) {
  592. reqHeaders := make(http.Header)
  593. for k, v := range c.header_ {
  594. reqHeaders[k] = v
  595. }
  596. reqHeaders.Set("User-Agent", c.s.userAgent())
  597. if c.ifNoneMatch_ != "" {
  598. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  599. }
  600. var body io.Reader = nil
  601. c.urlParams_.Set("alt", alt)
  602. urls := googleapi.ResolveRelative(c.s.BasePath, "v2")
  603. urls += "?" + c.urlParams_.Encode()
  604. req, _ := http.NewRequest("GET", urls, body)
  605. req.Header = reqHeaders
  606. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  607. }
  608. // Do executes the "language.translations.list" call.
  609. // Exactly one of *TranslationsListResponse or error will be non-nil.
  610. // Any non-2xx status code is an error. Response headers are in either
  611. // *TranslationsListResponse.ServerResponse.Header or (if a response was
  612. // returned at all) in error.(*googleapi.Error).Header. Use
  613. // googleapi.IsNotModified to check whether the returned error was
  614. // because http.StatusNotModified was returned.
  615. func (c *TranslationsListCall) Do(opts ...googleapi.CallOption) (*TranslationsListResponse, error) {
  616. gensupport.SetOptions(c.urlParams_, opts...)
  617. res, err := c.doRequest("json")
  618. if res != nil && res.StatusCode == http.StatusNotModified {
  619. if res.Body != nil {
  620. res.Body.Close()
  621. }
  622. return nil, &googleapi.Error{
  623. Code: res.StatusCode,
  624. Header: res.Header,
  625. }
  626. }
  627. if err != nil {
  628. return nil, err
  629. }
  630. defer googleapi.CloseBody(res)
  631. if err := googleapi.CheckResponse(res); err != nil {
  632. return nil, err
  633. }
  634. ret := &TranslationsListResponse{
  635. ServerResponse: googleapi.ServerResponse{
  636. Header: res.Header,
  637. HTTPStatusCode: res.StatusCode,
  638. },
  639. }
  640. target := &struct {
  641. Data *TranslationsListResponse `json:"data"`
  642. }{ret}
  643. if err := json.NewDecoder(res.Body).Decode(target); err != nil {
  644. return nil, err
  645. }
  646. return ret, nil
  647. // {
  648. // "description": "Returns text translations from one language to another.",
  649. // "httpMethod": "GET",
  650. // "id": "language.translations.list",
  651. // "parameterOrder": [
  652. // "q",
  653. // "target"
  654. // ],
  655. // "parameters": {
  656. // "cid": {
  657. // "description": "The customization id for translate",
  658. // "location": "query",
  659. // "repeated": true,
  660. // "type": "string"
  661. // },
  662. // "format": {
  663. // "description": "The format of the text",
  664. // "enum": [
  665. // "html",
  666. // "text"
  667. // ],
  668. // "enumDescriptions": [
  669. // "Specifies the input is in HTML",
  670. // "Specifies the input is in plain textual format"
  671. // ],
  672. // "location": "query",
  673. // "type": "string"
  674. // },
  675. // "model": {
  676. // "description": "the model to use for translation",
  677. // "location": "query",
  678. // "type": "string"
  679. // },
  680. // "q": {
  681. // "description": "The text to translate",
  682. // "location": "query",
  683. // "repeated": true,
  684. // "required": true,
  685. // "type": "string"
  686. // },
  687. // "source": {
  688. // "description": "The source language of the text",
  689. // "location": "query",
  690. // "type": "string"
  691. // },
  692. // "target": {
  693. // "description": "The target language into which the text should be translated",
  694. // "location": "query",
  695. // "required": true,
  696. // "type": "string"
  697. // }
  698. // },
  699. // "path": "v2",
  700. // "response": {
  701. // "$ref": "TranslationsListResponse"
  702. // }
  703. // }
  704. }