Debian Codegraph @

shopping/merchant/accounts/apiv1/terms_of_service_agreement_state_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/apiv1/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 newTermsOfServiceAgreementStateClientHook clientHook
40
41 // TermsOfServiceAgreementStateCallOptions contains the retry settings for each method of TermsOfServiceAgreementStateClient.
42 type TermsOfServiceAgreementStateCallOptions struct {
43 GetTermsOfServiceAgreementState []gax.CallOption
44 RetrieveForApplicationTermsOfServiceAgreementState []gax.CallOption
45 }
46
47 func defaultTermsOfServiceAgreementStateGRPCClientOptions() []option.ClientOption {
48 return []option.ClientOption{
49 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
50 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
51 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
52 internaloption.WithDefaultUniverseDomain("googleapis.com"),
53 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
54 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
55 internaloption.EnableJwtWithScope(),
56 internaloption.EnableNewAuthLibrary(),
57 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
58 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
59 }
60 }
61
62 func defaultTermsOfServiceAgreementStateCallOptions() *TermsOfServiceAgreementStateCallOptions {
63 return &TermsOfServiceAgreementStateCallOptions{
64 GetTermsOfServiceAgreementState: []gax.CallOption{
65 gax.WithTimeout(60000 * time.Millisecond),
66 gax.WithRetry(func() gax.Retryer {
67 return gax.OnCodes([]codes.Code{
68 codes.Unavailable,
69 }, gax.Backoff{
70 Initial: 1000 * time.Millisecond,
71 Max: 10000 * time.Millisecond,
72 Multiplier: 1.30,
73 })
74 }),
75 },
76 RetrieveForApplicationTermsOfServiceAgreementState: []gax.CallOption{
77 gax.WithTimeout(60000 * time.Millisecond),
78 gax.WithRetry(func() gax.Retryer {
79 return gax.OnCodes([]codes.Code{
80 codes.Unavailable,
81 }, gax.Backoff{
82 Initial: 1000 * time.Millisecond,
83 Max: 10000 * time.Millisecond,
84 Multiplier: 1.30,
85 })
86 }),
87 },
88 }
89 }
90
91 func defaultTermsOfServiceAgreementStateRESTCallOptions() *TermsOfServiceAgreementStateCallOptions {
92 return &TermsOfServiceAgreementStateCallOptions{
93 GetTermsOfServiceAgreementState: []gax.CallOption{
94 gax.WithTimeout(60000 * time.Millisecond),
95 gax.WithRetry(func() gax.Retryer {
96 return gax.OnHTTPCodes(gax.Backoff{
97 Initial: 1000 * time.Millisecond,
98 Max: 10000 * time.Millisecond,
99 Multiplier: 1.30,
100 },
101 http.StatusServiceUnavailable)
102 }),
103 },
104 RetrieveForApplicationTermsOfServiceAgreementState: []gax.CallOption{
105 gax.WithTimeout(60000 * time.Millisecond),
106 gax.WithRetry(func() gax.Retryer {
107 return gax.OnHTTPCodes(gax.Backoff{
108 Initial: 1000 * time.Millisecond,
109 Max: 10000 * time.Millisecond,
110 Multiplier: 1.30,
111 },
112 http.StatusServiceUnavailable)
113 }),
114 },
115 }
116 }
117
118 // internalTermsOfServiceAgreementStateClient is an interface that defines the methods available from Merchant API.
119 type internalTermsOfServiceAgreementStateClient interface {
120 Close() error
121 setGoogleClientInfo(...string)
122 Connection() *grpc.ClientConn
123 GetTermsOfServiceAgreementState(context.Context, *accountspb.GetTermsOfServiceAgreementStateRequest, ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error)
124 RetrieveForApplicationTermsOfServiceAgreementState(context.Context, *accountspb.RetrieveForApplicationTermsOfServiceAgreementStateRequest, ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error)
125 }
126
127 // TermsOfServiceAgreementStateClient is a client for interacting with Merchant API.
128 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
129 //
130 // Service to support TermsOfServiceAgreementState API.
131 type TermsOfServiceAgreementStateClient struct {
132 // The internal transport-dependent client.
133 internalClient internalTermsOfServiceAgreementStateClient
134
135 // The call options for this service.
136 CallOptions *TermsOfServiceAgreementStateCallOptions
137 }
138
139 // Wrapper methods routed to the internal client.
140
141 // Close closes the connection to the API service. The user should invoke this when
142 // the client is no longer required.
143 func (c *TermsOfServiceAgreementStateClient) Close() error {
144 return c.internalClient.Close()
145 }
146
147 // setGoogleClientInfo sets the name and version of the application in
148 // the `x-goog-api-client` header passed on each request. Intended for
149 // use by Google-written clients.
150 func (c *TermsOfServiceAgreementStateClient) setGoogleClientInfo(keyval ...string) {
151 c.internalClient.setGoogleClientInfo(keyval...)
152 }
153
154 // Connection returns a connection to the API service.
155 //
156 // Deprecated: Connections are now pooled so this method does not always
157 // return the same resource.
158 func (c *TermsOfServiceAgreementStateClient) Connection() *grpc.ClientConn {
159 return c.internalClient.Connection()
160 }
161
162 // GetTermsOfServiceAgreementState returns the state of a terms of service agreement.
163 func (c *TermsOfServiceAgreementStateClient) GetTermsOfServiceAgreementState(ctx context.Context, req *accountspb.GetTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
164 return c.internalClient.GetTermsOfServiceAgreementState(ctx, req, opts...)
165 }
166
167 // RetrieveForApplicationTermsOfServiceAgreementState retrieves the state of the agreement for the application terms of service.
168 //
169 // Application terms of service covers permissions related to the usage of
170 // data provided through Merchant Center, CSS Center, Manufacturer Center, and
171 // more.
172 func (c *TermsOfServiceAgreementStateClient) RetrieveForApplicationTermsOfServiceAgreementState(ctx context.Context, req *accountspb.RetrieveForApplicationTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
173 return c.internalClient.RetrieveForApplicationTermsOfServiceAgreementState(ctx, req, opts...)
174 }
175
176 // termsOfServiceAgreementStateGRPCClient is a client for interacting with Merchant API over gRPC transport.
177 //
178 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
179 type termsOfServiceAgreementStateGRPCClient struct {
180 // Connection pool of gRPC connections to the service.
181 connPool gtransport.ConnPool
182
183 // Points back to the CallOptions field of the containing TermsOfServiceAgreementStateClient
184 CallOptions **TermsOfServiceAgreementStateCallOptions
185
186 // The gRPC API client.
187 termsOfServiceAgreementStateClient accountspb.TermsOfServiceAgreementStateServiceClient
188
189 // The x-goog-* metadata to be sent with each request.
190 xGoogHeaders []string
191
192 logger *slog.Logger
193 }
194
195 // NewTermsOfServiceAgreementStateClient creates a new terms of service agreement state service client based on gRPC.
196 // The returned client must be Closed when it is done being used to clean up its underlying connections.
197 //
198 // Service to support TermsOfServiceAgreementState API.
199 func NewTermsOfServiceAgreementStateClient(ctx context.Context, opts ...option.ClientOption) (*TermsOfServiceAgreementStateClient, error) {
200 clientOpts := defaultTermsOfServiceAgreementStateGRPCClientOptions()
201 if newTermsOfServiceAgreementStateClientHook != nil {
202 hookOpts, err := newTermsOfServiceAgreementStateClientHook(ctx, clientHookParams{})
203 if err != nil {
204 return nil, err
205 }
206 clientOpts = append(clientOpts, hookOpts...)
207 }
208
209 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
210 if err != nil {
211 return nil, err
212 }
213 client := TermsOfServiceAgreementStateClient{CallOptions: defaultTermsOfServiceAgreementStateCallOptions()}
214
215 c := &termsOfServiceAgreementStateGRPCClient{
216 connPool: connPool,
217 termsOfServiceAgreementStateClient: accountspb.NewTermsOfServiceAgreementStateServiceClient(connPool),
218 CallOptions: &client.CallOptions,
219 logger: internaloption.GetLogger(opts),
220 }
221 c.setGoogleClientInfo()
222
223 client.internalClient = c
224
225 return &client, nil
226 }
227
228 // Connection returns a connection to the API service.
229 //
230 // Deprecated: Connections are now pooled so this method does not always
231 // return the same resource.
232 func (c *termsOfServiceAgreementStateGRPCClient) Connection() *grpc.ClientConn {
233 return c.connPool.Conn()
234 }
235
236 // setGoogleClientInfo sets the name and version of the application in
237 // the `x-goog-api-client` header passed on each request. Intended for
238 // use by Google-written clients.
239 func (c *termsOfServiceAgreementStateGRPCClient) setGoogleClientInfo(keyval ...string) {
240 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
241 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
242 c.xGoogHeaders = []string{
243 "x-goog-api-client", gax.XGoogHeader(kv...),
244 }
245 }
246
247 // Close closes the connection to the API service. The user should invoke this when
248 // the client is no longer required.
249 func (c *termsOfServiceAgreementStateGRPCClient) Close() error {
250 return c.connPool.Close()
251 }
252
253 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
254 type termsOfServiceAgreementStateRESTClient struct {
255 // The http endpoint to connect to.
256 endpoint string
257
258 // The http client.
259 httpClient *http.Client
260
261 // The x-goog-* headers to be sent with each request.
262 xGoogHeaders []string
263
264 // Points back to the CallOptions field of the containing TermsOfServiceAgreementStateClient
265 CallOptions **TermsOfServiceAgreementStateCallOptions
266
267 logger *slog.Logger
268 }
269
270 // NewTermsOfServiceAgreementStateRESTClient creates a new terms of service agreement state service rest client.
271 //
272 // Service to support TermsOfServiceAgreementState API.
273 func NewTermsOfServiceAgreementStateRESTClient(ctx context.Context, opts ...option.ClientOption) (*TermsOfServiceAgreementStateClient, error) {
274 clientOpts := append(defaultTermsOfServiceAgreementStateRESTClientOptions(), opts...)
275 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
276 if err != nil {
277 return nil, err
278 }
279
280 callOpts := defaultTermsOfServiceAgreementStateRESTCallOptions()
281 c := &termsOfServiceAgreementStateRESTClient{
282 endpoint: endpoint,
283 httpClient: httpClient,
284 CallOptions: &callOpts,
285 logger: internaloption.GetLogger(opts),
286 }
287 c.setGoogleClientInfo()
288
289 return &TermsOfServiceAgreementStateClient{internalClient: c, CallOptions: callOpts}, nil
290 }
291
292 func defaultTermsOfServiceAgreementStateRESTClientOptions() []option.ClientOption {
293 return []option.ClientOption{
294 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
295 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
296 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
297 internaloption.WithDefaultUniverseDomain("googleapis.com"),
298 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
299 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
300 internaloption.EnableNewAuthLibrary(),
301 }
302 }
303
304 // setGoogleClientInfo sets the name and version of the application in
305 // the `x-goog-api-client` header passed on each request. Intended for
306 // use by Google-written clients.
307 func (c *termsOfServiceAgreementStateRESTClient) setGoogleClientInfo(keyval ...string) {
308 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
309 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
310 c.xGoogHeaders = []string{
311 "x-goog-api-client", gax.XGoogHeader(kv...),
312 }
313 }
314
315 // Close closes the connection to the API service. The user should invoke this when
316 // the client is no longer required.
317 func (c *termsOfServiceAgreementStateRESTClient) Close() error {
318 // Replace httpClient with nil to force cleanup.
319 c.httpClient = nil
320 return nil
321 }
322
323 // Connection returns a connection to the API service.
324 //
325 // Deprecated: This method always returns nil.
326 func (c *termsOfServiceAgreementStateRESTClient) Connection() *grpc.ClientConn {
327 return nil
328 }
329 func (c *termsOfServiceAgreementStateGRPCClient) GetTermsOfServiceAgreementState(ctx context.Context, req *accountspb.GetTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
330 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
331
332 hds = append(c.xGoogHeaders, hds...)
333 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
334 opts = append((*c.CallOptions).GetTermsOfServiceAgreementState[0:len((*c.CallOptions).GetTermsOfServiceAgreementState):len((*c.CallOptions).GetTermsOfServiceAgreementState)], opts...)
335 var resp *accountspb.TermsOfServiceAgreementState
336 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
337 var err error
338 resp, err = executeRPC(ctx, c.termsOfServiceAgreementStateClient.GetTermsOfServiceAgreementState, req, settings.GRPC, c.logger, "GetTermsOfServiceAgreementState")
339 return err
340 }, opts...)
341 if err != nil {
342 return nil, err
343 }
344 return resp, nil
345 }
346
347 func (c *termsOfServiceAgreementStateGRPCClient) RetrieveForApplicationTermsOfServiceAgreementState(ctx context.Context, req *accountspb.RetrieveForApplicationTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
348 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
349
350 hds = append(c.xGoogHeaders, hds...)
351 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
352 opts = append((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState[0:len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState):len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState)], opts...)
353 var resp *accountspb.TermsOfServiceAgreementState
354 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
355 var err error
356 resp, err = executeRPC(ctx, c.termsOfServiceAgreementStateClient.RetrieveForApplicationTermsOfServiceAgreementState, req, settings.GRPC, c.logger, "RetrieveForApplicationTermsOfServiceAgreementState")
357 return err
358 }, opts...)
359 if err != nil {
360 return nil, err
361 }
362 return resp, nil
363 }
364
365 // GetTermsOfServiceAgreementState returns the state of a terms of service agreement.
366 func (c *termsOfServiceAgreementStateRESTClient) GetTermsOfServiceAgreementState(ctx context.Context, req *accountspb.GetTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
367 baseUrl, err := url.Parse(c.endpoint)
368 if err != nil {
369 return nil, err
370 }
371 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetName())
372
373 params := url.Values{}
374 params.Add("$alt", "json;enum-encoding=int")
375
376 baseUrl.RawQuery = params.Encode()
377
378 // Build HTTP headers from client and context metadata.
379 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
380
381 hds = append(c.xGoogHeaders, hds...)
382 hds = append(hds, "Content-Type", "application/json")
383 headers := gax.BuildHeaders(ctx, hds...)
384 opts = append((*c.CallOptions).GetTermsOfServiceAgreementState[0:len((*c.CallOptions).GetTermsOfServiceAgreementState):len((*c.CallOptions).GetTermsOfServiceAgreementState)], opts...)
385 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
386 resp := &accountspb.TermsOfServiceAgreementState{}
387 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
388 if settings.Path != "" {
389 baseUrl.Path = settings.Path
390 }
391 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
392 if err != nil {
393 return err
394 }
395 httpReq = httpReq.WithContext(ctx)
396 httpReq.Header = headers
397
398 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTermsOfServiceAgreementState")
399 if err != nil {
400 return err
401 }
402
403 if err := unm.Unmarshal(buf, resp); err != nil {
404 return err
405 }
406
407 return nil
408 }, opts...)
409 if e != nil {
410 return nil, e
411 }
412 return resp, nil
413 }
414
415 // RetrieveForApplicationTermsOfServiceAgreementState retrieves the state of the agreement for the application terms of service.
416 //
417 // Application terms of service covers permissions related to the usage of
418 // data provided through Merchant Center, CSS Center, Manufacturer Center, and
419 // more.
420 func (c *termsOfServiceAgreementStateRESTClient) RetrieveForApplicationTermsOfServiceAgreementState(ctx context.Context, req *accountspb.RetrieveForApplicationTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
421 baseUrl, err := url.Parse(c.endpoint)
422 if err != nil {
423 return nil, err
424 }
425 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/termsOfServiceAgreementStates:retrieveForApplication", req.GetParent())
426
427 params := url.Values{}
428 params.Add("$alt", "json;enum-encoding=int")
429
430 baseUrl.RawQuery = params.Encode()
431
432 // Build HTTP headers from client and context metadata.
433 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
434
435 hds = append(c.xGoogHeaders, hds...)
436 hds = append(hds, "Content-Type", "application/json")
437 headers := gax.BuildHeaders(ctx, hds...)
438 opts = append((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState[0:len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState):len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState)], opts...)
439 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
440 resp := &accountspb.TermsOfServiceAgreementState{}
441 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
442 if settings.Path != "" {
443 baseUrl.Path = settings.Path
444 }
445 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
446 if err != nil {
447 return err
448 }
449 httpReq = httpReq.WithContext(ctx)
450 httpReq.Header = headers
451
452 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "RetrieveForApplicationTermsOfServiceAgreementState")
453 if err != nil {
454 return err
455 }
456
457 if err := unm.Unmarshal(buf, resp); err != nil {
458 return err
459 }
460
461 return nil
462 }, opts...)
463 if e != nil {
464 return nil, e
465 }
466 return resp, nil
467 }