Debian Codegraph @

shopping/merchant/accounts/apiv1beta/terms_of_service_client.go

raw
1 // Copyright 2025 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 // https://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
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package accounts
18
19 import (
20 "context"
21 "fmt"
22 "log/slog"
23 "math"
24 "net/http"
25 "net/url"
26 "time"
27
28 accountspb "cloud.google.com/go/shopping/merchant/accounts/apiv1beta/accountspb"
29 gax "github.com/googleapis/gax-go/v2"
30 "google.golang.org/api/option"
31 "google.golang.org/api/option/internaloption"
32 gtransport "google.golang.org/api/transport/grpc"
33 httptransport "google.golang.org/api/transport/http"
34 "google.golang.org/grpc"
35 "google.golang.org/grpc/codes"
36 "google.golang.org/protobuf/encoding/protojson"
37 )
38
39 var newTermsOfServiceClientHook clientHook
40
41 // TermsOfServiceCallOptions contains the retry settings for each method of TermsOfServiceClient.
42 type TermsOfServiceCallOptions struct {
43 GetTermsOfService []gax.CallOption
44 RetrieveLatestTermsOfService []gax.CallOption
45 AcceptTermsOfService []gax.CallOption
46 }
47
48 func defaultTermsOfServiceGRPCClientOptions() []option.ClientOption {
49 return []option.ClientOption{
50 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
51 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
52 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
53 internaloption.WithDefaultUniverseDomain("googleapis.com"),
54 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
55 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
56 internaloption.EnableJwtWithScope(),
57 internaloption.EnableNewAuthLibrary(),
58 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
59 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
60 }
61 }
62
63 func defaultTermsOfServiceCallOptions() *TermsOfServiceCallOptions {
64 return &TermsOfServiceCallOptions{
65 GetTermsOfService: []gax.CallOption{
66 gax.WithTimeout(60000 * time.Millisecond),
67 gax.WithRetry(func() gax.Retryer {
68 return gax.OnCodes([]codes.Code{
69 codes.Unavailable,
70 }, gax.Backoff{
71 Initial: 1000 * time.Millisecond,
72 Max: 10000 * time.Millisecond,
73 Multiplier: 1.30,
74 })
75 }),
76 },
77 RetrieveLatestTermsOfService: []gax.CallOption{
78 gax.WithTimeout(60000 * time.Millisecond),
79 gax.WithRetry(func() gax.Retryer {
80 return gax.OnCodes([]codes.Code{
81 codes.Unavailable,
82 }, gax.Backoff{
83 Initial: 1000 * time.Millisecond,
84 Max: 10000 * time.Millisecond,
85 Multiplier: 1.30,
86 })
87 }),
88 },
89 AcceptTermsOfService: []gax.CallOption{
90 gax.WithTimeout(60000 * time.Millisecond),
91 gax.WithRetry(func() gax.Retryer {
92 return gax.OnCodes([]codes.Code{
93 codes.Unavailable,
94 }, gax.Backoff{
95 Initial: 1000 * time.Millisecond,
96 Max: 10000 * time.Millisecond,
97 Multiplier: 1.30,
98 })
99 }),
100 },
101 }
102 }
103
104 func defaultTermsOfServiceRESTCallOptions() *TermsOfServiceCallOptions {
105 return &TermsOfServiceCallOptions{
106 GetTermsOfService: []gax.CallOption{
107 gax.WithTimeout(60000 * time.Millisecond),
108 gax.WithRetry(func() gax.Retryer {
109 return gax.OnHTTPCodes(gax.Backoff{
110 Initial: 1000 * time.Millisecond,
111 Max: 10000 * time.Millisecond,
112 Multiplier: 1.30,
113 },
114 http.StatusServiceUnavailable)
115 }),
116 },
117 RetrieveLatestTermsOfService: []gax.CallOption{
118 gax.WithTimeout(60000 * time.Millisecond),
119 gax.WithRetry(func() gax.Retryer {
120 return gax.OnHTTPCodes(gax.Backoff{
121 Initial: 1000 * time.Millisecond,
122 Max: 10000 * time.Millisecond,
123 Multiplier: 1.30,
124 },
125 http.StatusServiceUnavailable)
126 }),
127 },
128 AcceptTermsOfService: []gax.CallOption{
129 gax.WithTimeout(60000 * time.Millisecond),
130 gax.WithRetry(func() gax.Retryer {
131 return gax.OnHTTPCodes(gax.Backoff{
132 Initial: 1000 * time.Millisecond,
133 Max: 10000 * time.Millisecond,
134 Multiplier: 1.30,
135 },
136 http.StatusServiceUnavailable)
137 }),
138 },
139 }
140 }
141
142 // internalTermsOfServiceClient is an interface that defines the methods available from Merchant API.
143 type internalTermsOfServiceClient interface {
144 Close() error
145 setGoogleClientInfo(...string)
146 Connection() *grpc.ClientConn
147 GetTermsOfService(context.Context, *accountspb.GetTermsOfServiceRequest, ...gax.CallOption) (*accountspb.TermsOfService, error)
148 RetrieveLatestTermsOfService(context.Context, *accountspb.RetrieveLatestTermsOfServiceRequest, ...gax.CallOption) (*accountspb.TermsOfService, error)
149 AcceptTermsOfService(context.Context, *accountspb.AcceptTermsOfServiceRequest, ...gax.CallOption) error
150 }
151
152 // TermsOfServiceClient is a client for interacting with Merchant API.
153 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
154 //
155 // Service to support TermsOfService API.
156 type TermsOfServiceClient struct {
157 // The internal transport-dependent client.
158 internalClient internalTermsOfServiceClient
159
160 // The call options for this service.
161 CallOptions *TermsOfServiceCallOptions
162 }
163
164 // Wrapper methods routed to the internal client.
165
166 // Close closes the connection to the API service. The user should invoke this when
167 // the client is no longer required.
168 func (c *TermsOfServiceClient) Close() error {
169 return c.internalClient.Close()
170 }
171
172 // setGoogleClientInfo sets the name and version of the application in
173 // the `x-goog-api-client` header passed on each request. Intended for
174 // use by Google-written clients.
175 func (c *TermsOfServiceClient) setGoogleClientInfo(keyval ...string) {
176 c.internalClient.setGoogleClientInfo(keyval...)
177 }
178
179 // Connection returns a connection to the API service.
180 //
181 // Deprecated: Connections are now pooled so this method does not always
182 // return the same resource.
183 func (c *TermsOfServiceClient) Connection() *grpc.ClientConn {
184 return c.internalClient.Connection()
185 }
186
187 // GetTermsOfService retrieves the TermsOfService associated with the provided version.
188 func (c *TermsOfServiceClient) GetTermsOfService(ctx context.Context, req *accountspb.GetTermsOfServiceRequest, opts ...gax.CallOption) (*accountspb.TermsOfService, error) {
189 return c.internalClient.GetTermsOfService(ctx, req, opts...)
190 }
191
192 // RetrieveLatestTermsOfService retrieves the latest version of the TermsOfService for a given kind and
193 // region_code.
194 func (c *TermsOfServiceClient) RetrieveLatestTermsOfService(ctx context.Context, req *accountspb.RetrieveLatestTermsOfServiceRequest, opts ...gax.CallOption) (*accountspb.TermsOfService, error) {
195 return c.internalClient.RetrieveLatestTermsOfService(ctx, req, opts...)
196 }
197
198 // AcceptTermsOfService accepts a TermsOfService. Executing this method requires admin access.
199 func (c *TermsOfServiceClient) AcceptTermsOfService(ctx context.Context, req *accountspb.AcceptTermsOfServiceRequest, opts ...gax.CallOption) error {
200 return c.internalClient.AcceptTermsOfService(ctx, req, opts...)
201 }
202
203 // termsOfServiceGRPCClient is a client for interacting with Merchant API over gRPC transport.
204 //
205 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
206 type termsOfServiceGRPCClient struct {
207 // Connection pool of gRPC connections to the service.
208 connPool gtransport.ConnPool
209
210 // Points back to the CallOptions field of the containing TermsOfServiceClient
211 CallOptions **TermsOfServiceCallOptions
212
213 // The gRPC API client.
214 termsOfServiceClient accountspb.TermsOfServiceServiceClient
215
216 // The x-goog-* metadata to be sent with each request.
217 xGoogHeaders []string
218
219 logger *slog.Logger
220 }
221
222 // NewTermsOfServiceClient creates a new terms of service service client based on gRPC.
223 // The returned client must be Closed when it is done being used to clean up its underlying connections.
224 //
225 // Service to support TermsOfService API.
226 func NewTermsOfServiceClient(ctx context.Context, opts ...option.ClientOption) (*TermsOfServiceClient, error) {
227 clientOpts := defaultTermsOfServiceGRPCClientOptions()
228 if newTermsOfServiceClientHook != nil {
229 hookOpts, err := newTermsOfServiceClientHook(ctx, clientHookParams{})
230 if err != nil {
231 return nil, err
232 }
233 clientOpts = append(clientOpts, hookOpts...)
234 }
235
236 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
237 if err != nil {
238 return nil, err
239 }
240 client := TermsOfServiceClient{CallOptions: defaultTermsOfServiceCallOptions()}
241
242 c := &termsOfServiceGRPCClient{
243 connPool: connPool,
244 termsOfServiceClient: accountspb.NewTermsOfServiceServiceClient(connPool),
245 CallOptions: &client.CallOptions,
246 logger: internaloption.GetLogger(opts),
247 }
248 c.setGoogleClientInfo()
249
250 client.internalClient = c
251
252 return &client, nil
253 }
254
255 // Connection returns a connection to the API service.
256 //
257 // Deprecated: Connections are now pooled so this method does not always
258 // return the same resource.
259 func (c *termsOfServiceGRPCClient) Connection() *grpc.ClientConn {
260 return c.connPool.Conn()
261 }
262
263 // setGoogleClientInfo sets the name and version of the application in
264 // the `x-goog-api-client` header passed on each request. Intended for
265 // use by Google-written clients.
266 func (c *termsOfServiceGRPCClient) setGoogleClientInfo(keyval ...string) {
267 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
268 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
269 c.xGoogHeaders = []string{
270 "x-goog-api-client", gax.XGoogHeader(kv...),
271 }
272 }
273
274 // Close closes the connection to the API service. The user should invoke this when
275 // the client is no longer required.
276 func (c *termsOfServiceGRPCClient) Close() error {
277 return c.connPool.Close()
278 }
279
280 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
281 type termsOfServiceRESTClient struct {
282 // The http endpoint to connect to.
283 endpoint string
284
285 // The http client.
286 httpClient *http.Client
287
288 // The x-goog-* headers to be sent with each request.
289 xGoogHeaders []string
290
291 // Points back to the CallOptions field of the containing TermsOfServiceClient
292 CallOptions **TermsOfServiceCallOptions
293
294 logger *slog.Logger
295 }
296
297 // NewTermsOfServiceRESTClient creates a new terms of service service rest client.
298 //
299 // Service to support TermsOfService API.
300 func NewTermsOfServiceRESTClient(ctx context.Context, opts ...option.ClientOption) (*TermsOfServiceClient, error) {
301 clientOpts := append(defaultTermsOfServiceRESTClientOptions(), opts...)
302 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
303 if err != nil {
304 return nil, err
305 }
306
307 callOpts := defaultTermsOfServiceRESTCallOptions()
308 c := &termsOfServiceRESTClient{
309 endpoint: endpoint,
310 httpClient: httpClient,
311 CallOptions: &callOpts,
312 logger: internaloption.GetLogger(opts),
313 }
314 c.setGoogleClientInfo()
315
316 return &TermsOfServiceClient{internalClient: c, CallOptions: callOpts}, nil
317 }
318
319 func defaultTermsOfServiceRESTClientOptions() []option.ClientOption {
320 return []option.ClientOption{
321 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
322 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
323 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
324 internaloption.WithDefaultUniverseDomain("googleapis.com"),
325 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
326 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
327 internaloption.EnableNewAuthLibrary(),
328 }
329 }
330
331 // setGoogleClientInfo sets the name and version of the application in
332 // the `x-goog-api-client` header passed on each request. Intended for
333 // use by Google-written clients.
334 func (c *termsOfServiceRESTClient) setGoogleClientInfo(keyval ...string) {
335 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
336 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
337 c.xGoogHeaders = []string{
338 "x-goog-api-client", gax.XGoogHeader(kv...),
339 }
340 }
341
342 // Close closes the connection to the API service. The user should invoke this when
343 // the client is no longer required.
344 func (c *termsOfServiceRESTClient) Close() error {
345 // Replace httpClient with nil to force cleanup.
346 c.httpClient = nil
347 return nil
348 }
349
350 // Connection returns a connection to the API service.
351 //
352 // Deprecated: This method always returns nil.
353 func (c *termsOfServiceRESTClient) Connection() *grpc.ClientConn {
354 return nil
355 }
356 func (c *termsOfServiceGRPCClient) GetTermsOfService(ctx context.Context, req *accountspb.GetTermsOfServiceRequest, opts ...gax.CallOption) (*accountspb.TermsOfService, error) {
357 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
358
359 hds = append(c.xGoogHeaders, hds...)
360 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
361 opts = append((*c.CallOptions).GetTermsOfService[0:len((*c.CallOptions).GetTermsOfService):len((*c.CallOptions).GetTermsOfService)], opts...)
362 var resp *accountspb.TermsOfService
363 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
364 var err error
365 resp, err = executeRPC(ctx, c.termsOfServiceClient.GetTermsOfService, req, settings.GRPC, c.logger, "GetTermsOfService")
366 return err
367 }, opts...)
368 if err != nil {
369 return nil, err
370 }
371 return resp, nil
372 }
373
374 func (c *termsOfServiceGRPCClient) RetrieveLatestTermsOfService(ctx context.Context, req *accountspb.RetrieveLatestTermsOfServiceRequest, opts ...gax.CallOption) (*accountspb.TermsOfService, error) {
375 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
376 opts = append((*c.CallOptions).RetrieveLatestTermsOfService[0:len((*c.CallOptions).RetrieveLatestTermsOfService):len((*c.CallOptions).RetrieveLatestTermsOfService)], opts...)
377 var resp *accountspb.TermsOfService
378 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
379 var err error
380 resp, err = executeRPC(ctx, c.termsOfServiceClient.RetrieveLatestTermsOfService, req, settings.GRPC, c.logger, "RetrieveLatestTermsOfService")
381 return err
382 }, opts...)
383 if err != nil {
384 return nil, err
385 }
386 return resp, nil
387 }
388
389 func (c *termsOfServiceGRPCClient) AcceptTermsOfService(ctx context.Context, req *accountspb.AcceptTermsOfServiceRequest, opts ...gax.CallOption) error {
390 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
391
392 hds = append(c.xGoogHeaders, hds...)
393 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
394 opts = append((*c.CallOptions).AcceptTermsOfService[0:len((*c.CallOptions).AcceptTermsOfService):len((*c.CallOptions).AcceptTermsOfService)], opts...)
395 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
396 var err error
397 _, err = executeRPC(ctx, c.termsOfServiceClient.AcceptTermsOfService, req, settings.GRPC, c.logger, "AcceptTermsOfService")
398 return err
399 }, opts...)
400 return err
401 }
402
403 // GetTermsOfService retrieves the TermsOfService associated with the provided version.
404 func (c *termsOfServiceRESTClient) GetTermsOfService(ctx context.Context, req *accountspb.GetTermsOfServiceRequest, opts ...gax.CallOption) (*accountspb.TermsOfService, error) {
405 baseUrl, err := url.Parse(c.endpoint)
406 if err != nil {
407 return nil, err
408 }
409 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName())
410
411 params := url.Values{}
412 params.Add("$alt", "json;enum-encoding=int")
413
414 baseUrl.RawQuery = params.Encode()
415
416 // Build HTTP headers from client and context metadata.
417 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
418
419 hds = append(c.xGoogHeaders, hds...)
420 hds = append(hds, "Content-Type", "application/json")
421 headers := gax.BuildHeaders(ctx, hds...)
422 opts = append((*c.CallOptions).GetTermsOfService[0:len((*c.CallOptions).GetTermsOfService):len((*c.CallOptions).GetTermsOfService)], opts...)
423 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
424 resp := &accountspb.TermsOfService{}
425 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
426 if settings.Path != "" {
427 baseUrl.Path = settings.Path
428 }
429 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
430 if err != nil {
431 return err
432 }
433 httpReq = httpReq.WithContext(ctx)
434 httpReq.Header = headers
435
436 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTermsOfService")
437 if err != nil {
438 return err
439 }
440
441 if err := unm.Unmarshal(buf, resp); err != nil {
442 return err
443 }
444
445 return nil
446 }, opts...)
447 if e != nil {
448 return nil, e
449 }
450 return resp, nil
451 }
452
453 // RetrieveLatestTermsOfService retrieves the latest version of the TermsOfService for a given kind and
454 // region_code.
455 func (c *termsOfServiceRESTClient) RetrieveLatestTermsOfService(ctx context.Context, req *accountspb.RetrieveLatestTermsOfServiceRequest, opts ...gax.CallOption) (*accountspb.TermsOfService, error) {
456 baseUrl, err := url.Parse(c.endpoint)
457 if err != nil {
458 return nil, err
459 }
460 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/termsOfService:retrieveLatest")
461
462 params := url.Values{}
463 params.Add("$alt", "json;enum-encoding=int")
464 params.Add("kind", fmt.Sprintf("%v", req.GetKind()))
465 params.Add("regionCode", fmt.Sprintf("%v", req.GetRegionCode()))
466
467 baseUrl.RawQuery = params.Encode()
468
469 // Build HTTP headers from client and context metadata.
470 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
471 headers := gax.BuildHeaders(ctx, hds...)
472 opts = append((*c.CallOptions).RetrieveLatestTermsOfService[0:len((*c.CallOptions).RetrieveLatestTermsOfService):len((*c.CallOptions).RetrieveLatestTermsOfService)], opts...)
473 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
474 resp := &accountspb.TermsOfService{}
475 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
476 if settings.Path != "" {
477 baseUrl.Path = settings.Path
478 }
479 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
480 if err != nil {
481 return err
482 }
483 httpReq = httpReq.WithContext(ctx)
484 httpReq.Header = headers
485
486 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "RetrieveLatestTermsOfService")
487 if err != nil {
488 return err
489 }
490
491 if err := unm.Unmarshal(buf, resp); err != nil {
492 return err
493 }
494
495 return nil
496 }, opts...)
497 if e != nil {
498 return nil, e
499 }
500 return resp, nil
501 }
502
503 // AcceptTermsOfService accepts a TermsOfService. Executing this method requires admin access.
504 func (c *termsOfServiceRESTClient) AcceptTermsOfService(ctx context.Context, req *accountspb.AcceptTermsOfServiceRequest, opts ...gax.CallOption) error {
505 baseUrl, err := url.Parse(c.endpoint)
506 if err != nil {
507 return err
508 }
509 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v:accept", req.GetName())
510
511 params := url.Values{}
512 params.Add("$alt", "json;enum-encoding=int")
513 params.Add("account", fmt.Sprintf("%v", req.GetAccount()))
514 params.Add("regionCode", fmt.Sprintf("%v", req.GetRegionCode()))
515
516 baseUrl.RawQuery = params.Encode()
517
518 // Build HTTP headers from client and context metadata.
519 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
520
521 hds = append(c.xGoogHeaders, hds...)
522 hds = append(hds, "Content-Type", "application/json")
523 headers := gax.BuildHeaders(ctx, hds...)
524 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
525 if settings.Path != "" {
526 baseUrl.Path = settings.Path
527 }
528 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
529 if err != nil {
530 return err
531 }
532 httpReq = httpReq.WithContext(ctx)
533 httpReq.Header = headers
534
535 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "AcceptTermsOfService")
536 return err
537 }, opts...)
538 }