Debian Codegraph @

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