Debian Codegraph @

shopping/merchant/inventories/apiv1beta/regional_inventory_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 inventories
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 inventoriespb "cloud.google.com/go/shopping/merchant/inventories/apiv1beta/inventoriespb"
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 newRegionalInventoryClientHook clientHook
43
44 // RegionalInventoryCallOptions contains the retry settings for each method of RegionalInventoryClient.
45 type RegionalInventoryCallOptions struct {
46 ListRegionalInventories []gax.CallOption
47 InsertRegionalInventory []gax.CallOption
48 DeleteRegionalInventory []gax.CallOption
49 }
50
51 func defaultRegionalInventoryGRPCClientOptions() []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 defaultRegionalInventoryCallOptions() *RegionalInventoryCallOptions {
67 return &RegionalInventoryCallOptions{
68 ListRegionalInventories: []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 InsertRegionalInventory: []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 DeleteRegionalInventory: []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 defaultRegionalInventoryRESTCallOptions() *RegionalInventoryCallOptions {
108 return &RegionalInventoryCallOptions{
109 ListRegionalInventories: []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 InsertRegionalInventory: []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 DeleteRegionalInventory: []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 // internalRegionalInventoryClient is an interface that defines the methods available from Merchant API.
146 type internalRegionalInventoryClient interface {
147 Close() error
148 setGoogleClientInfo(...string)
149 Connection() *grpc.ClientConn
150 ListRegionalInventories(context.Context, *inventoriespb.ListRegionalInventoriesRequest, ...gax.CallOption) *RegionalInventoryIterator
151 InsertRegionalInventory(context.Context, *inventoriespb.InsertRegionalInventoryRequest, ...gax.CallOption) (*inventoriespb.RegionalInventory, error)
152 DeleteRegionalInventory(context.Context, *inventoriespb.DeleteRegionalInventoryRequest, ...gax.CallOption) error
153 }
154
155 // RegionalInventoryClient 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 regional inventory for products. There is also separate
159 // regions resource and API to manage regions definitions.
160 type RegionalInventoryClient struct {
161 // The internal transport-dependent client.
162 internalClient internalRegionalInventoryClient
163
164 // The call options for this service.
165 CallOptions *RegionalInventoryCallOptions
166 }
167
168 // Wrapper methods routed to the internal client.
169
170 // Close closes the connection to the API service. The user should invoke this when
171 // the client is no longer required.
172 func (c *RegionalInventoryClient) Close() error {
173 return c.internalClient.Close()
174 }
175
176 // setGoogleClientInfo sets the name and version of the application in
177 // the `x-goog-api-client` header passed on each request. Intended for
178 // use by Google-written clients.
179 func (c *RegionalInventoryClient) setGoogleClientInfo(keyval ...string) {
180 c.internalClient.setGoogleClientInfo(keyval...)
181 }
182
183 // Connection returns a connection to the API service.
184 //
185 // Deprecated: Connections are now pooled so this method does not always
186 // return the same resource.
187 func (c *RegionalInventoryClient) Connection() *grpc.ClientConn {
188 return c.internalClient.Connection()
189 }
190
191 // ListRegionalInventories lists the RegionalInventory resources for the given product in your
192 // merchant account. The response might contain fewer items than specified by
193 // pageSize. If pageToken was returned in previous request, it can be
194 // used to obtain additional results.
195 //
196 // RegionalInventory resources are listed per product for a given account.
197 func (c *RegionalInventoryClient) ListRegionalInventories(ctx context.Context, req *inventoriespb.ListRegionalInventoriesRequest, opts ...gax.CallOption) *RegionalInventoryIterator {
198 return c.internalClient.ListRegionalInventories(ctx, req, opts...)
199 }
200
201 // InsertRegionalInventory inserts a RegionalInventory to a given product in your
202 // merchant account.
203 //
204 // Replaces the full RegionalInventory resource if an entry with the same
205 // [region][google.shopping.merchant.inventories.v1beta.RegionalInventory.region]
206 // already exists for the product.
207 //
208 // It might take up to 30 minutes for the new or updated RegionalInventory
209 // resource to appear in products.
210 func (c *RegionalInventoryClient) InsertRegionalInventory(ctx context.Context, req *inventoriespb.InsertRegionalInventoryRequest, opts ...gax.CallOption) (*inventoriespb.RegionalInventory, error) {
211 return c.internalClient.InsertRegionalInventory(ctx, req, opts...)
212 }
213
214 // DeleteRegionalInventory deletes the specified RegionalInventory resource from the given product
215 // in your merchant account. It might take up to an hour for the
216 // RegionalInventory to be deleted from the specific product.
217 // Once you have received a successful delete response, wait for that
218 // period before attempting a delete again.
219 func (c *RegionalInventoryClient) DeleteRegionalInventory(ctx context.Context, req *inventoriespb.DeleteRegionalInventoryRequest, opts ...gax.CallOption) error {
220 return c.internalClient.DeleteRegionalInventory(ctx, req, opts...)
221 }
222
223 // regionalInventoryGRPCClient is a client for interacting with Merchant API over gRPC transport.
224 //
225 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
226 type regionalInventoryGRPCClient struct {
227 // Connection pool of gRPC connections to the service.
228 connPool gtransport.ConnPool
229
230 // Points back to the CallOptions field of the containing RegionalInventoryClient
231 CallOptions **RegionalInventoryCallOptions
232
233 // The gRPC API client.
234 regionalInventoryClient inventoriespb.RegionalInventoryServiceClient
235
236 // The x-goog-* metadata to be sent with each request.
237 xGoogHeaders []string
238
239 logger *slog.Logger
240 }
241
242 // NewRegionalInventoryClient creates a new regional inventory service client based on gRPC.
243 // The returned client must be Closed when it is done being used to clean up its underlying connections.
244 //
245 // Service to manage regional inventory for products. There is also separate
246 // regions resource and API to manage regions definitions.
247 func NewRegionalInventoryClient(ctx context.Context, opts ...option.ClientOption) (*RegionalInventoryClient, error) {
248 clientOpts := defaultRegionalInventoryGRPCClientOptions()
249 if newRegionalInventoryClientHook != nil {
250 hookOpts, err := newRegionalInventoryClientHook(ctx, clientHookParams{})
251 if err != nil {
252 return nil, err
253 }
254 clientOpts = append(clientOpts, hookOpts...)
255 }
256
257 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
258 if err != nil {
259 return nil, err
260 }
261 client := RegionalInventoryClient{CallOptions: defaultRegionalInventoryCallOptions()}
262
263 c := &regionalInventoryGRPCClient{
264 connPool: connPool,
265 regionalInventoryClient: inventoriespb.NewRegionalInventoryServiceClient(connPool),
266 CallOptions: &client.CallOptions,
267 logger: internaloption.GetLogger(opts),
268 }
269 c.setGoogleClientInfo()
270
271 client.internalClient = c
272
273 return &client, nil
274 }
275
276 // Connection returns a connection to the API service.
277 //
278 // Deprecated: Connections are now pooled so this method does not always
279 // return the same resource.
280 func (c *regionalInventoryGRPCClient) Connection() *grpc.ClientConn {
281 return c.connPool.Conn()
282 }
283
284 // setGoogleClientInfo sets the name and version of the application in
285 // the `x-goog-api-client` header passed on each request. Intended for
286 // use by Google-written clients.
287 func (c *regionalInventoryGRPCClient) setGoogleClientInfo(keyval ...string) {
288 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
289 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
290 c.xGoogHeaders = []string{
291 "x-goog-api-client", gax.XGoogHeader(kv...),
292 }
293 }
294
295 // Close closes the connection to the API service. The user should invoke this when
296 // the client is no longer required.
297 func (c *regionalInventoryGRPCClient) Close() error {
298 return c.connPool.Close()
299 }
300
301 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
302 type regionalInventoryRESTClient struct {
303 // The http endpoint to connect to.
304 endpoint string
305
306 // The http client.
307 httpClient *http.Client
308
309 // The x-goog-* headers to be sent with each request.
310 xGoogHeaders []string
311
312 // Points back to the CallOptions field of the containing RegionalInventoryClient
313 CallOptions **RegionalInventoryCallOptions
314
315 logger *slog.Logger
316 }
317
318 // NewRegionalInventoryRESTClient creates a new regional inventory service rest client.
319 //
320 // Service to manage regional inventory for products. There is also separate
321 // regions resource and API to manage regions definitions.
322 func NewRegionalInventoryRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionalInventoryClient, error) {
323 clientOpts := append(defaultRegionalInventoryRESTClientOptions(), opts...)
324 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
325 if err != nil {
326 return nil, err
327 }
328
329 callOpts := defaultRegionalInventoryRESTCallOptions()
330 c := &regionalInventoryRESTClient{
331 endpoint: endpoint,
332 httpClient: httpClient,
333 CallOptions: &callOpts,
334 logger: internaloption.GetLogger(opts),
335 }
336 c.setGoogleClientInfo()
337
338 return &RegionalInventoryClient{internalClient: c, CallOptions: callOpts}, nil
339 }
340
341 func defaultRegionalInventoryRESTClientOptions() []option.ClientOption {
342 return []option.ClientOption{
343 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
344 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
345 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
346 internaloption.WithDefaultUniverseDomain("googleapis.com"),
347 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
348 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
349 internaloption.EnableNewAuthLibrary(),
350 }
351 }
352
353 // setGoogleClientInfo sets the name and version of the application in
354 // the `x-goog-api-client` header passed on each request. Intended for
355 // use by Google-written clients.
356 func (c *regionalInventoryRESTClient) setGoogleClientInfo(keyval ...string) {
357 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
358 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
359 c.xGoogHeaders = []string{
360 "x-goog-api-client", gax.XGoogHeader(kv...),
361 }
362 }
363
364 // Close closes the connection to the API service. The user should invoke this when
365 // the client is no longer required.
366 func (c *regionalInventoryRESTClient) Close() error {
367 // Replace httpClient with nil to force cleanup.
368 c.httpClient = nil
369 return nil
370 }
371
372 // Connection returns a connection to the API service.
373 //
374 // Deprecated: This method always returns nil.
375 func (c *regionalInventoryRESTClient) Connection() *grpc.ClientConn {
376 return nil
377 }
378 func (c *regionalInventoryGRPCClient) ListRegionalInventories(ctx context.Context, req *inventoriespb.ListRegionalInventoriesRequest, opts ...gax.CallOption) *RegionalInventoryIterator {
379 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
380
381 hds = append(c.xGoogHeaders, hds...)
382 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
383 opts = append((*c.CallOptions).ListRegionalInventories[0:len((*c.CallOptions).ListRegionalInventories):len((*c.CallOptions).ListRegionalInventories)], opts...)
384 it := &RegionalInventoryIterator{}
385 req = proto.Clone(req).(*inventoriespb.ListRegionalInventoriesRequest)
386 it.InternalFetch = func(pageSize int, pageToken string) ([]*inventoriespb.RegionalInventory, string, error) {
387 resp := &inventoriespb.ListRegionalInventoriesResponse{}
388 if pageToken != "" {
389 req.PageToken = pageToken
390 }
391 if pageSize > math.MaxInt32 {
392 req.PageSize = math.MaxInt32
393 } else if pageSize != 0 {
394 req.PageSize = int32(pageSize)
395 }
396 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
397 var err error
398 resp, err = executeRPC(ctx, c.regionalInventoryClient.ListRegionalInventories, req, settings.GRPC, c.logger, "ListRegionalInventories")
399 return err
400 }, opts...)
401 if err != nil {
402 return nil, "", err
403 }
404
405 it.Response = resp
406 return resp.GetRegionalInventories(), resp.GetNextPageToken(), nil
407 }
408 fetch := func(pageSize int, pageToken string) (string, error) {
409 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
410 if err != nil {
411 return "", err
412 }
413 it.items = append(it.items, items...)
414 return nextPageToken, nil
415 }
416
417 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
418 it.pageInfo.MaxSize = int(req.GetPageSize())
419 it.pageInfo.Token = req.GetPageToken()
420
421 return it
422 }
423
424 func (c *regionalInventoryGRPCClient) InsertRegionalInventory(ctx context.Context, req *inventoriespb.InsertRegionalInventoryRequest, opts ...gax.CallOption) (*inventoriespb.RegionalInventory, error) {
425 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
426
427 hds = append(c.xGoogHeaders, hds...)
428 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
429 opts = append((*c.CallOptions).InsertRegionalInventory[0:len((*c.CallOptions).InsertRegionalInventory):len((*c.CallOptions).InsertRegionalInventory)], opts...)
430 var resp *inventoriespb.RegionalInventory
431 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
432 var err error
433 resp, err = executeRPC(ctx, c.regionalInventoryClient.InsertRegionalInventory, req, settings.GRPC, c.logger, "InsertRegionalInventory")
434 return err
435 }, opts...)
436 if err != nil {
437 return nil, err
438 }
439 return resp, nil
440 }
441
442 func (c *regionalInventoryGRPCClient) DeleteRegionalInventory(ctx context.Context, req *inventoriespb.DeleteRegionalInventoryRequest, opts ...gax.CallOption) error {
443 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
444
445 hds = append(c.xGoogHeaders, hds...)
446 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
447 opts = append((*c.CallOptions).DeleteRegionalInventory[0:len((*c.CallOptions).DeleteRegionalInventory):len((*c.CallOptions).DeleteRegionalInventory)], opts...)
448 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
449 var err error
450 _, err = executeRPC(ctx, c.regionalInventoryClient.DeleteRegionalInventory, req, settings.GRPC, c.logger, "DeleteRegionalInventory")
451 return err
452 }, opts...)
453 return err
454 }
455
456 // ListRegionalInventories lists the RegionalInventory resources for the given product in your
457 // merchant account. The response might contain fewer items than specified by
458 // pageSize. If pageToken was returned in previous request, it can be
459 // used to obtain additional results.
460 //
461 // RegionalInventory resources are listed per product for a given account.
462 func (c *regionalInventoryRESTClient) ListRegionalInventories(ctx context.Context, req *inventoriespb.ListRegionalInventoriesRequest, opts ...gax.CallOption) *RegionalInventoryIterator {
463 it := &RegionalInventoryIterator{}
464 req = proto.Clone(req).(*inventoriespb.ListRegionalInventoriesRequest)
465 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
466 it.InternalFetch = func(pageSize int, pageToken string) ([]*inventoriespb.RegionalInventory, string, error) {
467 resp := &inventoriespb.ListRegionalInventoriesResponse{}
468 if pageToken != "" {
469 req.PageToken = pageToken
470 }
471 if pageSize > math.MaxInt32 {
472 req.PageSize = math.MaxInt32
473 } else if pageSize != 0 {
474 req.PageSize = int32(pageSize)
475 }
476 baseUrl, err := url.Parse(c.endpoint)
477 if err != nil {
478 return nil, "", err
479 }
480 baseUrl.Path += fmt.Sprintf("/inventories/v1beta/%v/regionalInventories", req.GetParent())
481
482 params := url.Values{}
483 params.Add("$alt", "json;enum-encoding=int")
484 if req.GetPageSize() != 0 {
485 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
486 }
487 if req.GetPageToken() != "" {
488 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
489 }
490
491 baseUrl.RawQuery = params.Encode()
492
493 // Build HTTP headers from client and context metadata.
494 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
495 headers := gax.BuildHeaders(ctx, hds...)
496 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
497 if settings.Path != "" {
498 baseUrl.Path = settings.Path
499 }
500 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
501 if err != nil {
502 return err
503 }
504 httpReq.Header = headers
505
506 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListRegionalInventories")
507 if err != nil {
508 return err
509 }
510 if err := unm.Unmarshal(buf, resp); err != nil {
511 return err
512 }
513
514 return nil
515 }, opts...)
516 if e != nil {
517 return nil, "", e
518 }
519 it.Response = resp
520 return resp.GetRegionalInventories(), resp.GetNextPageToken(), nil
521 }
522
523 fetch := func(pageSize int, pageToken string) (string, error) {
524 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
525 if err != nil {
526 return "", err
527 }
528 it.items = append(it.items, items...)
529 return nextPageToken, nil
530 }
531
532 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
533 it.pageInfo.MaxSize = int(req.GetPageSize())
534 it.pageInfo.Token = req.GetPageToken()
535
536 return it
537 }
538
539 // InsertRegionalInventory inserts a RegionalInventory to a given product in your
540 // merchant account.
541 //
542 // Replaces the full RegionalInventory resource if an entry with the same
543 // [region][google.shopping.merchant.inventories.v1beta.RegionalInventory.region]
544 // already exists for the product.
545 //
546 // It might take up to 30 minutes for the new or updated RegionalInventory
547 // resource to appear in products.
548 func (c *regionalInventoryRESTClient) InsertRegionalInventory(ctx context.Context, req *inventoriespb.InsertRegionalInventoryRequest, opts ...gax.CallOption) (*inventoriespb.RegionalInventory, error) {
549 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
550 body := req.GetRegionalInventory()
551 jsonReq, err := m.Marshal(body)
552 if err != nil {
553 return nil, err
554 }
555
556 baseUrl, err := url.Parse(c.endpoint)
557 if err != nil {
558 return nil, err
559 }
560 baseUrl.Path += fmt.Sprintf("/inventories/v1beta/%v/regionalInventories:insert", req.GetParent())
561
562 params := url.Values{}
563 params.Add("$alt", "json;enum-encoding=int")
564
565 baseUrl.RawQuery = params.Encode()
566
567 // Build HTTP headers from client and context metadata.
568 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
569
570 hds = append(c.xGoogHeaders, hds...)
571 hds = append(hds, "Content-Type", "application/json")
572 headers := gax.BuildHeaders(ctx, hds...)
573 opts = append((*c.CallOptions).InsertRegionalInventory[0:len((*c.CallOptions).InsertRegionalInventory):len((*c.CallOptions).InsertRegionalInventory)], opts...)
574 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
575 resp := &inventoriespb.RegionalInventory{}
576 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
577 if settings.Path != "" {
578 baseUrl.Path = settings.Path
579 }
580 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
581 if err != nil {
582 return err
583 }
584 httpReq = httpReq.WithContext(ctx)
585 httpReq.Header = headers
586
587 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "InsertRegionalInventory")
588 if err != nil {
589 return err
590 }
591
592 if err := unm.Unmarshal(buf, resp); err != nil {
593 return err
594 }
595
596 return nil
597 }, opts...)
598 if e != nil {
599 return nil, e
600 }
601 return resp, nil
602 }
603
604 // DeleteRegionalInventory deletes the specified RegionalInventory resource from the given product
605 // in your merchant account. It might take up to an hour for the
606 // RegionalInventory to be deleted from the specific product.
607 // Once you have received a successful delete response, wait for that
608 // period before attempting a delete again.
609 func (c *regionalInventoryRESTClient) DeleteRegionalInventory(ctx context.Context, req *inventoriespb.DeleteRegionalInventoryRequest, opts ...gax.CallOption) error {
610 baseUrl, err := url.Parse(c.endpoint)
611 if err != nil {
612 return err
613 }
614 baseUrl.Path += fmt.Sprintf("/inventories/v1beta/%v", req.GetName())
615
616 params := url.Values{}
617 params.Add("$alt", "json;enum-encoding=int")
618
619 baseUrl.RawQuery = params.Encode()
620
621 // Build HTTP headers from client and context metadata.
622 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
623
624 hds = append(c.xGoogHeaders, hds...)
625 hds = append(hds, "Content-Type", "application/json")
626 headers := gax.BuildHeaders(ctx, hds...)
627 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
628 if settings.Path != "" {
629 baseUrl.Path = settings.Path
630 }
631 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
632 if err != nil {
633 return err
634 }
635 httpReq = httpReq.WithContext(ctx)
636 httpReq.Header = headers
637
638 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteRegionalInventory")
639 return err
640 }, opts...)
641 }