Debian Codegraph @

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