Debian Codegraph @

shopping/merchant/lfp/apiv1beta/lfp_store_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 lfp
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 lfppb "cloud.google.com/go/shopping/merchant/lfp/apiv1beta/lfppb"
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 newLfpStoreClientHook clientHook
43
44 // LfpStoreCallOptions contains the retry settings for each method of LfpStoreClient.
45 type LfpStoreCallOptions struct {
46 GetLfpStore []gax.CallOption
47 InsertLfpStore []gax.CallOption
48 DeleteLfpStore []gax.CallOption
49 ListLfpStores []gax.CallOption
50 }
51
52 func defaultLfpStoreGRPCClientOptions() []option.ClientOption {
53 return []option.ClientOption{
54 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
55 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
56 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
57 internaloption.WithDefaultUniverseDomain("googleapis.com"),
58 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
59 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
60 internaloption.EnableJwtWithScope(),
61 internaloption.EnableNewAuthLibrary(),
62 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
63 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
64 }
65 }
66
67 func defaultLfpStoreCallOptions() *LfpStoreCallOptions {
68 return &LfpStoreCallOptions{
69 GetLfpStore: []gax.CallOption{
70 gax.WithTimeout(60000 * time.Millisecond),
71 gax.WithRetry(func() gax.Retryer {
72 return gax.OnCodes([]codes.Code{
73 codes.Unavailable,
74 }, gax.Backoff{
75 Initial: 1000 * time.Millisecond,
76 Max: 10000 * time.Millisecond,
77 Multiplier: 1.30,
78 })
79 }),
80 },
81 InsertLfpStore: []gax.CallOption{
82 gax.WithTimeout(60000 * time.Millisecond),
83 gax.WithRetry(func() gax.Retryer {
84 return gax.OnCodes([]codes.Code{
85 codes.Unavailable,
86 }, gax.Backoff{
87 Initial: 1000 * time.Millisecond,
88 Max: 10000 * time.Millisecond,
89 Multiplier: 1.30,
90 })
91 }),
92 },
93 DeleteLfpStore: []gax.CallOption{
94 gax.WithTimeout(60000 * time.Millisecond),
95 gax.WithRetry(func() gax.Retryer {
96 return gax.OnCodes([]codes.Code{
97 codes.Unavailable,
98 }, gax.Backoff{
99 Initial: 1000 * time.Millisecond,
100 Max: 10000 * time.Millisecond,
101 Multiplier: 1.30,
102 })
103 }),
104 },
105 ListLfpStores: []gax.CallOption{
106 gax.WithTimeout(60000 * time.Millisecond),
107 gax.WithRetry(func() gax.Retryer {
108 return gax.OnCodes([]codes.Code{
109 codes.Unavailable,
110 }, gax.Backoff{
111 Initial: 1000 * time.Millisecond,
112 Max: 10000 * time.Millisecond,
113 Multiplier: 1.30,
114 })
115 }),
116 },
117 }
118 }
119
120 func defaultLfpStoreRESTCallOptions() *LfpStoreCallOptions {
121 return &LfpStoreCallOptions{
122 GetLfpStore: []gax.CallOption{
123 gax.WithTimeout(60000 * time.Millisecond),
124 gax.WithRetry(func() gax.Retryer {
125 return gax.OnHTTPCodes(gax.Backoff{
126 Initial: 1000 * time.Millisecond,
127 Max: 10000 * time.Millisecond,
128 Multiplier: 1.30,
129 },
130 http.StatusServiceUnavailable)
131 }),
132 },
133 InsertLfpStore: []gax.CallOption{
134 gax.WithTimeout(60000 * time.Millisecond),
135 gax.WithRetry(func() gax.Retryer {
136 return gax.OnHTTPCodes(gax.Backoff{
137 Initial: 1000 * time.Millisecond,
138 Max: 10000 * time.Millisecond,
139 Multiplier: 1.30,
140 },
141 http.StatusServiceUnavailable)
142 }),
143 },
144 DeleteLfpStore: []gax.CallOption{
145 gax.WithTimeout(60000 * time.Millisecond),
146 gax.WithRetry(func() gax.Retryer {
147 return gax.OnHTTPCodes(gax.Backoff{
148 Initial: 1000 * time.Millisecond,
149 Max: 10000 * time.Millisecond,
150 Multiplier: 1.30,
151 },
152 http.StatusServiceUnavailable)
153 }),
154 },
155 ListLfpStores: []gax.CallOption{
156 gax.WithTimeout(60000 * time.Millisecond),
157 gax.WithRetry(func() gax.Retryer {
158 return gax.OnHTTPCodes(gax.Backoff{
159 Initial: 1000 * time.Millisecond,
160 Max: 10000 * time.Millisecond,
161 Multiplier: 1.30,
162 },
163 http.StatusServiceUnavailable)
164 }),
165 },
166 }
167 }
168
169 // internalLfpStoreClient is an interface that defines the methods available from Merchant API.
170 type internalLfpStoreClient interface {
171 Close() error
172 setGoogleClientInfo(...string)
173 Connection() *grpc.ClientConn
174 GetLfpStore(context.Context, *lfppb.GetLfpStoreRequest, ...gax.CallOption) (*lfppb.LfpStore, error)
175 InsertLfpStore(context.Context, *lfppb.InsertLfpStoreRequest, ...gax.CallOption) (*lfppb.LfpStore, error)
176 DeleteLfpStore(context.Context, *lfppb.DeleteLfpStoreRequest, ...gax.CallOption) error
177 ListLfpStores(context.Context, *lfppb.ListLfpStoresRequest, ...gax.CallOption) *LfpStoreIterator
178 }
179
180 // LfpStoreClient is a client for interacting with Merchant API.
181 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
182 //
183 // Service for a LFP
184 // partner (at https://support.google.com/merchants/answer/7676652) to submit local
185 // stores for a merchant.
186 type LfpStoreClient struct {
187 // The internal transport-dependent client.
188 internalClient internalLfpStoreClient
189
190 // The call options for this service.
191 CallOptions *LfpStoreCallOptions
192 }
193
194 // Wrapper methods routed to the internal client.
195
196 // Close closes the connection to the API service. The user should invoke this when
197 // the client is no longer required.
198 func (c *LfpStoreClient) Close() error {
199 return c.internalClient.Close()
200 }
201
202 // setGoogleClientInfo sets the name and version of the application in
203 // the `x-goog-api-client` header passed on each request. Intended for
204 // use by Google-written clients.
205 func (c *LfpStoreClient) setGoogleClientInfo(keyval ...string) {
206 c.internalClient.setGoogleClientInfo(keyval...)
207 }
208
209 // Connection returns a connection to the API service.
210 //
211 // Deprecated: Connections are now pooled so this method does not always
212 // return the same resource.
213 func (c *LfpStoreClient) Connection() *grpc.ClientConn {
214 return c.internalClient.Connection()
215 }
216
217 // GetLfpStore retrieves information about a store.
218 func (c *LfpStoreClient) GetLfpStore(ctx context.Context, req *lfppb.GetLfpStoreRequest, opts ...gax.CallOption) (*lfppb.LfpStore, error) {
219 return c.internalClient.GetLfpStore(ctx, req, opts...)
220 }
221
222 // InsertLfpStore inserts a store for the target merchant. If the store with the same store
223 // code already exists, it will be replaced.
224 func (c *LfpStoreClient) InsertLfpStore(ctx context.Context, req *lfppb.InsertLfpStoreRequest, opts ...gax.CallOption) (*lfppb.LfpStore, error) {
225 return c.internalClient.InsertLfpStore(ctx, req, opts...)
226 }
227
228 // DeleteLfpStore deletes a store for a target merchant.
229 func (c *LfpStoreClient) DeleteLfpStore(ctx context.Context, req *lfppb.DeleteLfpStoreRequest, opts ...gax.CallOption) error {
230 return c.internalClient.DeleteLfpStore(ctx, req, opts...)
231 }
232
233 // ListLfpStores lists the stores of the target merchant, specified by the filter in
234 // ListLfpStoresRequest.
235 func (c *LfpStoreClient) ListLfpStores(ctx context.Context, req *lfppb.ListLfpStoresRequest, opts ...gax.CallOption) *LfpStoreIterator {
236 return c.internalClient.ListLfpStores(ctx, req, opts...)
237 }
238
239 // lfpStoreGRPCClient is a client for interacting with Merchant API over gRPC transport.
240 //
241 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
242 type lfpStoreGRPCClient struct {
243 // Connection pool of gRPC connections to the service.
244 connPool gtransport.ConnPool
245
246 // Points back to the CallOptions field of the containing LfpStoreClient
247 CallOptions **LfpStoreCallOptions
248
249 // The gRPC API client.
250 lfpStoreClient lfppb.LfpStoreServiceClient
251
252 // The x-goog-* metadata to be sent with each request.
253 xGoogHeaders []string
254
255 logger *slog.Logger
256 }
257
258 // NewLfpStoreClient creates a new lfp store service client based on gRPC.
259 // The returned client must be Closed when it is done being used to clean up its underlying connections.
260 //
261 // Service for a LFP
262 // partner (at https://support.google.com/merchants/answer/7676652) to submit local
263 // stores for a merchant.
264 func NewLfpStoreClient(ctx context.Context, opts ...option.ClientOption) (*LfpStoreClient, error) {
265 clientOpts := defaultLfpStoreGRPCClientOptions()
266 if newLfpStoreClientHook != nil {
267 hookOpts, err := newLfpStoreClientHook(ctx, clientHookParams{})
268 if err != nil {
269 return nil, err
270 }
271 clientOpts = append(clientOpts, hookOpts...)
272 }
273
274 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
275 if err != nil {
276 return nil, err
277 }
278 client := LfpStoreClient{CallOptions: defaultLfpStoreCallOptions()}
279
280 c := &lfpStoreGRPCClient{
281 connPool: connPool,
282 lfpStoreClient: lfppb.NewLfpStoreServiceClient(connPool),
283 CallOptions: &client.CallOptions,
284 logger: internaloption.GetLogger(opts),
285 }
286 c.setGoogleClientInfo()
287
288 client.internalClient = c
289
290 return &client, nil
291 }
292
293 // Connection returns a connection to the API service.
294 //
295 // Deprecated: Connections are now pooled so this method does not always
296 // return the same resource.
297 func (c *lfpStoreGRPCClient) Connection() *grpc.ClientConn {
298 return c.connPool.Conn()
299 }
300
301 // setGoogleClientInfo sets the name and version of the application in
302 // the `x-goog-api-client` header passed on each request. Intended for
303 // use by Google-written clients.
304 func (c *lfpStoreGRPCClient) setGoogleClientInfo(keyval ...string) {
305 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
306 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
307 c.xGoogHeaders = []string{
308 "x-goog-api-client", gax.XGoogHeader(kv...),
309 }
310 }
311
312 // Close closes the connection to the API service. The user should invoke this when
313 // the client is no longer required.
314 func (c *lfpStoreGRPCClient) Close() error {
315 return c.connPool.Close()
316 }
317
318 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
319 type lfpStoreRESTClient struct {
320 // The http endpoint to connect to.
321 endpoint string
322
323 // The http client.
324 httpClient *http.Client
325
326 // The x-goog-* headers to be sent with each request.
327 xGoogHeaders []string
328
329 // Points back to the CallOptions field of the containing LfpStoreClient
330 CallOptions **LfpStoreCallOptions
331
332 logger *slog.Logger
333 }
334
335 // NewLfpStoreRESTClient creates a new lfp store service rest client.
336 //
337 // Service for a LFP
338 // partner (at https://support.google.com/merchants/answer/7676652) to submit local
339 // stores for a merchant.
340 func NewLfpStoreRESTClient(ctx context.Context, opts ...option.ClientOption) (*LfpStoreClient, error) {
341 clientOpts := append(defaultLfpStoreRESTClientOptions(), opts...)
342 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
343 if err != nil {
344 return nil, err
345 }
346
347 callOpts := defaultLfpStoreRESTCallOptions()
348 c := &lfpStoreRESTClient{
349 endpoint: endpoint,
350 httpClient: httpClient,
351 CallOptions: &callOpts,
352 logger: internaloption.GetLogger(opts),
353 }
354 c.setGoogleClientInfo()
355
356 return &LfpStoreClient{internalClient: c, CallOptions: callOpts}, nil
357 }
358
359 func defaultLfpStoreRESTClientOptions() []option.ClientOption {
360 return []option.ClientOption{
361 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
362 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
363 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
364 internaloption.WithDefaultUniverseDomain("googleapis.com"),
365 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
366 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
367 internaloption.EnableNewAuthLibrary(),
368 }
369 }
370
371 // setGoogleClientInfo sets the name and version of the application in
372 // the `x-goog-api-client` header passed on each request. Intended for
373 // use by Google-written clients.
374 func (c *lfpStoreRESTClient) setGoogleClientInfo(keyval ...string) {
375 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
376 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
377 c.xGoogHeaders = []string{
378 "x-goog-api-client", gax.XGoogHeader(kv...),
379 }
380 }
381
382 // Close closes the connection to the API service. The user should invoke this when
383 // the client is no longer required.
384 func (c *lfpStoreRESTClient) Close() error {
385 // Replace httpClient with nil to force cleanup.
386 c.httpClient = nil
387 return nil
388 }
389
390 // Connection returns a connection to the API service.
391 //
392 // Deprecated: This method always returns nil.
393 func (c *lfpStoreRESTClient) Connection() *grpc.ClientConn {
394 return nil
395 }
396 func (c *lfpStoreGRPCClient) GetLfpStore(ctx context.Context, req *lfppb.GetLfpStoreRequest, opts ...gax.CallOption) (*lfppb.LfpStore, error) {
397 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
398
399 hds = append(c.xGoogHeaders, hds...)
400 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
401 opts = append((*c.CallOptions).GetLfpStore[0:len((*c.CallOptions).GetLfpStore):len((*c.CallOptions).GetLfpStore)], opts...)
402 var resp *lfppb.LfpStore
403 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
404 var err error
405 resp, err = executeRPC(ctx, c.lfpStoreClient.GetLfpStore, req, settings.GRPC, c.logger, "GetLfpStore")
406 return err
407 }, opts...)
408 if err != nil {
409 return nil, err
410 }
411 return resp, nil
412 }
413
414 func (c *lfpStoreGRPCClient) InsertLfpStore(ctx context.Context, req *lfppb.InsertLfpStoreRequest, opts ...gax.CallOption) (*lfppb.LfpStore, error) {
415 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
416
417 hds = append(c.xGoogHeaders, hds...)
418 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
419 opts = append((*c.CallOptions).InsertLfpStore[0:len((*c.CallOptions).InsertLfpStore):len((*c.CallOptions).InsertLfpStore)], opts...)
420 var resp *lfppb.LfpStore
421 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
422 var err error
423 resp, err = executeRPC(ctx, c.lfpStoreClient.InsertLfpStore, req, settings.GRPC, c.logger, "InsertLfpStore")
424 return err
425 }, opts...)
426 if err != nil {
427 return nil, err
428 }
429 return resp, nil
430 }
431
432 func (c *lfpStoreGRPCClient) DeleteLfpStore(ctx context.Context, req *lfppb.DeleteLfpStoreRequest, opts ...gax.CallOption) error {
433 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
434
435 hds = append(c.xGoogHeaders, hds...)
436 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
437 opts = append((*c.CallOptions).DeleteLfpStore[0:len((*c.CallOptions).DeleteLfpStore):len((*c.CallOptions).DeleteLfpStore)], opts...)
438 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
439 var err error
440 _, err = executeRPC(ctx, c.lfpStoreClient.DeleteLfpStore, req, settings.GRPC, c.logger, "DeleteLfpStore")
441 return err
442 }, opts...)
443 return err
444 }
445
446 func (c *lfpStoreGRPCClient) ListLfpStores(ctx context.Context, req *lfppb.ListLfpStoresRequest, opts ...gax.CallOption) *LfpStoreIterator {
447 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
448
449 hds = append(c.xGoogHeaders, hds...)
450 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
451 opts = append((*c.CallOptions).ListLfpStores[0:len((*c.CallOptions).ListLfpStores):len((*c.CallOptions).ListLfpStores)], opts...)
452 it := &LfpStoreIterator{}
453 req = proto.Clone(req).(*lfppb.ListLfpStoresRequest)
454 it.InternalFetch = func(pageSize int, pageToken string) ([]*lfppb.LfpStore, string, error) {
455 resp := &lfppb.ListLfpStoresResponse{}
456 if pageToken != "" {
457 req.PageToken = pageToken
458 }
459 if pageSize > math.MaxInt32 {
460 req.PageSize = math.MaxInt32
461 } else if pageSize != 0 {
462 req.PageSize = int32(pageSize)
463 }
464 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
465 var err error
466 resp, err = executeRPC(ctx, c.lfpStoreClient.ListLfpStores, req, settings.GRPC, c.logger, "ListLfpStores")
467 return err
468 }, opts...)
469 if err != nil {
470 return nil, "", err
471 }
472
473 it.Response = resp
474 return resp.GetLfpStores(), resp.GetNextPageToken(), nil
475 }
476 fetch := func(pageSize int, pageToken string) (string, error) {
477 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
478 if err != nil {
479 return "", err
480 }
481 it.items = append(it.items, items...)
482 return nextPageToken, nil
483 }
484
485 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
486 it.pageInfo.MaxSize = int(req.GetPageSize())
487 it.pageInfo.Token = req.GetPageToken()
488
489 return it
490 }
491
492 // GetLfpStore retrieves information about a store.
493 func (c *lfpStoreRESTClient) GetLfpStore(ctx context.Context, req *lfppb.GetLfpStoreRequest, opts ...gax.CallOption) (*lfppb.LfpStore, error) {
494 baseUrl, err := url.Parse(c.endpoint)
495 if err != nil {
496 return nil, err
497 }
498 baseUrl.Path += fmt.Sprintf("/lfp/v1beta/%v", req.GetName())
499
500 params := url.Values{}
501 params.Add("$alt", "json;enum-encoding=int")
502
503 baseUrl.RawQuery = params.Encode()
504
505 // Build HTTP headers from client and context metadata.
506 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
507
508 hds = append(c.xGoogHeaders, hds...)
509 hds = append(hds, "Content-Type", "application/json")
510 headers := gax.BuildHeaders(ctx, hds...)
511 opts = append((*c.CallOptions).GetLfpStore[0:len((*c.CallOptions).GetLfpStore):len((*c.CallOptions).GetLfpStore)], opts...)
512 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
513 resp := &lfppb.LfpStore{}
514 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
515 if settings.Path != "" {
516 baseUrl.Path = settings.Path
517 }
518 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
519 if err != nil {
520 return err
521 }
522 httpReq = httpReq.WithContext(ctx)
523 httpReq.Header = headers
524
525 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLfpStore")
526 if err != nil {
527 return err
528 }
529
530 if err := unm.Unmarshal(buf, resp); err != nil {
531 return err
532 }
533
534 return nil
535 }, opts...)
536 if e != nil {
537 return nil, e
538 }
539 return resp, nil
540 }
541
542 // InsertLfpStore inserts a store for the target merchant. If the store with the same store
543 // code already exists, it will be replaced.
544 func (c *lfpStoreRESTClient) InsertLfpStore(ctx context.Context, req *lfppb.InsertLfpStoreRequest, opts ...gax.CallOption) (*lfppb.LfpStore, error) {
545 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
546 body := req.GetLfpStore()
547 jsonReq, err := m.Marshal(body)
548 if err != nil {
549 return nil, err
550 }
551
552 baseUrl, err := url.Parse(c.endpoint)
553 if err != nil {
554 return nil, err
555 }
556 baseUrl.Path += fmt.Sprintf("/lfp/v1beta/%v/lfpStores:insert", req.GetParent())
557
558 params := url.Values{}
559 params.Add("$alt", "json;enum-encoding=int")
560
561 baseUrl.RawQuery = params.Encode()
562
563 // Build HTTP headers from client and context metadata.
564 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
565
566 hds = append(c.xGoogHeaders, hds...)
567 hds = append(hds, "Content-Type", "application/json")
568 headers := gax.BuildHeaders(ctx, hds...)
569 opts = append((*c.CallOptions).InsertLfpStore[0:len((*c.CallOptions).InsertLfpStore):len((*c.CallOptions).InsertLfpStore)], opts...)
570 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
571 resp := &lfppb.LfpStore{}
572 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
573 if settings.Path != "" {
574 baseUrl.Path = settings.Path
575 }
576 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
577 if err != nil {
578 return err
579 }
580 httpReq = httpReq.WithContext(ctx)
581 httpReq.Header = headers
582
583 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "InsertLfpStore")
584 if err != nil {
585 return err
586 }
587
588 if err := unm.Unmarshal(buf, resp); err != nil {
589 return err
590 }
591
592 return nil
593 }, opts...)
594 if e != nil {
595 return nil, e
596 }
597 return resp, nil
598 }
599
600 // DeleteLfpStore deletes a store for a target merchant.
601 func (c *lfpStoreRESTClient) DeleteLfpStore(ctx context.Context, req *lfppb.DeleteLfpStoreRequest, opts ...gax.CallOption) error {
602 baseUrl, err := url.Parse(c.endpoint)
603 if err != nil {
604 return err
605 }
606 baseUrl.Path += fmt.Sprintf("/lfp/v1beta/%v", req.GetName())
607
608 params := url.Values{}
609 params.Add("$alt", "json;enum-encoding=int")
610
611 baseUrl.RawQuery = params.Encode()
612
613 // Build HTTP headers from client and context metadata.
614 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
615
616 hds = append(c.xGoogHeaders, hds...)
617 hds = append(hds, "Content-Type", "application/json")
618 headers := gax.BuildHeaders(ctx, hds...)
619 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
620 if settings.Path != "" {
621 baseUrl.Path = settings.Path
622 }
623 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
624 if err != nil {
625 return err
626 }
627 httpReq = httpReq.WithContext(ctx)
628 httpReq.Header = headers
629
630 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteLfpStore")
631 return err
632 }, opts...)
633 }
634
635 // ListLfpStores lists the stores of the target merchant, specified by the filter in
636 // ListLfpStoresRequest.
637 func (c *lfpStoreRESTClient) ListLfpStores(ctx context.Context, req *lfppb.ListLfpStoresRequest, opts ...gax.CallOption) *LfpStoreIterator {
638 it := &LfpStoreIterator{}
639 req = proto.Clone(req).(*lfppb.ListLfpStoresRequest)
640 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
641 it.InternalFetch = func(pageSize int, pageToken string) ([]*lfppb.LfpStore, string, error) {
642 resp := &lfppb.ListLfpStoresResponse{}
643 if pageToken != "" {
644 req.PageToken = pageToken
645 }
646 if pageSize > math.MaxInt32 {
647 req.PageSize = math.MaxInt32
648 } else if pageSize != 0 {
649 req.PageSize = int32(pageSize)
650 }
651 baseUrl, err := url.Parse(c.endpoint)
652 if err != nil {
653 return nil, "", err
654 }
655 baseUrl.Path += fmt.Sprintf("/lfp/v1beta/%v/lfpStores", req.GetParent())
656
657 params := url.Values{}
658 params.Add("$alt", "json;enum-encoding=int")
659 if req.GetPageSize() != 0 {
660 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
661 }
662 if req.GetPageToken() != "" {
663 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
664 }
665 params.Add("targetAccount", fmt.Sprintf("%v", req.GetTargetAccount()))
666
667 baseUrl.RawQuery = params.Encode()
668
669 // Build HTTP headers from client and context metadata.
670 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
671 headers := gax.BuildHeaders(ctx, hds...)
672 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
673 if settings.Path != "" {
674 baseUrl.Path = settings.Path
675 }
676 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
677 if err != nil {
678 return err
679 }
680 httpReq.Header = headers
681
682 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLfpStores")
683 if err != nil {
684 return err
685 }
686 if err := unm.Unmarshal(buf, resp); err != nil {
687 return err
688 }
689
690 return nil
691 }, opts...)
692 if e != nil {
693 return nil, "", e
694 }
695 it.Response = resp
696 return resp.GetLfpStores(), resp.GetNextPageToken(), nil
697 }
698
699 fetch := func(pageSize int, pageToken string) (string, error) {
700 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
701 if err != nil {
702 return "", err
703 }
704 it.items = append(it.items, items...)
705 return nextPageToken, nil
706 }
707
708 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
709 it.pageInfo.MaxSize = int(req.GetPageSize())
710 it.pageInfo.Token = req.GetPageToken()
711
712 return it
713 }