Debian Codegraph @

shopping/merchant/accounts/apiv1beta/programs_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 newProgramsClientHook clientHook
43
44 // ProgramsCallOptions contains the retry settings for each method of ProgramsClient.
45 type ProgramsCallOptions struct {
46 GetProgram []gax.CallOption
47 ListPrograms []gax.CallOption
48 EnableProgram []gax.CallOption
49 DisableProgram []gax.CallOption
50 }
51
52 func defaultProgramsGRPCClientOptions() []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 defaultProgramsCallOptions() *ProgramsCallOptions {
68 return &ProgramsCallOptions{
69 GetProgram: []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 ListPrograms: []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 EnableProgram: []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 DisableProgram: []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 defaultProgramsRESTCallOptions() *ProgramsCallOptions {
121 return &ProgramsCallOptions{
122 GetProgram: []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 ListPrograms: []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 EnableProgram: []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 DisableProgram: []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 // internalProgramsClient is an interface that defines the methods available from Merchant API.
170 type internalProgramsClient interface {
171 Close() error
172 setGoogleClientInfo(...string)
173 Connection() *grpc.ClientConn
174 GetProgram(context.Context, *accountspb.GetProgramRequest, ...gax.CallOption) (*accountspb.Program, error)
175 ListPrograms(context.Context, *accountspb.ListProgramsRequest, ...gax.CallOption) *ProgramIterator
176 EnableProgram(context.Context, *accountspb.EnableProgramRequest, ...gax.CallOption) (*accountspb.Program, error)
177 DisableProgram(context.Context, *accountspb.DisableProgramRequest, ...gax.CallOption) (*accountspb.Program, error)
178 }
179
180 // ProgramsClient 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 program management.
184 //
185 // Programs provide a mechanism for adding functionality to merchant accounts. A
186 // typical example of this is the Free product
187 // listings (at https://support.google.com/merchants/topic/9240261?ref_topic=7257954,7259405,&sjid=796648681813264022-EU)
188 // program, which enables products from a merchant’s store to be shown across
189 // Google for free.
190 //
191 // This service exposes methods to retrieve a merchant’s
192 // participation in all available programs, in addition to methods for
193 // explicitly enabling or disabling participation in each program.
194 type ProgramsClient struct {
195 // The internal transport-dependent client.
196 internalClient internalProgramsClient
197
198 // The call options for this service.
199 CallOptions *ProgramsCallOptions
200 }
201
202 // Wrapper methods routed to the internal client.
203
204 // Close closes the connection to the API service. The user should invoke this when
205 // the client is no longer required.
206 func (c *ProgramsClient) Close() error {
207 return c.internalClient.Close()
208 }
209
210 // setGoogleClientInfo sets the name and version of the application in
211 // the `x-goog-api-client` header passed on each request. Intended for
212 // use by Google-written clients.
213 func (c *ProgramsClient) setGoogleClientInfo(keyval ...string) {
214 c.internalClient.setGoogleClientInfo(keyval...)
215 }
216
217 // Connection returns a connection to the API service.
218 //
219 // Deprecated: Connections are now pooled so this method does not always
220 // return the same resource.
221 func (c *ProgramsClient) Connection() *grpc.ClientConn {
222 return c.internalClient.Connection()
223 }
224
225 // GetProgram retrieves the specified program for the account.
226 func (c *ProgramsClient) GetProgram(ctx context.Context, req *accountspb.GetProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
227 return c.internalClient.GetProgram(ctx, req, opts...)
228 }
229
230 // ListPrograms retrieves all programs for the account.
231 func (c *ProgramsClient) ListPrograms(ctx context.Context, req *accountspb.ListProgramsRequest, opts ...gax.CallOption) *ProgramIterator {
232 return c.internalClient.ListPrograms(ctx, req, opts...)
233 }
234
235 // EnableProgram enable participation in the specified program for the account. Executing
236 // this method requires admin access.
237 func (c *ProgramsClient) EnableProgram(ctx context.Context, req *accountspb.EnableProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
238 return c.internalClient.EnableProgram(ctx, req, opts...)
239 }
240
241 // DisableProgram disable participation in the specified program for the account. Executing
242 // this method requires admin access.
243 func (c *ProgramsClient) DisableProgram(ctx context.Context, req *accountspb.DisableProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
244 return c.internalClient.DisableProgram(ctx, req, opts...)
245 }
246
247 // programsGRPCClient is a client for interacting with Merchant API over gRPC transport.
248 //
249 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
250 type programsGRPCClient struct {
251 // Connection pool of gRPC connections to the service.
252 connPool gtransport.ConnPool
253
254 // Points back to the CallOptions field of the containing ProgramsClient
255 CallOptions **ProgramsCallOptions
256
257 // The gRPC API client.
258 programsClient accountspb.ProgramsServiceClient
259
260 // The x-goog-* metadata to be sent with each request.
261 xGoogHeaders []string
262
263 logger *slog.Logger
264 }
265
266 // NewProgramsClient creates a new programs service client based on gRPC.
267 // The returned client must be Closed when it is done being used to clean up its underlying connections.
268 //
269 // Service for program management.
270 //
271 // Programs provide a mechanism for adding functionality to merchant accounts. A
272 // typical example of this is the Free product
273 // listings (at https://support.google.com/merchants/topic/9240261?ref_topic=7257954,7259405,&sjid=796648681813264022-EU)
274 // program, which enables products from a merchant’s store to be shown across
275 // Google for free.
276 //
277 // This service exposes methods to retrieve a merchant’s
278 // participation in all available programs, in addition to methods for
279 // explicitly enabling or disabling participation in each program.
280 func NewProgramsClient(ctx context.Context, opts ...option.ClientOption) (*ProgramsClient, error) {
281 clientOpts := defaultProgramsGRPCClientOptions()
282 if newProgramsClientHook != nil {
283 hookOpts, err := newProgramsClientHook(ctx, clientHookParams{})
284 if err != nil {
285 return nil, err
286 }
287 clientOpts = append(clientOpts, hookOpts...)
288 }
289
290 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
291 if err != nil {
292 return nil, err
293 }
294 client := ProgramsClient{CallOptions: defaultProgramsCallOptions()}
295
296 c := &programsGRPCClient{
297 connPool: connPool,
298 programsClient: accountspb.NewProgramsServiceClient(connPool),
299 CallOptions: &client.CallOptions,
300 logger: internaloption.GetLogger(opts),
301 }
302 c.setGoogleClientInfo()
303
304 client.internalClient = c
305
306 return &client, nil
307 }
308
309 // Connection returns a connection to the API service.
310 //
311 // Deprecated: Connections are now pooled so this method does not always
312 // return the same resource.
313 func (c *programsGRPCClient) Connection() *grpc.ClientConn {
314 return c.connPool.Conn()
315 }
316
317 // setGoogleClientInfo sets the name and version of the application in
318 // the `x-goog-api-client` header passed on each request. Intended for
319 // use by Google-written clients.
320 func (c *programsGRPCClient) setGoogleClientInfo(keyval ...string) {
321 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
322 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
323 c.xGoogHeaders = []string{
324 "x-goog-api-client", gax.XGoogHeader(kv...),
325 }
326 }
327
328 // Close closes the connection to the API service. The user should invoke this when
329 // the client is no longer required.
330 func (c *programsGRPCClient) Close() error {
331 return c.connPool.Close()
332 }
333
334 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
335 type programsRESTClient struct {
336 // The http endpoint to connect to.
337 endpoint string
338
339 // The http client.
340 httpClient *http.Client
341
342 // The x-goog-* headers to be sent with each request.
343 xGoogHeaders []string
344
345 // Points back to the CallOptions field of the containing ProgramsClient
346 CallOptions **ProgramsCallOptions
347
348 logger *slog.Logger
349 }
350
351 // NewProgramsRESTClient creates a new programs service rest client.
352 //
353 // Service for program management.
354 //
355 // Programs provide a mechanism for adding functionality to merchant accounts. A
356 // typical example of this is the Free product
357 // listings (at https://support.google.com/merchants/topic/9240261?ref_topic=7257954,7259405,&sjid=796648681813264022-EU)
358 // program, which enables products from a merchant’s store to be shown across
359 // Google for free.
360 //
361 // This service exposes methods to retrieve a merchant’s
362 // participation in all available programs, in addition to methods for
363 // explicitly enabling or disabling participation in each program.
364 func NewProgramsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ProgramsClient, error) {
365 clientOpts := append(defaultProgramsRESTClientOptions(), opts...)
366 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
367 if err != nil {
368 return nil, err
369 }
370
371 callOpts := defaultProgramsRESTCallOptions()
372 c := &programsRESTClient{
373 endpoint: endpoint,
374 httpClient: httpClient,
375 CallOptions: &callOpts,
376 logger: internaloption.GetLogger(opts),
377 }
378 c.setGoogleClientInfo()
379
380 return &ProgramsClient{internalClient: c, CallOptions: callOpts}, nil
381 }
382
383 func defaultProgramsRESTClientOptions() []option.ClientOption {
384 return []option.ClientOption{
385 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
386 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
387 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
388 internaloption.WithDefaultUniverseDomain("googleapis.com"),
389 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
390 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
391 internaloption.EnableNewAuthLibrary(),
392 }
393 }
394
395 // setGoogleClientInfo sets the name and version of the application in
396 // the `x-goog-api-client` header passed on each request. Intended for
397 // use by Google-written clients.
398 func (c *programsRESTClient) setGoogleClientInfo(keyval ...string) {
399 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
400 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
401 c.xGoogHeaders = []string{
402 "x-goog-api-client", gax.XGoogHeader(kv...),
403 }
404 }
405
406 // Close closes the connection to the API service. The user should invoke this when
407 // the client is no longer required.
408 func (c *programsRESTClient) Close() error {
409 // Replace httpClient with nil to force cleanup.
410 c.httpClient = nil
411 return nil
412 }
413
414 // Connection returns a connection to the API service.
415 //
416 // Deprecated: This method always returns nil.
417 func (c *programsRESTClient) Connection() *grpc.ClientConn {
418 return nil
419 }
420 func (c *programsGRPCClient) GetProgram(ctx context.Context, req *accountspb.GetProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
421 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
422
423 hds = append(c.xGoogHeaders, hds...)
424 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
425 opts = append((*c.CallOptions).GetProgram[0:len((*c.CallOptions).GetProgram):len((*c.CallOptions).GetProgram)], opts...)
426 var resp *accountspb.Program
427 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
428 var err error
429 resp, err = executeRPC(ctx, c.programsClient.GetProgram, req, settings.GRPC, c.logger, "GetProgram")
430 return err
431 }, opts...)
432 if err != nil {
433 return nil, err
434 }
435 return resp, nil
436 }
437
438 func (c *programsGRPCClient) ListPrograms(ctx context.Context, req *accountspb.ListProgramsRequest, opts ...gax.CallOption) *ProgramIterator {
439 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
440
441 hds = append(c.xGoogHeaders, hds...)
442 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
443 opts = append((*c.CallOptions).ListPrograms[0:len((*c.CallOptions).ListPrograms):len((*c.CallOptions).ListPrograms)], opts...)
444 it := &ProgramIterator{}
445 req = proto.Clone(req).(*accountspb.ListProgramsRequest)
446 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Program, string, error) {
447 resp := &accountspb.ListProgramsResponse{}
448 if pageToken != "" {
449 req.PageToken = pageToken
450 }
451 if pageSize > math.MaxInt32 {
452 req.PageSize = math.MaxInt32
453 } else if pageSize != 0 {
454 req.PageSize = int32(pageSize)
455 }
456 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
457 var err error
458 resp, err = executeRPC(ctx, c.programsClient.ListPrograms, req, settings.GRPC, c.logger, "ListPrograms")
459 return err
460 }, opts...)
461 if err != nil {
462 return nil, "", err
463 }
464
465 it.Response = resp
466 return resp.GetPrograms(), resp.GetNextPageToken(), nil
467 }
468 fetch := func(pageSize int, pageToken string) (string, error) {
469 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
470 if err != nil {
471 return "", err
472 }
473 it.items = append(it.items, items...)
474 return nextPageToken, nil
475 }
476
477 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
478 it.pageInfo.MaxSize = int(req.GetPageSize())
479 it.pageInfo.Token = req.GetPageToken()
480
481 return it
482 }
483
484 func (c *programsGRPCClient) EnableProgram(ctx context.Context, req *accountspb.EnableProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
485 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
486
487 hds = append(c.xGoogHeaders, hds...)
488 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
489 opts = append((*c.CallOptions).EnableProgram[0:len((*c.CallOptions).EnableProgram):len((*c.CallOptions).EnableProgram)], opts...)
490 var resp *accountspb.Program
491 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
492 var err error
493 resp, err = executeRPC(ctx, c.programsClient.EnableProgram, req, settings.GRPC, c.logger, "EnableProgram")
494 return err
495 }, opts...)
496 if err != nil {
497 return nil, err
498 }
499 return resp, nil
500 }
501
502 func (c *programsGRPCClient) DisableProgram(ctx context.Context, req *accountspb.DisableProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
503 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
504
505 hds = append(c.xGoogHeaders, hds...)
506 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
507 opts = append((*c.CallOptions).DisableProgram[0:len((*c.CallOptions).DisableProgram):len((*c.CallOptions).DisableProgram)], opts...)
508 var resp *accountspb.Program
509 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
510 var err error
511 resp, err = executeRPC(ctx, c.programsClient.DisableProgram, req, settings.GRPC, c.logger, "DisableProgram")
512 return err
513 }, opts...)
514 if err != nil {
515 return nil, err
516 }
517 return resp, nil
518 }
519
520 // GetProgram retrieves the specified program for the account.
521 func (c *programsRESTClient) GetProgram(ctx context.Context, req *accountspb.GetProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
522 baseUrl, err := url.Parse(c.endpoint)
523 if err != nil {
524 return nil, err
525 }
526 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName())
527
528 params := url.Values{}
529 params.Add("$alt", "json;enum-encoding=int")
530
531 baseUrl.RawQuery = params.Encode()
532
533 // Build HTTP headers from client and context metadata.
534 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
535
536 hds = append(c.xGoogHeaders, hds...)
537 hds = append(hds, "Content-Type", "application/json")
538 headers := gax.BuildHeaders(ctx, hds...)
539 opts = append((*c.CallOptions).GetProgram[0:len((*c.CallOptions).GetProgram):len((*c.CallOptions).GetProgram)], opts...)
540 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
541 resp := &accountspb.Program{}
542 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
543 if settings.Path != "" {
544 baseUrl.Path = settings.Path
545 }
546 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
547 if err != nil {
548 return err
549 }
550 httpReq = httpReq.WithContext(ctx)
551 httpReq.Header = headers
552
553 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetProgram")
554 if err != nil {
555 return err
556 }
557
558 if err := unm.Unmarshal(buf, resp); err != nil {
559 return err
560 }
561
562 return nil
563 }, opts...)
564 if e != nil {
565 return nil, e
566 }
567 return resp, nil
568 }
569
570 // ListPrograms retrieves all programs for the account.
571 func (c *programsRESTClient) ListPrograms(ctx context.Context, req *accountspb.ListProgramsRequest, opts ...gax.CallOption) *ProgramIterator {
572 it := &ProgramIterator{}
573 req = proto.Clone(req).(*accountspb.ListProgramsRequest)
574 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
575 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Program, string, error) {
576 resp := &accountspb.ListProgramsResponse{}
577 if pageToken != "" {
578 req.PageToken = pageToken
579 }
580 if pageSize > math.MaxInt32 {
581 req.PageSize = math.MaxInt32
582 } else if pageSize != 0 {
583 req.PageSize = int32(pageSize)
584 }
585 baseUrl, err := url.Parse(c.endpoint)
586 if err != nil {
587 return nil, "", err
588 }
589 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v/programs", req.GetParent())
590
591 params := url.Values{}
592 params.Add("$alt", "json;enum-encoding=int")
593 if req.GetPageSize() != 0 {
594 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
595 }
596 if req.GetPageToken() != "" {
597 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
598 }
599
600 baseUrl.RawQuery = params.Encode()
601
602 // Build HTTP headers from client and context metadata.
603 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
604 headers := gax.BuildHeaders(ctx, hds...)
605 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
606 if settings.Path != "" {
607 baseUrl.Path = settings.Path
608 }
609 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
610 if err != nil {
611 return err
612 }
613 httpReq.Header = headers
614
615 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListPrograms")
616 if err != nil {
617 return err
618 }
619 if err := unm.Unmarshal(buf, resp); err != nil {
620 return err
621 }
622
623 return nil
624 }, opts...)
625 if e != nil {
626 return nil, "", e
627 }
628 it.Response = resp
629 return resp.GetPrograms(), resp.GetNextPageToken(), nil
630 }
631
632 fetch := func(pageSize int, pageToken string) (string, error) {
633 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
634 if err != nil {
635 return "", err
636 }
637 it.items = append(it.items, items...)
638 return nextPageToken, nil
639 }
640
641 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
642 it.pageInfo.MaxSize = int(req.GetPageSize())
643 it.pageInfo.Token = req.GetPageToken()
644
645 return it
646 }
647
648 // EnableProgram enable participation in the specified program for the account. Executing
649 // this method requires admin access.
650 func (c *programsRESTClient) EnableProgram(ctx context.Context, req *accountspb.EnableProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
651 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
652 jsonReq, err := m.Marshal(req)
653 if err != nil {
654 return nil, err
655 }
656
657 baseUrl, err := url.Parse(c.endpoint)
658 if err != nil {
659 return nil, err
660 }
661 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v:enable", req.GetName())
662
663 params := url.Values{}
664 params.Add("$alt", "json;enum-encoding=int")
665
666 baseUrl.RawQuery = params.Encode()
667
668 // Build HTTP headers from client and context metadata.
669 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
670
671 hds = append(c.xGoogHeaders, hds...)
672 hds = append(hds, "Content-Type", "application/json")
673 headers := gax.BuildHeaders(ctx, hds...)
674 opts = append((*c.CallOptions).EnableProgram[0:len((*c.CallOptions).EnableProgram):len((*c.CallOptions).EnableProgram)], opts...)
675 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
676 resp := &accountspb.Program{}
677 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
678 if settings.Path != "" {
679 baseUrl.Path = settings.Path
680 }
681 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
682 if err != nil {
683 return err
684 }
685 httpReq = httpReq.WithContext(ctx)
686 httpReq.Header = headers
687
688 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "EnableProgram")
689 if err != nil {
690 return err
691 }
692
693 if err := unm.Unmarshal(buf, resp); err != nil {
694 return err
695 }
696
697 return nil
698 }, opts...)
699 if e != nil {
700 return nil, e
701 }
702 return resp, nil
703 }
704
705 // DisableProgram disable participation in the specified program for the account. Executing
706 // this method requires admin access.
707 func (c *programsRESTClient) DisableProgram(ctx context.Context, req *accountspb.DisableProgramRequest, opts ...gax.CallOption) (*accountspb.Program, error) {
708 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
709 jsonReq, err := m.Marshal(req)
710 if err != nil {
711 return nil, err
712 }
713
714 baseUrl, err := url.Parse(c.endpoint)
715 if err != nil {
716 return nil, err
717 }
718 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v:disable", req.GetName())
719
720 params := url.Values{}
721 params.Add("$alt", "json;enum-encoding=int")
722
723 baseUrl.RawQuery = params.Encode()
724
725 // Build HTTP headers from client and context metadata.
726 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
727
728 hds = append(c.xGoogHeaders, hds...)
729 hds = append(hds, "Content-Type", "application/json")
730 headers := gax.BuildHeaders(ctx, hds...)
731 opts = append((*c.CallOptions).DisableProgram[0:len((*c.CallOptions).DisableProgram):len((*c.CallOptions).DisableProgram)], opts...)
732 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
733 resp := &accountspb.Program{}
734 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
735 if settings.Path != "" {
736 baseUrl.Path = settings.Path
737 }
738 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
739 if err != nil {
740 return err
741 }
742 httpReq = httpReq.WithContext(ctx)
743 httpReq.Header = headers
744
745 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "DisableProgram")
746 if err != nil {
747 return err
748 }
749
750 if err := unm.Unmarshal(buf, resp); err != nil {
751 return err
752 }
753
754 return nil
755 }, opts...)
756 if e != nil {
757 return nil, e
758 }
759 return resp, nil
760 }