Debian Codegraph @

shopping/merchant/accounts/apiv1/omnichannel_settings_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 newOmnichannelSettingsClientHook clientHook
43
44 // OmnichannelSettingsCallOptions contains the retry settings for each method of OmnichannelSettingsClient.
45 type OmnichannelSettingsCallOptions struct {
46 GetOmnichannelSetting []gax.CallOption
47 ListOmnichannelSettings []gax.CallOption
48 CreateOmnichannelSetting []gax.CallOption
49 UpdateOmnichannelSetting []gax.CallOption
50 RequestInventoryVerification []gax.CallOption
51 }
52
53 func defaultOmnichannelSettingsGRPCClientOptions() []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 defaultOmnichannelSettingsCallOptions() *OmnichannelSettingsCallOptions {
69 return &OmnichannelSettingsCallOptions{
70 GetOmnichannelSetting: []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 ListOmnichannelSettings: []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 CreateOmnichannelSetting: []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 UpdateOmnichannelSetting: []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 RequestInventoryVerification: []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 defaultOmnichannelSettingsRESTCallOptions() *OmnichannelSettingsCallOptions {
134 return &OmnichannelSettingsCallOptions{
135 GetOmnichannelSetting: []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 ListOmnichannelSettings: []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 CreateOmnichannelSetting: []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 UpdateOmnichannelSetting: []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 RequestInventoryVerification: []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 // internalOmnichannelSettingsClient is an interface that defines the methods available from Merchant API.
194 type internalOmnichannelSettingsClient interface {
195 Close() error
196 setGoogleClientInfo(...string)
197 Connection() *grpc.ClientConn
198 GetOmnichannelSetting(context.Context, *accountspb.GetOmnichannelSettingRequest, ...gax.CallOption) (*accountspb.OmnichannelSetting, error)
199 ListOmnichannelSettings(context.Context, *accountspb.ListOmnichannelSettingsRequest, ...gax.CallOption) *OmnichannelSettingIterator
200 CreateOmnichannelSetting(context.Context, *accountspb.CreateOmnichannelSettingRequest, ...gax.CallOption) (*accountspb.OmnichannelSetting, error)
201 UpdateOmnichannelSetting(context.Context, *accountspb.UpdateOmnichannelSettingRequest, ...gax.CallOption) (*accountspb.OmnichannelSetting, error)
202 RequestInventoryVerification(context.Context, *accountspb.RequestInventoryVerificationRequest, ...gax.CallOption) (*accountspb.RequestInventoryVerificationResponse, error)
203 }
204
205 // OmnichannelSettingsClient 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 // The service facilitates the management of a merchant’s omnichannel settings.
209 //
210 // This API defines the following resource model:OmnichannelSetting
211 type OmnichannelSettingsClient struct {
212 // The internal transport-dependent client.
213 internalClient internalOmnichannelSettingsClient
214
215 // The call options for this service.
216 CallOptions *OmnichannelSettingsCallOptions
217 }
218
219 // Wrapper methods routed to the internal client.
220
221 // Close closes the connection to the API service. The user should invoke this when
222 // the client is no longer required.
223 func (c *OmnichannelSettingsClient) Close() error {
224 return c.internalClient.Close()
225 }
226
227 // setGoogleClientInfo sets the name and version of the application in
228 // the `x-goog-api-client` header passed on each request. Intended for
229 // use by Google-written clients.
230 func (c *OmnichannelSettingsClient) setGoogleClientInfo(keyval ...string) {
231 c.internalClient.setGoogleClientInfo(keyval...)
232 }
233
234 // Connection returns a connection to the API service.
235 //
236 // Deprecated: Connections are now pooled so this method does not always
237 // return the same resource.
238 func (c *OmnichannelSettingsClient) Connection() *grpc.ClientConn {
239 return c.internalClient.Connection()
240 }
241
242 // GetOmnichannelSetting get the omnichannel settings for a given merchant.
243 func (c *OmnichannelSettingsClient) GetOmnichannelSetting(ctx context.Context, req *accountspb.GetOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
244 return c.internalClient.GetOmnichannelSetting(ctx, req, opts...)
245 }
246
247 // ListOmnichannelSettings list all the omnichannel settings for a given merchant.
248 func (c *OmnichannelSettingsClient) ListOmnichannelSettings(ctx context.Context, req *accountspb.ListOmnichannelSettingsRequest, opts ...gax.CallOption) *OmnichannelSettingIterator {
249 return c.internalClient.ListOmnichannelSettings(ctx, req, opts...)
250 }
251
252 // CreateOmnichannelSetting create the omnichannel settings for a given merchant.
253 func (c *OmnichannelSettingsClient) CreateOmnichannelSetting(ctx context.Context, req *accountspb.CreateOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
254 return c.internalClient.CreateOmnichannelSetting(ctx, req, opts...)
255 }
256
257 // UpdateOmnichannelSetting update the omnichannel setting for a given merchant in a given country.
258 func (c *OmnichannelSettingsClient) UpdateOmnichannelSetting(ctx context.Context, req *accountspb.UpdateOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
259 return c.internalClient.UpdateOmnichannelSetting(ctx, req, opts...)
260 }
261
262 // RequestInventoryVerification requests inventory verification for a given merchant in a given country.
263 func (c *OmnichannelSettingsClient) RequestInventoryVerification(ctx context.Context, req *accountspb.RequestInventoryVerificationRequest, opts ...gax.CallOption) (*accountspb.RequestInventoryVerificationResponse, error) {
264 return c.internalClient.RequestInventoryVerification(ctx, req, opts...)
265 }
266
267 // omnichannelSettingsGRPCClient is a client for interacting with Merchant API over gRPC transport.
268 //
269 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
270 type omnichannelSettingsGRPCClient struct {
271 // Connection pool of gRPC connections to the service.
272 connPool gtransport.ConnPool
273
274 // Points back to the CallOptions field of the containing OmnichannelSettingsClient
275 CallOptions **OmnichannelSettingsCallOptions
276
277 // The gRPC API client.
278 omnichannelSettingsClient accountspb.OmnichannelSettingsServiceClient
279
280 // The x-goog-* metadata to be sent with each request.
281 xGoogHeaders []string
282
283 logger *slog.Logger
284 }
285
286 // NewOmnichannelSettingsClient creates a new omnichannel settings service client based on gRPC.
287 // The returned client must be Closed when it is done being used to clean up its underlying connections.
288 //
289 // The service facilitates the management of a merchant’s omnichannel settings.
290 //
291 // This API defines the following resource model:OmnichannelSetting
292 func NewOmnichannelSettingsClient(ctx context.Context, opts ...option.ClientOption) (*OmnichannelSettingsClient, error) {
293 clientOpts := defaultOmnichannelSettingsGRPCClientOptions()
294 if newOmnichannelSettingsClientHook != nil {
295 hookOpts, err := newOmnichannelSettingsClientHook(ctx, clientHookParams{})
296 if err != nil {
297 return nil, err
298 }
299 clientOpts = append(clientOpts, hookOpts...)
300 }
301
302 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
303 if err != nil {
304 return nil, err
305 }
306 client := OmnichannelSettingsClient{CallOptions: defaultOmnichannelSettingsCallOptions()}
307
308 c := &omnichannelSettingsGRPCClient{
309 connPool: connPool,
310 omnichannelSettingsClient: accountspb.NewOmnichannelSettingsServiceClient(connPool),
311 CallOptions: &client.CallOptions,
312 logger: internaloption.GetLogger(opts),
313 }
314 c.setGoogleClientInfo()
315
316 client.internalClient = c
317
318 return &client, nil
319 }
320
321 // Connection returns a connection to the API service.
322 //
323 // Deprecated: Connections are now pooled so this method does not always
324 // return the same resource.
325 func (c *omnichannelSettingsGRPCClient) Connection() *grpc.ClientConn {
326 return c.connPool.Conn()
327 }
328
329 // setGoogleClientInfo sets the name and version of the application in
330 // the `x-goog-api-client` header passed on each request. Intended for
331 // use by Google-written clients.
332 func (c *omnichannelSettingsGRPCClient) setGoogleClientInfo(keyval ...string) {
333 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
334 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
335 c.xGoogHeaders = []string{
336 "x-goog-api-client", gax.XGoogHeader(kv...),
337 }
338 }
339
340 // Close closes the connection to the API service. The user should invoke this when
341 // the client is no longer required.
342 func (c *omnichannelSettingsGRPCClient) Close() error {
343 return c.connPool.Close()
344 }
345
346 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
347 type omnichannelSettingsRESTClient struct {
348 // The http endpoint to connect to.
349 endpoint string
350
351 // The http client.
352 httpClient *http.Client
353
354 // The x-goog-* headers to be sent with each request.
355 xGoogHeaders []string
356
357 // Points back to the CallOptions field of the containing OmnichannelSettingsClient
358 CallOptions **OmnichannelSettingsCallOptions
359
360 logger *slog.Logger
361 }
362
363 // NewOmnichannelSettingsRESTClient creates a new omnichannel settings service rest client.
364 //
365 // The service facilitates the management of a merchant’s omnichannel settings.
366 //
367 // This API defines the following resource model:OmnichannelSetting
368 func NewOmnichannelSettingsRESTClient(ctx context.Context, opts ...option.ClientOption) (*OmnichannelSettingsClient, error) {
369 clientOpts := append(defaultOmnichannelSettingsRESTClientOptions(), opts...)
370 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
371 if err != nil {
372 return nil, err
373 }
374
375 callOpts := defaultOmnichannelSettingsRESTCallOptions()
376 c := &omnichannelSettingsRESTClient{
377 endpoint: endpoint,
378 httpClient: httpClient,
379 CallOptions: &callOpts,
380 logger: internaloption.GetLogger(opts),
381 }
382 c.setGoogleClientInfo()
383
384 return &OmnichannelSettingsClient{internalClient: c, CallOptions: callOpts}, nil
385 }
386
387 func defaultOmnichannelSettingsRESTClientOptions() []option.ClientOption {
388 return []option.ClientOption{
389 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
390 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
391 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
392 internaloption.WithDefaultUniverseDomain("googleapis.com"),
393 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
394 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
395 internaloption.EnableNewAuthLibrary(),
396 }
397 }
398
399 // setGoogleClientInfo sets the name and version of the application in
400 // the `x-goog-api-client` header passed on each request. Intended for
401 // use by Google-written clients.
402 func (c *omnichannelSettingsRESTClient) setGoogleClientInfo(keyval ...string) {
403 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
404 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
405 c.xGoogHeaders = []string{
406 "x-goog-api-client", gax.XGoogHeader(kv...),
407 }
408 }
409
410 // Close closes the connection to the API service. The user should invoke this when
411 // the client is no longer required.
412 func (c *omnichannelSettingsRESTClient) Close() error {
413 // Replace httpClient with nil to force cleanup.
414 c.httpClient = nil
415 return nil
416 }
417
418 // Connection returns a connection to the API service.
419 //
420 // Deprecated: This method always returns nil.
421 func (c *omnichannelSettingsRESTClient) Connection() *grpc.ClientConn {
422 return nil
423 }
424 func (c *omnichannelSettingsGRPCClient) GetOmnichannelSetting(ctx context.Context, req *accountspb.GetOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
425 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
426
427 hds = append(c.xGoogHeaders, hds...)
428 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
429 opts = append((*c.CallOptions).GetOmnichannelSetting[0:len((*c.CallOptions).GetOmnichannelSetting):len((*c.CallOptions).GetOmnichannelSetting)], opts...)
430 var resp *accountspb.OmnichannelSetting
431 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
432 var err error
433 resp, err = executeRPC(ctx, c.omnichannelSettingsClient.GetOmnichannelSetting, req, settings.GRPC, c.logger, "GetOmnichannelSetting")
434 return err
435 }, opts...)
436 if err != nil {
437 return nil, err
438 }
439 return resp, nil
440 }
441
442 func (c *omnichannelSettingsGRPCClient) ListOmnichannelSettings(ctx context.Context, req *accountspb.ListOmnichannelSettingsRequest, opts ...gax.CallOption) *OmnichannelSettingIterator {
443 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
444
445 hds = append(c.xGoogHeaders, hds...)
446 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
447 opts = append((*c.CallOptions).ListOmnichannelSettings[0:len((*c.CallOptions).ListOmnichannelSettings):len((*c.CallOptions).ListOmnichannelSettings)], opts...)
448 it := &OmnichannelSettingIterator{}
449 req = proto.Clone(req).(*accountspb.ListOmnichannelSettingsRequest)
450 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.OmnichannelSetting, string, error) {
451 resp := &accountspb.ListOmnichannelSettingsResponse{}
452 if pageToken != "" {
453 req.PageToken = pageToken
454 }
455 if pageSize > math.MaxInt32 {
456 req.PageSize = math.MaxInt32
457 } else if pageSize != 0 {
458 req.PageSize = int32(pageSize)
459 }
460 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
461 var err error
462 resp, err = executeRPC(ctx, c.omnichannelSettingsClient.ListOmnichannelSettings, req, settings.GRPC, c.logger, "ListOmnichannelSettings")
463 return err
464 }, opts...)
465 if err != nil {
466 return nil, "", err
467 }
468
469 it.Response = resp
470 return resp.GetOmnichannelSettings(), resp.GetNextPageToken(), nil
471 }
472 fetch := func(pageSize int, pageToken string) (string, error) {
473 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
474 if err != nil {
475 return "", err
476 }
477 it.items = append(it.items, items...)
478 return nextPageToken, nil
479 }
480
481 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
482 it.pageInfo.MaxSize = int(req.GetPageSize())
483 it.pageInfo.Token = req.GetPageToken()
484
485 return it
486 }
487
488 func (c *omnichannelSettingsGRPCClient) CreateOmnichannelSetting(ctx context.Context, req *accountspb.CreateOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
489 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
490
491 hds = append(c.xGoogHeaders, hds...)
492 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
493 opts = append((*c.CallOptions).CreateOmnichannelSetting[0:len((*c.CallOptions).CreateOmnichannelSetting):len((*c.CallOptions).CreateOmnichannelSetting)], opts...)
494 var resp *accountspb.OmnichannelSetting
495 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
496 var err error
497 resp, err = executeRPC(ctx, c.omnichannelSettingsClient.CreateOmnichannelSetting, req, settings.GRPC, c.logger, "CreateOmnichannelSetting")
498 return err
499 }, opts...)
500 if err != nil {
501 return nil, err
502 }
503 return resp, nil
504 }
505
506 func (c *omnichannelSettingsGRPCClient) UpdateOmnichannelSetting(ctx context.Context, req *accountspb.UpdateOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
507 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "omnichannel_setting.name", url.QueryEscape(req.GetOmnichannelSetting().GetName()))}
508
509 hds = append(c.xGoogHeaders, hds...)
510 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
511 opts = append((*c.CallOptions).UpdateOmnichannelSetting[0:len((*c.CallOptions).UpdateOmnichannelSetting):len((*c.CallOptions).UpdateOmnichannelSetting)], opts...)
512 var resp *accountspb.OmnichannelSetting
513 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
514 var err error
515 resp, err = executeRPC(ctx, c.omnichannelSettingsClient.UpdateOmnichannelSetting, req, settings.GRPC, c.logger, "UpdateOmnichannelSetting")
516 return err
517 }, opts...)
518 if err != nil {
519 return nil, err
520 }
521 return resp, nil
522 }
523
524 func (c *omnichannelSettingsGRPCClient) RequestInventoryVerification(ctx context.Context, req *accountspb.RequestInventoryVerificationRequest, opts ...gax.CallOption) (*accountspb.RequestInventoryVerificationResponse, error) {
525 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
526
527 hds = append(c.xGoogHeaders, hds...)
528 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
529 opts = append((*c.CallOptions).RequestInventoryVerification[0:len((*c.CallOptions).RequestInventoryVerification):len((*c.CallOptions).RequestInventoryVerification)], opts...)
530 var resp *accountspb.RequestInventoryVerificationResponse
531 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
532 var err error
533 resp, err = executeRPC(ctx, c.omnichannelSettingsClient.RequestInventoryVerification, req, settings.GRPC, c.logger, "RequestInventoryVerification")
534 return err
535 }, opts...)
536 if err != nil {
537 return nil, err
538 }
539 return resp, nil
540 }
541
542 // GetOmnichannelSetting get the omnichannel settings for a given merchant.
543 func (c *omnichannelSettingsRESTClient) GetOmnichannelSetting(ctx context.Context, req *accountspb.GetOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
544 baseUrl, err := url.Parse(c.endpoint)
545 if err != nil {
546 return nil, err
547 }
548 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetName())
549
550 params := url.Values{}
551 params.Add("$alt", "json;enum-encoding=int")
552
553 baseUrl.RawQuery = params.Encode()
554
555 // Build HTTP headers from client and context metadata.
556 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
557
558 hds = append(c.xGoogHeaders, hds...)
559 hds = append(hds, "Content-Type", "application/json")
560 headers := gax.BuildHeaders(ctx, hds...)
561 opts = append((*c.CallOptions).GetOmnichannelSetting[0:len((*c.CallOptions).GetOmnichannelSetting):len((*c.CallOptions).GetOmnichannelSetting)], opts...)
562 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
563 resp := &accountspb.OmnichannelSetting{}
564 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
565 if settings.Path != "" {
566 baseUrl.Path = settings.Path
567 }
568 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
569 if err != nil {
570 return err
571 }
572 httpReq = httpReq.WithContext(ctx)
573 httpReq.Header = headers
574
575 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOmnichannelSetting")
576 if err != nil {
577 return err
578 }
579
580 if err := unm.Unmarshal(buf, resp); err != nil {
581 return err
582 }
583
584 return nil
585 }, opts...)
586 if e != nil {
587 return nil, e
588 }
589 return resp, nil
590 }
591
592 // ListOmnichannelSettings list all the omnichannel settings for a given merchant.
593 func (c *omnichannelSettingsRESTClient) ListOmnichannelSettings(ctx context.Context, req *accountspb.ListOmnichannelSettingsRequest, opts ...gax.CallOption) *OmnichannelSettingIterator {
594 it := &OmnichannelSettingIterator{}
595 req = proto.Clone(req).(*accountspb.ListOmnichannelSettingsRequest)
596 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
597 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.OmnichannelSetting, string, error) {
598 resp := &accountspb.ListOmnichannelSettingsResponse{}
599 if pageToken != "" {
600 req.PageToken = pageToken
601 }
602 if pageSize > math.MaxInt32 {
603 req.PageSize = math.MaxInt32
604 } else if pageSize != 0 {
605 req.PageSize = int32(pageSize)
606 }
607 baseUrl, err := url.Parse(c.endpoint)
608 if err != nil {
609 return nil, "", err
610 }
611 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/omnichannelSettings", req.GetParent())
612
613 params := url.Values{}
614 params.Add("$alt", "json;enum-encoding=int")
615 if req.GetPageSize() != 0 {
616 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
617 }
618 if req.GetPageToken() != "" {
619 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
620 }
621
622 baseUrl.RawQuery = params.Encode()
623
624 // Build HTTP headers from client and context metadata.
625 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
626 headers := gax.BuildHeaders(ctx, hds...)
627 e := 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("GET", baseUrl.String(), nil)
632 if err != nil {
633 return err
634 }
635 httpReq.Header = headers
636
637 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOmnichannelSettings")
638 if err != nil {
639 return err
640 }
641 if err := unm.Unmarshal(buf, resp); err != nil {
642 return err
643 }
644
645 return nil
646 }, opts...)
647 if e != nil {
648 return nil, "", e
649 }
650 it.Response = resp
651 return resp.GetOmnichannelSettings(), resp.GetNextPageToken(), nil
652 }
653
654 fetch := func(pageSize int, pageToken string) (string, error) {
655 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
656 if err != nil {
657 return "", err
658 }
659 it.items = append(it.items, items...)
660 return nextPageToken, nil
661 }
662
663 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
664 it.pageInfo.MaxSize = int(req.GetPageSize())
665 it.pageInfo.Token = req.GetPageToken()
666
667 return it
668 }
669
670 // CreateOmnichannelSetting create the omnichannel settings for a given merchant.
671 func (c *omnichannelSettingsRESTClient) CreateOmnichannelSetting(ctx context.Context, req *accountspb.CreateOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
672 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
673 body := req.GetOmnichannelSetting()
674 jsonReq, err := m.Marshal(body)
675 if err != nil {
676 return nil, err
677 }
678
679 baseUrl, err := url.Parse(c.endpoint)
680 if err != nil {
681 return nil, err
682 }
683 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/omnichannelSettings", req.GetParent())
684
685 params := url.Values{}
686 params.Add("$alt", "json;enum-encoding=int")
687
688 baseUrl.RawQuery = params.Encode()
689
690 // Build HTTP headers from client and context metadata.
691 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
692
693 hds = append(c.xGoogHeaders, hds...)
694 hds = append(hds, "Content-Type", "application/json")
695 headers := gax.BuildHeaders(ctx, hds...)
696 opts = append((*c.CallOptions).CreateOmnichannelSetting[0:len((*c.CallOptions).CreateOmnichannelSetting):len((*c.CallOptions).CreateOmnichannelSetting)], opts...)
697 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
698 resp := &accountspb.OmnichannelSetting{}
699 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
700 if settings.Path != "" {
701 baseUrl.Path = settings.Path
702 }
703 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
704 if err != nil {
705 return err
706 }
707 httpReq = httpReq.WithContext(ctx)
708 httpReq.Header = headers
709
710 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateOmnichannelSetting")
711 if err != nil {
712 return err
713 }
714
715 if err := unm.Unmarshal(buf, resp); err != nil {
716 return err
717 }
718
719 return nil
720 }, opts...)
721 if e != nil {
722 return nil, e
723 }
724 return resp, nil
725 }
726
727 // UpdateOmnichannelSetting update the omnichannel setting for a given merchant in a given country.
728 func (c *omnichannelSettingsRESTClient) UpdateOmnichannelSetting(ctx context.Context, req *accountspb.UpdateOmnichannelSettingRequest, opts ...gax.CallOption) (*accountspb.OmnichannelSetting, error) {
729 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
730 body := req.GetOmnichannelSetting()
731 jsonReq, err := m.Marshal(body)
732 if err != nil {
733 return nil, err
734 }
735
736 baseUrl, err := url.Parse(c.endpoint)
737 if err != nil {
738 return nil, err
739 }
740 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetOmnichannelSetting().GetName())
741
742 params := url.Values{}
743 params.Add("$alt", "json;enum-encoding=int")
744 if req.GetUpdateMask() != nil {
745 field, err := protojson.Marshal(req.GetUpdateMask())
746 if err != nil {
747 return nil, err
748 }
749 params.Add("updateMask", string(field[1:len(field)-1]))
750 }
751
752 baseUrl.RawQuery = params.Encode()
753
754 // Build HTTP headers from client and context metadata.
755 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "omnichannel_setting.name", url.QueryEscape(req.GetOmnichannelSetting().GetName()))}
756
757 hds = append(c.xGoogHeaders, hds...)
758 hds = append(hds, "Content-Type", "application/json")
759 headers := gax.BuildHeaders(ctx, hds...)
760 opts = append((*c.CallOptions).UpdateOmnichannelSetting[0:len((*c.CallOptions).UpdateOmnichannelSetting):len((*c.CallOptions).UpdateOmnichannelSetting)], opts...)
761 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
762 resp := &accountspb.OmnichannelSetting{}
763 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
764 if settings.Path != "" {
765 baseUrl.Path = settings.Path
766 }
767 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
768 if err != nil {
769 return err
770 }
771 httpReq = httpReq.WithContext(ctx)
772 httpReq.Header = headers
773
774 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateOmnichannelSetting")
775 if err != nil {
776 return err
777 }
778
779 if err := unm.Unmarshal(buf, resp); err != nil {
780 return err
781 }
782
783 return nil
784 }, opts...)
785 if e != nil {
786 return nil, e
787 }
788 return resp, nil
789 }
790
791 // RequestInventoryVerification requests inventory verification for a given merchant in a given country.
792 func (c *omnichannelSettingsRESTClient) RequestInventoryVerification(ctx context.Context, req *accountspb.RequestInventoryVerificationRequest, opts ...gax.CallOption) (*accountspb.RequestInventoryVerificationResponse, error) {
793 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
794 jsonReq, err := m.Marshal(req)
795 if err != nil {
796 return nil, err
797 }
798
799 baseUrl, err := url.Parse(c.endpoint)
800 if err != nil {
801 return nil, err
802 }
803 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v:requestInventoryVerification", req.GetName())
804
805 params := url.Values{}
806 params.Add("$alt", "json;enum-encoding=int")
807
808 baseUrl.RawQuery = params.Encode()
809
810 // Build HTTP headers from client and context metadata.
811 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
812
813 hds = append(c.xGoogHeaders, hds...)
814 hds = append(hds, "Content-Type", "application/json")
815 headers := gax.BuildHeaders(ctx, hds...)
816 opts = append((*c.CallOptions).RequestInventoryVerification[0:len((*c.CallOptions).RequestInventoryVerification):len((*c.CallOptions).RequestInventoryVerification)], opts...)
817 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
818 resp := &accountspb.RequestInventoryVerificationResponse{}
819 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
820 if settings.Path != "" {
821 baseUrl.Path = settings.Path
822 }
823 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
824 if err != nil {
825 return err
826 }
827 httpReq = httpReq.WithContext(ctx)
828 httpReq.Header = headers
829
830 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RequestInventoryVerification")
831 if err != nil {
832 return err
833 }
834
835 if err := unm.Unmarshal(buf, resp); err != nil {
836 return err
837 }
838
839 return nil
840 }, opts...)
841 if e != nil {
842 return nil, e
843 }
844 return resp, nil
845 }