Debian Codegraph @

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