1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 package translate
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
81
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
103 const (
104
105 CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
106
107
108 CloudTranslationScope = "https://www.googleapis.com/auth/cloud-translation"
109 )
110
111
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
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
137
138
139
140
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
155 UserAgent string
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
199 type DetectLanguageRequest struct {
200
201
202
203 Q []string `json:"q,omitempty"`
204
205
206
207
208
209 ForceSendFields []string `json:"-"`
210
211
212
213
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
224 Detections [][]*DetectionsResourceItem `json:"detections,omitempty"`
225
226
227 googleapi.ServerResponse `json:"-"`
228
229
230
231
232
233 ForceSendFields []string `json:"-"`
234
235
236
237
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
248 Confidence float64 `json:"confidence,omitempty"`
249
250 IsReliable bool `json:"isReliable,omitempty"`
251
252 Language string `json:"language,omitempty"`
253
254
255
256
257
258 ForceSendFields []string `json:"-"`
259
260
261
262
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
286
287 type GetSupportedLanguagesRequest struct {
288
289
290
291 Target string `json:"target,omitempty"`
292
293
294
295
296
297 ForceSendFields []string `json:"-"`
298
299
300
301
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
312
313
314
315
316 Languages []*LanguagesResource `json:"languages,omitempty"`
317
318
319 googleapi.ServerResponse `json:"-"`
320
321
322
323
324
325 ForceSendFields []string `json:"-"`
326
327
328
329
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
340
341
342
343
344 Language string `json:"language,omitempty"`
345
346 Name string `json:"name,omitempty"`
347
348
349
350
351
352 ForceSendFields []string `json:"-"`
353
354
355
356
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
366
367 type TranslateTextRequest struct {
368
369
370
371 Format string `json:"format,omitempty"`
372
373
374
375 Model string `json:"model,omitempty"`
376
377
378
379 Q []string `json:"q,omitempty"`
380
381
382
383
384
385
386
387 Source string `json:"source,omitempty"`
388
389
390
391 Target string `json:"target,omitempty"`
392
393
394
395
396
397 ForceSendFields []string `json:"-"`
398
399
400
401
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
411 type TranslationsListResponse struct {
412
413
414 Translations []*TranslationsResource `json:"translations,omitempty"`
415
416
417 googleapi.ServerResponse `json:"-"`
418
419
420
421
422
423 ForceSendFields []string `json:"-"`
424
425
426
427
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
438
439
440
441
442 DetectedSourceLanguage string `json:"detectedSourceLanguage,omitempty"`
443
444
445
446
447 Model string `json:"model,omitempty"`
448
449 TranslatedText string `json:"translatedText,omitempty"`
450
451
452
453
454
455 ForceSendFields []string `json:"-"`
456
457
458
459
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
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
484
485
486 func (c *DetectionsDetectCall) Fields(s ...googleapi.Field) *DetectionsDetectCall {
487 c.urlParams_.Set("fields", googleapi.CombineFields(s))
488 return c
489 }
490
491
492 func (c *DetectionsDetectCall) Context(ctx context.Context) *DetectionsDetectCall {
493 c.ctx_ = ctx
494 return c
495 }
496
497
498
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
526
527
528
529
530
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
574
575
576
577
578
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
586
587
588 func (c *DetectionsListCall) Fields(s ...googleapi.Field) *DetectionsListCall {
589 c.urlParams_.Set("fields", googleapi.CombineFields(s))
590 return c
591 }
592
593
594
595
596 func (c *DetectionsListCall) IfNoneMatch(entityTag string) *DetectionsListCall {
597 c.ifNoneMatch_ = entityTag
598 return c
599 }
600
601
602 func (c *DetectionsListCall) Context(ctx context.Context) *DetectionsListCall {
603 c.ctx_ = ctx
604 return c
605 }
606
607
608
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
635
636
637
638
639
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
683 func (r *LanguagesService) List() *LanguagesListCall {
684 c := &LanguagesListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
685 return c
686 }
687
688
689
690 func (c *LanguagesListCall) Model(model string) *LanguagesListCall {
691 c.urlParams_.Set("model", model)
692 return c
693 }
694
695
696
697
698 func (c *LanguagesListCall) Target(target string) *LanguagesListCall {
699 c.urlParams_.Set("target", target)
700 return c
701 }
702
703
704
705
706 func (c *LanguagesListCall) Fields(s ...googleapi.Field) *LanguagesListCall {
707 c.urlParams_.Set("fields", googleapi.CombineFields(s))
708 return c
709 }
710
711
712
713
714 func (c *LanguagesListCall) IfNoneMatch(entityTag string) *LanguagesListCall {
715 c.ifNoneMatch_ = entityTag
716 return c
717 }
718
719
720 func (c *LanguagesListCall) Context(ctx context.Context) *LanguagesListCall {
721 c.ctx_ = ctx
722 return c
723 }
724
725
726
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
753
754
755
756
757
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
801
802
803
804
805
806
807
808
809
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
818 func (c *TranslationsListCall) Cid(cid ...string) *TranslationsListCall {
819 c.urlParams_.SetMulti("cid", append([]string{}, cid...))
820 return c
821 }
822
823
824
825
826
827
828
829
830
831 func (c *TranslationsListCall) Format(format string) *TranslationsListCall {
832 c.urlParams_.Set("format", format)
833 return c
834 }
835
836
837
838
839 func (c *TranslationsListCall) Model(model string) *TranslationsListCall {
840 c.urlParams_.Set("model", model)
841 return c
842 }
843
844
845
846
847
848
849
850
851 func (c *TranslationsListCall) Source(source string) *TranslationsListCall {
852 c.urlParams_.Set("source", source)
853 return c
854 }
855
856
857
858
859 func (c *TranslationsListCall) Fields(s ...googleapi.Field) *TranslationsListCall {
860 c.urlParams_.Set("fields", googleapi.CombineFields(s))
861 return c
862 }
863
864
865
866
867 func (c *TranslationsListCall) IfNoneMatch(entityTag string) *TranslationsListCall {
868 c.ifNoneMatch_ = entityTag
869 return c
870 }
871
872
873 func (c *TranslationsListCall) Context(ctx context.Context) *TranslationsListCall {
874 c.ctx_ = ctx
875 return c
876 }
877
878
879
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
906
907
908
909
910
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
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
961
962
963 func (c *TranslationsTranslateCall) Fields(s ...googleapi.Field) *TranslationsTranslateCall {
964 c.urlParams_.Set("fields", googleapi.CombineFields(s))
965 return c
966 }
967
968
969 func (c *TranslationsTranslateCall) Context(ctx context.Context) *TranslationsTranslateCall {
970 c.ctx_ = ctx
971 return c
972 }
973
974
975
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
1003
1004
1005
1006
1007
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