Debian Codegraph @

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