Debian Codegraph @

shopping/merchant/notifications/apiv1/notifications_api_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 notifications
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 notificationspb "cloud.google.com/go/shopping/merchant/notifications/apiv1/notificationspb"
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 newNotificationsApiClientHook clientHook
43
44 // NotificationsApiCallOptions contains the retry settings for each method of NotificationsApiClient.
45 type NotificationsApiCallOptions struct {
46 GetNotificationSubscription []gax.CallOption
47 CreateNotificationSubscription []gax.CallOption
48 UpdateNotificationSubscription []gax.CallOption
49 DeleteNotificationSubscription []gax.CallOption
50 ListNotificationSubscriptions []gax.CallOption
51 GetNotificationSubscriptionHealthMetrics []gax.CallOption
52 }
53
54 func defaultNotificationsApiGRPCClientOptions() []option.ClientOption {
55 return []option.ClientOption{
56 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
57 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
58 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
59 internaloption.WithDefaultUniverseDomain("googleapis.com"),
60 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
61 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
62 internaloption.EnableJwtWithScope(),
63 internaloption.EnableNewAuthLibrary(),
64 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
65 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
66 }
67 }
68
69 func defaultNotificationsApiCallOptions() *NotificationsApiCallOptions {
70 return &NotificationsApiCallOptions{
71 GetNotificationSubscription: []gax.CallOption{
72 gax.WithTimeout(60000 * time.Millisecond),
73 gax.WithRetry(func() gax.Retryer {
74 return gax.OnCodes([]codes.Code{
75 codes.Unavailable,
76 }, gax.Backoff{
77 Initial: 1000 * time.Millisecond,
78 Max: 10000 * time.Millisecond,
79 Multiplier: 1.30,
80 })
81 }),
82 },
83 CreateNotificationSubscription: []gax.CallOption{
84 gax.WithTimeout(60000 * time.Millisecond),
85 gax.WithRetry(func() gax.Retryer {
86 return gax.OnCodes([]codes.Code{
87 codes.Unavailable,
88 }, gax.Backoff{
89 Initial: 1000 * time.Millisecond,
90 Max: 10000 * time.Millisecond,
91 Multiplier: 1.30,
92 })
93 }),
94 },
95 UpdateNotificationSubscription: []gax.CallOption{
96 gax.WithTimeout(60000 * time.Millisecond),
97 gax.WithRetry(func() gax.Retryer {
98 return gax.OnCodes([]codes.Code{
99 codes.Unavailable,
100 }, gax.Backoff{
101 Initial: 1000 * time.Millisecond,
102 Max: 10000 * time.Millisecond,
103 Multiplier: 1.30,
104 })
105 }),
106 },
107 DeleteNotificationSubscription: []gax.CallOption{
108 gax.WithTimeout(60000 * time.Millisecond),
109 gax.WithRetry(func() gax.Retryer {
110 return gax.OnCodes([]codes.Code{
111 codes.Unavailable,
112 }, gax.Backoff{
113 Initial: 1000 * time.Millisecond,
114 Max: 10000 * time.Millisecond,
115 Multiplier: 1.30,
116 })
117 }),
118 },
119 ListNotificationSubscriptions: []gax.CallOption{
120 gax.WithTimeout(60000 * time.Millisecond),
121 gax.WithRetry(func() gax.Retryer {
122 return gax.OnCodes([]codes.Code{
123 codes.Unavailable,
124 }, gax.Backoff{
125 Initial: 1000 * time.Millisecond,
126 Max: 10000 * time.Millisecond,
127 Multiplier: 1.30,
128 })
129 }),
130 },
131 GetNotificationSubscriptionHealthMetrics: []gax.CallOption{
132 gax.WithTimeout(60000 * time.Millisecond),
133 gax.WithRetry(func() gax.Retryer {
134 return gax.OnCodes([]codes.Code{
135 codes.Unavailable,
136 }, gax.Backoff{
137 Initial: 1000 * time.Millisecond,
138 Max: 10000 * time.Millisecond,
139 Multiplier: 1.30,
140 })
141 }),
142 },
143 }
144 }
145
146 func defaultNotificationsApiRESTCallOptions() *NotificationsApiCallOptions {
147 return &NotificationsApiCallOptions{
148 GetNotificationSubscription: []gax.CallOption{
149 gax.WithTimeout(60000 * time.Millisecond),
150 gax.WithRetry(func() gax.Retryer {
151 return gax.OnHTTPCodes(gax.Backoff{
152 Initial: 1000 * time.Millisecond,
153 Max: 10000 * time.Millisecond,
154 Multiplier: 1.30,
155 },
156 http.StatusServiceUnavailable)
157 }),
158 },
159 CreateNotificationSubscription: []gax.CallOption{
160 gax.WithTimeout(60000 * time.Millisecond),
161 gax.WithRetry(func() gax.Retryer {
162 return gax.OnHTTPCodes(gax.Backoff{
163 Initial: 1000 * time.Millisecond,
164 Max: 10000 * time.Millisecond,
165 Multiplier: 1.30,
166 },
167 http.StatusServiceUnavailable)
168 }),
169 },
170 UpdateNotificationSubscription: []gax.CallOption{
171 gax.WithTimeout(60000 * time.Millisecond),
172 gax.WithRetry(func() gax.Retryer {
173 return gax.OnHTTPCodes(gax.Backoff{
174 Initial: 1000 * time.Millisecond,
175 Max: 10000 * time.Millisecond,
176 Multiplier: 1.30,
177 },
178 http.StatusServiceUnavailable)
179 }),
180 },
181 DeleteNotificationSubscription: []gax.CallOption{
182 gax.WithTimeout(60000 * time.Millisecond),
183 gax.WithRetry(func() gax.Retryer {
184 return gax.OnHTTPCodes(gax.Backoff{
185 Initial: 1000 * time.Millisecond,
186 Max: 10000 * time.Millisecond,
187 Multiplier: 1.30,
188 },
189 http.StatusServiceUnavailable)
190 }),
191 },
192 ListNotificationSubscriptions: []gax.CallOption{
193 gax.WithTimeout(60000 * time.Millisecond),
194 gax.WithRetry(func() gax.Retryer {
195 return gax.OnHTTPCodes(gax.Backoff{
196 Initial: 1000 * time.Millisecond,
197 Max: 10000 * time.Millisecond,
198 Multiplier: 1.30,
199 },
200 http.StatusServiceUnavailable)
201 }),
202 },
203 GetNotificationSubscriptionHealthMetrics: []gax.CallOption{
204 gax.WithTimeout(60000 * time.Millisecond),
205 gax.WithRetry(func() gax.Retryer {
206 return gax.OnHTTPCodes(gax.Backoff{
207 Initial: 1000 * time.Millisecond,
208 Max: 10000 * time.Millisecond,
209 Multiplier: 1.30,
210 },
211 http.StatusServiceUnavailable)
212 }),
213 },
214 }
215 }
216
217 // internalNotificationsApiClient is an interface that defines the methods available from Merchant API.
218 type internalNotificationsApiClient interface {
219 Close() error
220 setGoogleClientInfo(...string)
221 Connection() *grpc.ClientConn
222 GetNotificationSubscription(context.Context, *notificationspb.GetNotificationSubscriptionRequest, ...gax.CallOption) (*notificationspb.NotificationSubscription, error)
223 CreateNotificationSubscription(context.Context, *notificationspb.CreateNotificationSubscriptionRequest, ...gax.CallOption) (*notificationspb.NotificationSubscription, error)
224 UpdateNotificationSubscription(context.Context, *notificationspb.UpdateNotificationSubscriptionRequest, ...gax.CallOption) (*notificationspb.NotificationSubscription, error)
225 DeleteNotificationSubscription(context.Context, *notificationspb.DeleteNotificationSubscriptionRequest, ...gax.CallOption) error
226 ListNotificationSubscriptions(context.Context, *notificationspb.ListNotificationSubscriptionsRequest, ...gax.CallOption) *NotificationSubscriptionIterator
227 GetNotificationSubscriptionHealthMetrics(context.Context, *notificationspb.GetNotificationSubscriptionHealthMetricsRequest, ...gax.CallOption) (*notificationspb.NotificationSubscriptionHealthMetrics, error)
228 }
229
230 // NotificationsApiClient is a client for interacting with Merchant API.
231 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
232 //
233 // Service to manage notification subscriptions for merchants
234 type NotificationsApiClient struct {
235 // The internal transport-dependent client.
236 internalClient internalNotificationsApiClient
237
238 // The call options for this service.
239 CallOptions *NotificationsApiCallOptions
240 }
241
242 // Wrapper methods routed to the internal client.
243
244 // Close closes the connection to the API service. The user should invoke this when
245 // the client is no longer required.
246 func (c *NotificationsApiClient) Close() error {
247 return c.internalClient.Close()
248 }
249
250 // setGoogleClientInfo sets the name and version of the application in
251 // the `x-goog-api-client` header passed on each request. Intended for
252 // use by Google-written clients.
253 func (c *NotificationsApiClient) setGoogleClientInfo(keyval ...string) {
254 c.internalClient.setGoogleClientInfo(keyval...)
255 }
256
257 // Connection returns a connection to the API service.
258 //
259 // Deprecated: Connections are now pooled so this method does not always
260 // return the same resource.
261 func (c *NotificationsApiClient) Connection() *grpc.ClientConn {
262 return c.internalClient.Connection()
263 }
264
265 // GetNotificationSubscription gets notification subscriptions for an account.
266 func (c *NotificationsApiClient) GetNotificationSubscription(ctx context.Context, req *notificationspb.GetNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
267 return c.internalClient.GetNotificationSubscription(ctx, req, opts...)
268 }
269
270 // CreateNotificationSubscription creates a notification subscription for a business.
271 // For standalone or subaccounts accounts, the business can create a
272 // subscription for self. For MCAs, the business can create a
273 // subscription for all managed accounts or for a specific subaccount.
274 //
275 // We will allow the following types of notification subscriptions to exist
276 // together (per business as a subscriber per event type):
277 //
278 // Subscription for all managed accounts + subscription for self.
279 //
280 // Multiple “partial” subscriptions for managed accounts + subscription
281 // for self.
282 //
283 // we will not allow (per business as a subscriber per event type):
284 //
285 // Multiple self subscriptions.
286 //
287 // Multiple “all managed accounts” subscriptions.
288 //
289 // “All managed accounts” subscription and partial subscriptions at the
290 // same time.
291 //
292 // Multiple partial subscriptions for the same target account.
293 func (c *NotificationsApiClient) CreateNotificationSubscription(ctx context.Context, req *notificationspb.CreateNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
294 return c.internalClient.CreateNotificationSubscription(ctx, req, opts...)
295 }
296
297 // UpdateNotificationSubscription updates an existing notification subscription for a merchant.
298 func (c *NotificationsApiClient) UpdateNotificationSubscription(ctx context.Context, req *notificationspb.UpdateNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
299 return c.internalClient.UpdateNotificationSubscription(ctx, req, opts...)
300 }
301
302 // DeleteNotificationSubscription deletes a notification subscription for a merchant.
303 func (c *NotificationsApiClient) DeleteNotificationSubscription(ctx context.Context, req *notificationspb.DeleteNotificationSubscriptionRequest, opts ...gax.CallOption) error {
304 return c.internalClient.DeleteNotificationSubscription(ctx, req, opts...)
305 }
306
307 // ListNotificationSubscriptions gets all the notification subscriptions for a merchant.
308 func (c *NotificationsApiClient) ListNotificationSubscriptions(ctx context.Context, req *notificationspb.ListNotificationSubscriptionsRequest, opts ...gax.CallOption) *NotificationSubscriptionIterator {
309 return c.internalClient.ListNotificationSubscriptions(ctx, req, opts...)
310 }
311
312 // GetNotificationSubscriptionHealthMetrics retrieves notification subscription health metrics for a merchant.
313 // We recommend calling this periodically (hourly or daily) to monitor health
314 // of your callback endpoint.
315 func (c *NotificationsApiClient) GetNotificationSubscriptionHealthMetrics(ctx context.Context, req *notificationspb.GetNotificationSubscriptionHealthMetricsRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscriptionHealthMetrics, error) {
316 return c.internalClient.GetNotificationSubscriptionHealthMetrics(ctx, req, opts...)
317 }
318
319 // notificationsApiGRPCClient is a client for interacting with Merchant API over gRPC transport.
320 //
321 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
322 type notificationsApiGRPCClient struct {
323 // Connection pool of gRPC connections to the service.
324 connPool gtransport.ConnPool
325
326 // Points back to the CallOptions field of the containing NotificationsApiClient
327 CallOptions **NotificationsApiCallOptions
328
329 // The gRPC API client.
330 notificationsApiClient notificationspb.NotificationsApiServiceClient
331
332 // The x-goog-* metadata to be sent with each request.
333 xGoogHeaders []string
334
335 logger *slog.Logger
336 }
337
338 // NewNotificationsApiClient creates a new notifications api service client based on gRPC.
339 // The returned client must be Closed when it is done being used to clean up its underlying connections.
340 //
341 // Service to manage notification subscriptions for merchants
342 func NewNotificationsApiClient(ctx context.Context, opts ...option.ClientOption) (*NotificationsApiClient, error) {
343 clientOpts := defaultNotificationsApiGRPCClientOptions()
344 if newNotificationsApiClientHook != nil {
345 hookOpts, err := newNotificationsApiClientHook(ctx, clientHookParams{})
346 if err != nil {
347 return nil, err
348 }
349 clientOpts = append(clientOpts, hookOpts...)
350 }
351
352 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
353 if err != nil {
354 return nil, err
355 }
356 client := NotificationsApiClient{CallOptions: defaultNotificationsApiCallOptions()}
357
358 c := &notificationsApiGRPCClient{
359 connPool: connPool,
360 notificationsApiClient: notificationspb.NewNotificationsApiServiceClient(connPool),
361 CallOptions: &client.CallOptions,
362 logger: internaloption.GetLogger(opts),
363 }
364 c.setGoogleClientInfo()
365
366 client.internalClient = c
367
368 return &client, nil
369 }
370
371 // Connection returns a connection to the API service.
372 //
373 // Deprecated: Connections are now pooled so this method does not always
374 // return the same resource.
375 func (c *notificationsApiGRPCClient) Connection() *grpc.ClientConn {
376 return c.connPool.Conn()
377 }
378
379 // setGoogleClientInfo sets the name and version of the application in
380 // the `x-goog-api-client` header passed on each request. Intended for
381 // use by Google-written clients.
382 func (c *notificationsApiGRPCClient) setGoogleClientInfo(keyval ...string) {
383 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
384 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
385 c.xGoogHeaders = []string{
386 "x-goog-api-client", gax.XGoogHeader(kv...),
387 }
388 }
389
390 // Close closes the connection to the API service. The user should invoke this when
391 // the client is no longer required.
392 func (c *notificationsApiGRPCClient) Close() error {
393 return c.connPool.Close()
394 }
395
396 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
397 type notificationsApiRESTClient struct {
398 // The http endpoint to connect to.
399 endpoint string
400
401 // The http client.
402 httpClient *http.Client
403
404 // The x-goog-* headers to be sent with each request.
405 xGoogHeaders []string
406
407 // Points back to the CallOptions field of the containing NotificationsApiClient
408 CallOptions **NotificationsApiCallOptions
409
410 logger *slog.Logger
411 }
412
413 // NewNotificationsApiRESTClient creates a new notifications api service rest client.
414 //
415 // Service to manage notification subscriptions for merchants
416 func NewNotificationsApiRESTClient(ctx context.Context, opts ...option.ClientOption) (*NotificationsApiClient, error) {
417 clientOpts := append(defaultNotificationsApiRESTClientOptions(), opts...)
418 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
419 if err != nil {
420 return nil, err
421 }
422
423 callOpts := defaultNotificationsApiRESTCallOptions()
424 c := &notificationsApiRESTClient{
425 endpoint: endpoint,
426 httpClient: httpClient,
427 CallOptions: &callOpts,
428 logger: internaloption.GetLogger(opts),
429 }
430 c.setGoogleClientInfo()
431
432 return &NotificationsApiClient{internalClient: c, CallOptions: callOpts}, nil
433 }
434
435 func defaultNotificationsApiRESTClientOptions() []option.ClientOption {
436 return []option.ClientOption{
437 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
438 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
439 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
440 internaloption.WithDefaultUniverseDomain("googleapis.com"),
441 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
442 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
443 internaloption.EnableNewAuthLibrary(),
444 }
445 }
446
447 // setGoogleClientInfo sets the name and version of the application in
448 // the `x-goog-api-client` header passed on each request. Intended for
449 // use by Google-written clients.
450 func (c *notificationsApiRESTClient) setGoogleClientInfo(keyval ...string) {
451 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
452 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
453 c.xGoogHeaders = []string{
454 "x-goog-api-client", gax.XGoogHeader(kv...),
455 }
456 }
457
458 // Close closes the connection to the API service. The user should invoke this when
459 // the client is no longer required.
460 func (c *notificationsApiRESTClient) Close() error {
461 // Replace httpClient with nil to force cleanup.
462 c.httpClient = nil
463 return nil
464 }
465
466 // Connection returns a connection to the API service.
467 //
468 // Deprecated: This method always returns nil.
469 func (c *notificationsApiRESTClient) Connection() *grpc.ClientConn {
470 return nil
471 }
472 func (c *notificationsApiGRPCClient) GetNotificationSubscription(ctx context.Context, req *notificationspb.GetNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
473 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
474
475 hds = append(c.xGoogHeaders, hds...)
476 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
477 opts = append((*c.CallOptions).GetNotificationSubscription[0:len((*c.CallOptions).GetNotificationSubscription):len((*c.CallOptions).GetNotificationSubscription)], opts...)
478 var resp *notificationspb.NotificationSubscription
479 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
480 var err error
481 resp, err = executeRPC(ctx, c.notificationsApiClient.GetNotificationSubscription, req, settings.GRPC, c.logger, "GetNotificationSubscription")
482 return err
483 }, opts...)
484 if err != nil {
485 return nil, err
486 }
487 return resp, nil
488 }
489
490 func (c *notificationsApiGRPCClient) CreateNotificationSubscription(ctx context.Context, req *notificationspb.CreateNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
491 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
492
493 hds = append(c.xGoogHeaders, hds...)
494 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
495 opts = append((*c.CallOptions).CreateNotificationSubscription[0:len((*c.CallOptions).CreateNotificationSubscription):len((*c.CallOptions).CreateNotificationSubscription)], opts...)
496 var resp *notificationspb.NotificationSubscription
497 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
498 var err error
499 resp, err = executeRPC(ctx, c.notificationsApiClient.CreateNotificationSubscription, req, settings.GRPC, c.logger, "CreateNotificationSubscription")
500 return err
501 }, opts...)
502 if err != nil {
503 return nil, err
504 }
505 return resp, nil
506 }
507
508 func (c *notificationsApiGRPCClient) UpdateNotificationSubscription(ctx context.Context, req *notificationspb.UpdateNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
509 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "notification_subscription.name", url.QueryEscape(req.GetNotificationSubscription().GetName()))}
510
511 hds = append(c.xGoogHeaders, hds...)
512 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
513 opts = append((*c.CallOptions).UpdateNotificationSubscription[0:len((*c.CallOptions).UpdateNotificationSubscription):len((*c.CallOptions).UpdateNotificationSubscription)], opts...)
514 var resp *notificationspb.NotificationSubscription
515 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
516 var err error
517 resp, err = executeRPC(ctx, c.notificationsApiClient.UpdateNotificationSubscription, req, settings.GRPC, c.logger, "UpdateNotificationSubscription")
518 return err
519 }, opts...)
520 if err != nil {
521 return nil, err
522 }
523 return resp, nil
524 }
525
526 func (c *notificationsApiGRPCClient) DeleteNotificationSubscription(ctx context.Context, req *notificationspb.DeleteNotificationSubscriptionRequest, opts ...gax.CallOption) error {
527 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
528
529 hds = append(c.xGoogHeaders, hds...)
530 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
531 opts = append((*c.CallOptions).DeleteNotificationSubscription[0:len((*c.CallOptions).DeleteNotificationSubscription):len((*c.CallOptions).DeleteNotificationSubscription)], opts...)
532 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
533 var err error
534 _, err = executeRPC(ctx, c.notificationsApiClient.DeleteNotificationSubscription, req, settings.GRPC, c.logger, "DeleteNotificationSubscription")
535 return err
536 }, opts...)
537 return err
538 }
539
540 func (c *notificationsApiGRPCClient) ListNotificationSubscriptions(ctx context.Context, req *notificationspb.ListNotificationSubscriptionsRequest, opts ...gax.CallOption) *NotificationSubscriptionIterator {
541 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
542
543 hds = append(c.xGoogHeaders, hds...)
544 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
545 opts = append((*c.CallOptions).ListNotificationSubscriptions[0:len((*c.CallOptions).ListNotificationSubscriptions):len((*c.CallOptions).ListNotificationSubscriptions)], opts...)
546 it := &NotificationSubscriptionIterator{}
547 req = proto.Clone(req).(*notificationspb.ListNotificationSubscriptionsRequest)
548 it.InternalFetch = func(pageSize int, pageToken string) ([]*notificationspb.NotificationSubscription, string, error) {
549 resp := &notificationspb.ListNotificationSubscriptionsResponse{}
550 if pageToken != "" {
551 req.PageToken = pageToken
552 }
553 if pageSize > math.MaxInt32 {
554 req.PageSize = math.MaxInt32
555 } else if pageSize != 0 {
556 req.PageSize = int32(pageSize)
557 }
558 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
559 var err error
560 resp, err = executeRPC(ctx, c.notificationsApiClient.ListNotificationSubscriptions, req, settings.GRPC, c.logger, "ListNotificationSubscriptions")
561 return err
562 }, opts...)
563 if err != nil {
564 return nil, "", err
565 }
566
567 it.Response = resp
568 return resp.GetNotificationSubscriptions(), resp.GetNextPageToken(), nil
569 }
570 fetch := func(pageSize int, pageToken string) (string, error) {
571 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
572 if err != nil {
573 return "", err
574 }
575 it.items = append(it.items, items...)
576 return nextPageToken, nil
577 }
578
579 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
580 it.pageInfo.MaxSize = int(req.GetPageSize())
581 it.pageInfo.Token = req.GetPageToken()
582
583 return it
584 }
585
586 func (c *notificationsApiGRPCClient) GetNotificationSubscriptionHealthMetrics(ctx context.Context, req *notificationspb.GetNotificationSubscriptionHealthMetricsRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscriptionHealthMetrics, error) {
587 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
588
589 hds = append(c.xGoogHeaders, hds...)
590 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
591 opts = append((*c.CallOptions).GetNotificationSubscriptionHealthMetrics[0:len((*c.CallOptions).GetNotificationSubscriptionHealthMetrics):len((*c.CallOptions).GetNotificationSubscriptionHealthMetrics)], opts...)
592 var resp *notificationspb.NotificationSubscriptionHealthMetrics
593 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
594 var err error
595 resp, err = executeRPC(ctx, c.notificationsApiClient.GetNotificationSubscriptionHealthMetrics, req, settings.GRPC, c.logger, "GetNotificationSubscriptionHealthMetrics")
596 return err
597 }, opts...)
598 if err != nil {
599 return nil, err
600 }
601 return resp, nil
602 }
603
604 // GetNotificationSubscription gets notification subscriptions for an account.
605 func (c *notificationsApiRESTClient) GetNotificationSubscription(ctx context.Context, req *notificationspb.GetNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
606 baseUrl, err := url.Parse(c.endpoint)
607 if err != nil {
608 return nil, err
609 }
610 baseUrl.Path += fmt.Sprintf("/notifications/v1/%v", req.GetName())
611
612 params := url.Values{}
613 params.Add("$alt", "json;enum-encoding=int")
614
615 baseUrl.RawQuery = params.Encode()
616
617 // Build HTTP headers from client and context metadata.
618 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
619
620 hds = append(c.xGoogHeaders, hds...)
621 hds = append(hds, "Content-Type", "application/json")
622 headers := gax.BuildHeaders(ctx, hds...)
623 opts = append((*c.CallOptions).GetNotificationSubscription[0:len((*c.CallOptions).GetNotificationSubscription):len((*c.CallOptions).GetNotificationSubscription)], opts...)
624 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
625 resp := &notificationspb.NotificationSubscription{}
626 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
627 if settings.Path != "" {
628 baseUrl.Path = settings.Path
629 }
630 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
631 if err != nil {
632 return err
633 }
634 httpReq = httpReq.WithContext(ctx)
635 httpReq.Header = headers
636
637 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetNotificationSubscription")
638 if err != nil {
639 return err
640 }
641
642 if err := unm.Unmarshal(buf, resp); err != nil {
643 return err
644 }
645
646 return nil
647 }, opts...)
648 if e != nil {
649 return nil, e
650 }
651 return resp, nil
652 }
653
654 // CreateNotificationSubscription creates a notification subscription for a business.
655 // For standalone or subaccounts accounts, the business can create a
656 // subscription for self. For MCAs, the business can create a
657 // subscription for all managed accounts or for a specific subaccount.
658 //
659 // We will allow the following types of notification subscriptions to exist
660 // together (per business as a subscriber per event type):
661 //
662 // Subscription for all managed accounts + subscription for self.
663 //
664 // Multiple “partial” subscriptions for managed accounts + subscription
665 // for self.
666 //
667 // we will not allow (per business as a subscriber per event type):
668 //
669 // Multiple self subscriptions.
670 //
671 // Multiple “all managed accounts” subscriptions.
672 //
673 // “All managed accounts” subscription and partial subscriptions at the
674 // same time.
675 //
676 // Multiple partial subscriptions for the same target account.
677 func (c *notificationsApiRESTClient) CreateNotificationSubscription(ctx context.Context, req *notificationspb.CreateNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
678 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
679 body := req.GetNotificationSubscription()
680 jsonReq, err := m.Marshal(body)
681 if err != nil {
682 return nil, err
683 }
684
685 baseUrl, err := url.Parse(c.endpoint)
686 if err != nil {
687 return nil, err
688 }
689 baseUrl.Path += fmt.Sprintf("/notifications/v1/%v/notificationsubscriptions", req.GetParent())
690
691 params := url.Values{}
692 params.Add("$alt", "json;enum-encoding=int")
693
694 baseUrl.RawQuery = params.Encode()
695
696 // Build HTTP headers from client and context metadata.
697 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
698
699 hds = append(c.xGoogHeaders, hds...)
700 hds = append(hds, "Content-Type", "application/json")
701 headers := gax.BuildHeaders(ctx, hds...)
702 opts = append((*c.CallOptions).CreateNotificationSubscription[0:len((*c.CallOptions).CreateNotificationSubscription):len((*c.CallOptions).CreateNotificationSubscription)], opts...)
703 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
704 resp := &notificationspb.NotificationSubscription{}
705 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
706 if settings.Path != "" {
707 baseUrl.Path = settings.Path
708 }
709 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
710 if err != nil {
711 return err
712 }
713 httpReq = httpReq.WithContext(ctx)
714 httpReq.Header = headers
715
716 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateNotificationSubscription")
717 if err != nil {
718 return err
719 }
720
721 if err := unm.Unmarshal(buf, resp); err != nil {
722 return err
723 }
724
725 return nil
726 }, opts...)
727 if e != nil {
728 return nil, e
729 }
730 return resp, nil
731 }
732
733 // UpdateNotificationSubscription updates an existing notification subscription for a merchant.
734 func (c *notificationsApiRESTClient) UpdateNotificationSubscription(ctx context.Context, req *notificationspb.UpdateNotificationSubscriptionRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscription, error) {
735 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
736 body := req.GetNotificationSubscription()
737 jsonReq, err := m.Marshal(body)
738 if err != nil {
739 return nil, err
740 }
741
742 baseUrl, err := url.Parse(c.endpoint)
743 if err != nil {
744 return nil, err
745 }
746 baseUrl.Path += fmt.Sprintf("/notifications/v1/%v", req.GetNotificationSubscription().GetName())
747
748 params := url.Values{}
749 params.Add("$alt", "json;enum-encoding=int")
750 if req.GetUpdateMask() != nil {
751 field, err := protojson.Marshal(req.GetUpdateMask())
752 if err != nil {
753 return nil, err
754 }
755 params.Add("updateMask", string(field[1:len(field)-1]))
756 }
757
758 baseUrl.RawQuery = params.Encode()
759
760 // Build HTTP headers from client and context metadata.
761 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "notification_subscription.name", url.QueryEscape(req.GetNotificationSubscription().GetName()))}
762
763 hds = append(c.xGoogHeaders, hds...)
764 hds = append(hds, "Content-Type", "application/json")
765 headers := gax.BuildHeaders(ctx, hds...)
766 opts = append((*c.CallOptions).UpdateNotificationSubscription[0:len((*c.CallOptions).UpdateNotificationSubscription):len((*c.CallOptions).UpdateNotificationSubscription)], opts...)
767 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
768 resp := &notificationspb.NotificationSubscription{}
769 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
770 if settings.Path != "" {
771 baseUrl.Path = settings.Path
772 }
773 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
774 if err != nil {
775 return err
776 }
777 httpReq = httpReq.WithContext(ctx)
778 httpReq.Header = headers
779
780 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateNotificationSubscription")
781 if err != nil {
782 return err
783 }
784
785 if err := unm.Unmarshal(buf, resp); err != nil {
786 return err
787 }
788
789 return nil
790 }, opts...)
791 if e != nil {
792 return nil, e
793 }
794 return resp, nil
795 }
796
797 // DeleteNotificationSubscription deletes a notification subscription for a merchant.
798 func (c *notificationsApiRESTClient) DeleteNotificationSubscription(ctx context.Context, req *notificationspb.DeleteNotificationSubscriptionRequest, opts ...gax.CallOption) error {
799 baseUrl, err := url.Parse(c.endpoint)
800 if err != nil {
801 return err
802 }
803 baseUrl.Path += fmt.Sprintf("/notifications/v1/%v", 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 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
817 if settings.Path != "" {
818 baseUrl.Path = settings.Path
819 }
820 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
821 if err != nil {
822 return err
823 }
824 httpReq = httpReq.WithContext(ctx)
825 httpReq.Header = headers
826
827 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteNotificationSubscription")
828 return err
829 }, opts...)
830 }
831
832 // ListNotificationSubscriptions gets all the notification subscriptions for a merchant.
833 func (c *notificationsApiRESTClient) ListNotificationSubscriptions(ctx context.Context, req *notificationspb.ListNotificationSubscriptionsRequest, opts ...gax.CallOption) *NotificationSubscriptionIterator {
834 it := &NotificationSubscriptionIterator{}
835 req = proto.Clone(req).(*notificationspb.ListNotificationSubscriptionsRequest)
836 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
837 it.InternalFetch = func(pageSize int, pageToken string) ([]*notificationspb.NotificationSubscription, string, error) {
838 resp := &notificationspb.ListNotificationSubscriptionsResponse{}
839 if pageToken != "" {
840 req.PageToken = pageToken
841 }
842 if pageSize > math.MaxInt32 {
843 req.PageSize = math.MaxInt32
844 } else if pageSize != 0 {
845 req.PageSize = int32(pageSize)
846 }
847 baseUrl, err := url.Parse(c.endpoint)
848 if err != nil {
849 return nil, "", err
850 }
851 baseUrl.Path += fmt.Sprintf("/notifications/v1/%v/notificationsubscriptions", req.GetParent())
852
853 params := url.Values{}
854 params.Add("$alt", "json;enum-encoding=int")
855 if req.GetPageSize() != 0 {
856 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
857 }
858 if req.GetPageToken() != "" {
859 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
860 }
861
862 baseUrl.RawQuery = params.Encode()
863
864 // Build HTTP headers from client and context metadata.
865 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
866 headers := gax.BuildHeaders(ctx, hds...)
867 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
868 if settings.Path != "" {
869 baseUrl.Path = settings.Path
870 }
871 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
872 if err != nil {
873 return err
874 }
875 httpReq.Header = headers
876
877 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListNotificationSubscriptions")
878 if err != nil {
879 return err
880 }
881 if err := unm.Unmarshal(buf, resp); err != nil {
882 return err
883 }
884
885 return nil
886 }, opts...)
887 if e != nil {
888 return nil, "", e
889 }
890 it.Response = resp
891 return resp.GetNotificationSubscriptions(), resp.GetNextPageToken(), nil
892 }
893
894 fetch := func(pageSize int, pageToken string) (string, error) {
895 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
896 if err != nil {
897 return "", err
898 }
899 it.items = append(it.items, items...)
900 return nextPageToken, nil
901 }
902
903 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
904 it.pageInfo.MaxSize = int(req.GetPageSize())
905 it.pageInfo.Token = req.GetPageToken()
906
907 return it
908 }
909
910 // GetNotificationSubscriptionHealthMetrics retrieves notification subscription health metrics for a merchant.
911 // We recommend calling this periodically (hourly or daily) to monitor health
912 // of your callback endpoint.
913 func (c *notificationsApiRESTClient) GetNotificationSubscriptionHealthMetrics(ctx context.Context, req *notificationspb.GetNotificationSubscriptionHealthMetricsRequest, opts ...gax.CallOption) (*notificationspb.NotificationSubscriptionHealthMetrics, error) {
914 baseUrl, err := url.Parse(c.endpoint)
915 if err != nil {
916 return nil, err
917 }
918 baseUrl.Path += fmt.Sprintf("/notifications/v1/%v:getHealth", req.GetName())
919
920 params := url.Values{}
921 params.Add("$alt", "json;enum-encoding=int")
922
923 baseUrl.RawQuery = params.Encode()
924
925 // Build HTTP headers from client and context metadata.
926 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
927
928 hds = append(c.xGoogHeaders, hds...)
929 hds = append(hds, "Content-Type", "application/json")
930 headers := gax.BuildHeaders(ctx, hds...)
931 opts = append((*c.CallOptions).GetNotificationSubscriptionHealthMetrics[0:len((*c.CallOptions).GetNotificationSubscriptionHealthMetrics):len((*c.CallOptions).GetNotificationSubscriptionHealthMetrics)], opts...)
932 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
933 resp := &notificationspb.NotificationSubscriptionHealthMetrics{}
934 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
935 if settings.Path != "" {
936 baseUrl.Path = settings.Path
937 }
938 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
939 if err != nil {
940 return err
941 }
942 httpReq = httpReq.WithContext(ctx)
943 httpReq.Header = headers
944
945 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetNotificationSubscriptionHealthMetrics")
946 if err != nil {
947 return err
948 }
949
950 if err := unm.Unmarshal(buf, resp); err != nil {
951 return err
952 }
953
954 return nil
955 }, opts...)
956 if e != nil {
957 return nil, e
958 }
959 return resp, nil
960 }