Debian Codegraph @

shopping/merchant/accounts/apiv1beta/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/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 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 func (c *TermsOfServiceAgreementStateClient) RetrieveForApplicationTermsOfServiceAgreementState(ctx context.Context, req *accountspb.RetrieveForApplicationTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
169 return c.internalClient.RetrieveForApplicationTermsOfServiceAgreementState(ctx, req, opts...)
170 }
171
172 // termsOfServiceAgreementStateGRPCClient is a client for interacting with Merchant API over gRPC transport.
173 //
174 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
175 type termsOfServiceAgreementStateGRPCClient struct {
176 // Connection pool of gRPC connections to the service.
177 connPool gtransport.ConnPool
178
179 // Points back to the CallOptions field of the containing TermsOfServiceAgreementStateClient
180 CallOptions **TermsOfServiceAgreementStateCallOptions
181
182 // The gRPC API client.
183 termsOfServiceAgreementStateClient accountspb.TermsOfServiceAgreementStateServiceClient
184
185 // The x-goog-* metadata to be sent with each request.
186 xGoogHeaders []string
187
188 logger *slog.Logger
189 }
190
191 // NewTermsOfServiceAgreementStateClient creates a new terms of service agreement state service client based on gRPC.
192 // The returned client must be Closed when it is done being used to clean up its underlying connections.
193 //
194 // Service to support TermsOfServiceAgreementState API.
195 func NewTermsOfServiceAgreementStateClient(ctx context.Context, opts ...option.ClientOption) (*TermsOfServiceAgreementStateClient, error) {
196 clientOpts := defaultTermsOfServiceAgreementStateGRPCClientOptions()
197 if newTermsOfServiceAgreementStateClientHook != nil {
198 hookOpts, err := newTermsOfServiceAgreementStateClientHook(ctx, clientHookParams{})
199 if err != nil {
200 return nil, err
201 }
202 clientOpts = append(clientOpts, hookOpts...)
203 }
204
205 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
206 if err != nil {
207 return nil, err
208 }
209 client := TermsOfServiceAgreementStateClient{CallOptions: defaultTermsOfServiceAgreementStateCallOptions()}
210
211 c := &termsOfServiceAgreementStateGRPCClient{
212 connPool: connPool,
213 termsOfServiceAgreementStateClient: accountspb.NewTermsOfServiceAgreementStateServiceClient(connPool),
214 CallOptions: &client.CallOptions,
215 logger: internaloption.GetLogger(opts),
216 }
217 c.setGoogleClientInfo()
218
219 client.internalClient = c
220
221 return &client, nil
222 }
223
224 // Connection returns a connection to the API service.
225 //
226 // Deprecated: Connections are now pooled so this method does not always
227 // return the same resource.
228 func (c *termsOfServiceAgreementStateGRPCClient) Connection() *grpc.ClientConn {
229 return c.connPool.Conn()
230 }
231
232 // setGoogleClientInfo sets the name and version of the application in
233 // the `x-goog-api-client` header passed on each request. Intended for
234 // use by Google-written clients.
235 func (c *termsOfServiceAgreementStateGRPCClient) setGoogleClientInfo(keyval ...string) {
236 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
237 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
238 c.xGoogHeaders = []string{
239 "x-goog-api-client", gax.XGoogHeader(kv...),
240 }
241 }
242
243 // Close closes the connection to the API service. The user should invoke this when
244 // the client is no longer required.
245 func (c *termsOfServiceAgreementStateGRPCClient) Close() error {
246 return c.connPool.Close()
247 }
248
249 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
250 type termsOfServiceAgreementStateRESTClient struct {
251 // The http endpoint to connect to.
252 endpoint string
253
254 // The http client.
255 httpClient *http.Client
256
257 // The x-goog-* headers to be sent with each request.
258 xGoogHeaders []string
259
260 // Points back to the CallOptions field of the containing TermsOfServiceAgreementStateClient
261 CallOptions **TermsOfServiceAgreementStateCallOptions
262
263 logger *slog.Logger
264 }
265
266 // NewTermsOfServiceAgreementStateRESTClient creates a new terms of service agreement state service rest client.
267 //
268 // Service to support TermsOfServiceAgreementState API.
269 func NewTermsOfServiceAgreementStateRESTClient(ctx context.Context, opts ...option.ClientOption) (*TermsOfServiceAgreementStateClient, error) {
270 clientOpts := append(defaultTermsOfServiceAgreementStateRESTClientOptions(), opts...)
271 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
272 if err != nil {
273 return nil, err
274 }
275
276 callOpts := defaultTermsOfServiceAgreementStateRESTCallOptions()
277 c := &termsOfServiceAgreementStateRESTClient{
278 endpoint: endpoint,
279 httpClient: httpClient,
280 CallOptions: &callOpts,
281 logger: internaloption.GetLogger(opts),
282 }
283 c.setGoogleClientInfo()
284
285 return &TermsOfServiceAgreementStateClient{internalClient: c, CallOptions: callOpts}, nil
286 }
287
288 func defaultTermsOfServiceAgreementStateRESTClientOptions() []option.ClientOption {
289 return []option.ClientOption{
290 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
291 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
292 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
293 internaloption.WithDefaultUniverseDomain("googleapis.com"),
294 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
295 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
296 internaloption.EnableNewAuthLibrary(),
297 }
298 }
299
300 // setGoogleClientInfo sets the name and version of the application in
301 // the `x-goog-api-client` header passed on each request. Intended for
302 // use by Google-written clients.
303 func (c *termsOfServiceAgreementStateRESTClient) setGoogleClientInfo(keyval ...string) {
304 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
305 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
306 c.xGoogHeaders = []string{
307 "x-goog-api-client", gax.XGoogHeader(kv...),
308 }
309 }
310
311 // Close closes the connection to the API service. The user should invoke this when
312 // the client is no longer required.
313 func (c *termsOfServiceAgreementStateRESTClient) Close() error {
314 // Replace httpClient with nil to force cleanup.
315 c.httpClient = nil
316 return nil
317 }
318
319 // Connection returns a connection to the API service.
320 //
321 // Deprecated: This method always returns nil.
322 func (c *termsOfServiceAgreementStateRESTClient) Connection() *grpc.ClientConn {
323 return nil
324 }
325 func (c *termsOfServiceAgreementStateGRPCClient) GetTermsOfServiceAgreementState(ctx context.Context, req *accountspb.GetTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
326 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
327
328 hds = append(c.xGoogHeaders, hds...)
329 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
330 opts = append((*c.CallOptions).GetTermsOfServiceAgreementState[0:len((*c.CallOptions).GetTermsOfServiceAgreementState):len((*c.CallOptions).GetTermsOfServiceAgreementState)], opts...)
331 var resp *accountspb.TermsOfServiceAgreementState
332 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
333 var err error
334 resp, err = executeRPC(ctx, c.termsOfServiceAgreementStateClient.GetTermsOfServiceAgreementState, req, settings.GRPC, c.logger, "GetTermsOfServiceAgreementState")
335 return err
336 }, opts...)
337 if err != nil {
338 return nil, err
339 }
340 return resp, nil
341 }
342
343 func (c *termsOfServiceAgreementStateGRPCClient) RetrieveForApplicationTermsOfServiceAgreementState(ctx context.Context, req *accountspb.RetrieveForApplicationTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
344 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
345
346 hds = append(c.xGoogHeaders, hds...)
347 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
348 opts = append((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState[0:len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState):len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState)], opts...)
349 var resp *accountspb.TermsOfServiceAgreementState
350 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
351 var err error
352 resp, err = executeRPC(ctx, c.termsOfServiceAgreementStateClient.RetrieveForApplicationTermsOfServiceAgreementState, req, settings.GRPC, c.logger, "RetrieveForApplicationTermsOfServiceAgreementState")
353 return err
354 }, opts...)
355 if err != nil {
356 return nil, err
357 }
358 return resp, nil
359 }
360
361 // GetTermsOfServiceAgreementState returns the state of a terms of service agreement.
362 func (c *termsOfServiceAgreementStateRESTClient) GetTermsOfServiceAgreementState(ctx context.Context, req *accountspb.GetTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
363 baseUrl, err := url.Parse(c.endpoint)
364 if err != nil {
365 return nil, err
366 }
367 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName())
368
369 params := url.Values{}
370 params.Add("$alt", "json;enum-encoding=int")
371
372 baseUrl.RawQuery = params.Encode()
373
374 // Build HTTP headers from client and context metadata.
375 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
376
377 hds = append(c.xGoogHeaders, hds...)
378 hds = append(hds, "Content-Type", "application/json")
379 headers := gax.BuildHeaders(ctx, hds...)
380 opts = append((*c.CallOptions).GetTermsOfServiceAgreementState[0:len((*c.CallOptions).GetTermsOfServiceAgreementState):len((*c.CallOptions).GetTermsOfServiceAgreementState)], opts...)
381 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
382 resp := &accountspb.TermsOfServiceAgreementState{}
383 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
384 if settings.Path != "" {
385 baseUrl.Path = settings.Path
386 }
387 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
388 if err != nil {
389 return err
390 }
391 httpReq = httpReq.WithContext(ctx)
392 httpReq.Header = headers
393
394 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTermsOfServiceAgreementState")
395 if err != nil {
396 return err
397 }
398
399 if err := unm.Unmarshal(buf, resp); err != nil {
400 return err
401 }
402
403 return nil
404 }, opts...)
405 if e != nil {
406 return nil, e
407 }
408 return resp, nil
409 }
410
411 // RetrieveForApplicationTermsOfServiceAgreementState retrieves the state of the agreement for the application terms of service.
412 func (c *termsOfServiceAgreementStateRESTClient) RetrieveForApplicationTermsOfServiceAgreementState(ctx context.Context, req *accountspb.RetrieveForApplicationTermsOfServiceAgreementStateRequest, opts ...gax.CallOption) (*accountspb.TermsOfServiceAgreementState, error) {
413 baseUrl, err := url.Parse(c.endpoint)
414 if err != nil {
415 return nil, err
416 }
417 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v/termsOfServiceAgreementStates:retrieveForApplication", req.GetParent())
418
419 params := url.Values{}
420 params.Add("$alt", "json;enum-encoding=int")
421
422 baseUrl.RawQuery = params.Encode()
423
424 // Build HTTP headers from client and context metadata.
425 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
426
427 hds = append(c.xGoogHeaders, hds...)
428 hds = append(hds, "Content-Type", "application/json")
429 headers := gax.BuildHeaders(ctx, hds...)
430 opts = append((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState[0:len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState):len((*c.CallOptions).RetrieveForApplicationTermsOfServiceAgreementState)], opts...)
431 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
432 resp := &accountspb.TermsOfServiceAgreementState{}
433 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
434 if settings.Path != "" {
435 baseUrl.Path = settings.Path
436 }
437 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
438 if err != nil {
439 return err
440 }
441 httpReq = httpReq.WithContext(ctx)
442 httpReq.Header = headers
443
444 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "RetrieveForApplicationTermsOfServiceAgreementState")
445 if err != nil {
446 return err
447 }
448
449 if err := unm.Unmarshal(buf, resp); err != nil {
450 return err
451 }
452
453 return nil
454 }, opts...)
455 if e != nil {
456 return nil, e
457 }
458 return resp, nil
459 }