Debian Codegraph @

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