Debian Codegraph @

shopping/merchant/conversions/apiv1/conversion_sources_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 conversions
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 conversionspb "cloud.google.com/go/shopping/merchant/conversions/apiv1/conversionspb"
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 newConversionSourcesClientHook clientHook
43
44 // ConversionSourcesCallOptions contains the retry settings for each method of ConversionSourcesClient.
45 type ConversionSourcesCallOptions struct {
46 CreateConversionSource []gax.CallOption
47 UpdateConversionSource []gax.CallOption
48 DeleteConversionSource []gax.CallOption
49 UndeleteConversionSource []gax.CallOption
50 GetConversionSource []gax.CallOption
51 ListConversionSources []gax.CallOption
52 }
53
54 func defaultConversionSourcesGRPCClientOptions() []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 defaultConversionSourcesCallOptions() *ConversionSourcesCallOptions {
70 return &ConversionSourcesCallOptions{
71 CreateConversionSource: []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 UpdateConversionSource: []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 DeleteConversionSource: []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 UndeleteConversionSource: []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 GetConversionSource: []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 ListConversionSources: []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 defaultConversionSourcesRESTCallOptions() *ConversionSourcesCallOptions {
147 return &ConversionSourcesCallOptions{
148 CreateConversionSource: []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 UpdateConversionSource: []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 DeleteConversionSource: []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 UndeleteConversionSource: []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 GetConversionSource: []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 ListConversionSources: []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 // internalConversionSourcesClient is an interface that defines the methods available from Merchant API.
218 type internalConversionSourcesClient interface {
219 Close() error
220 setGoogleClientInfo(...string)
221 Connection() *grpc.ClientConn
222 CreateConversionSource(context.Context, *conversionspb.CreateConversionSourceRequest, ...gax.CallOption) (*conversionspb.ConversionSource, error)
223 UpdateConversionSource(context.Context, *conversionspb.UpdateConversionSourceRequest, ...gax.CallOption) (*conversionspb.ConversionSource, error)
224 DeleteConversionSource(context.Context, *conversionspb.DeleteConversionSourceRequest, ...gax.CallOption) error
225 UndeleteConversionSource(context.Context, *conversionspb.UndeleteConversionSourceRequest, ...gax.CallOption) (*conversionspb.ConversionSource, error)
226 GetConversionSource(context.Context, *conversionspb.GetConversionSourceRequest, ...gax.CallOption) (*conversionspb.ConversionSource, error)
227 ListConversionSources(context.Context, *conversionspb.ListConversionSourcesRequest, ...gax.CallOption) *ConversionSourceIterator
228 }
229
230 // ConversionSourcesClient 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 for managing conversion sources for a merchant account.
234 type ConversionSourcesClient struct {
235 // The internal transport-dependent client.
236 internalClient internalConversionSourcesClient
237
238 // The call options for this service.
239 CallOptions *ConversionSourcesCallOptions
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 *ConversionSourcesClient) 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 *ConversionSourcesClient) 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 *ConversionSourcesClient) Connection() *grpc.ClientConn {
262 return c.internalClient.Connection()
263 }
264
265 // CreateConversionSource creates a new conversion source.
266 func (c *ConversionSourcesClient) CreateConversionSource(ctx context.Context, req *conversionspb.CreateConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
267 return c.internalClient.CreateConversionSource(ctx, req, opts...)
268 }
269
270 // UpdateConversionSource updates information of an existing conversion source. Available only for
271 // Merchant Center Destination conversion sources.
272 func (c *ConversionSourcesClient) UpdateConversionSource(ctx context.Context, req *conversionspb.UpdateConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
273 return c.internalClient.UpdateConversionSource(ctx, req, opts...)
274 }
275
276 // DeleteConversionSource archives an existing conversion source. If the conversion source is a
277 // Merchant Center Destination, it will be recoverable for 30 days. If the
278 // conversion source is a Google Analytics Link, it will be deleted
279 // immediately and can be restored by creating a new one.
280 func (c *ConversionSourcesClient) DeleteConversionSource(ctx context.Context, req *conversionspb.DeleteConversionSourceRequest, opts ...gax.CallOption) error {
281 return c.internalClient.DeleteConversionSource(ctx, req, opts...)
282 }
283
284 // UndeleteConversionSource re-enables an archived conversion source. Only Available for Merchant
285 // Center Destination conversion sources.
286 func (c *ConversionSourcesClient) UndeleteConversionSource(ctx context.Context, req *conversionspb.UndeleteConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
287 return c.internalClient.UndeleteConversionSource(ctx, req, opts...)
288 }
289
290 // GetConversionSource fetches a conversion source.
291 func (c *ConversionSourcesClient) GetConversionSource(ctx context.Context, req *conversionspb.GetConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
292 return c.internalClient.GetConversionSource(ctx, req, opts...)
293 }
294
295 // ListConversionSources retrieves the list of conversion sources the caller has access to.
296 func (c *ConversionSourcesClient) ListConversionSources(ctx context.Context, req *conversionspb.ListConversionSourcesRequest, opts ...gax.CallOption) *ConversionSourceIterator {
297 return c.internalClient.ListConversionSources(ctx, req, opts...)
298 }
299
300 // conversionSourcesGRPCClient is a client for interacting with Merchant API over gRPC transport.
301 //
302 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
303 type conversionSourcesGRPCClient struct {
304 // Connection pool of gRPC connections to the service.
305 connPool gtransport.ConnPool
306
307 // Points back to the CallOptions field of the containing ConversionSourcesClient
308 CallOptions **ConversionSourcesCallOptions
309
310 // The gRPC API client.
311 conversionSourcesClient conversionspb.ConversionSourcesServiceClient
312
313 // The x-goog-* metadata to be sent with each request.
314 xGoogHeaders []string
315
316 logger *slog.Logger
317 }
318
319 // NewConversionSourcesClient creates a new conversion sources service client based on gRPC.
320 // The returned client must be Closed when it is done being used to clean up its underlying connections.
321 //
322 // Service for managing conversion sources for a merchant account.
323 func NewConversionSourcesClient(ctx context.Context, opts ...option.ClientOption) (*ConversionSourcesClient, error) {
324 clientOpts := defaultConversionSourcesGRPCClientOptions()
325 if newConversionSourcesClientHook != nil {
326 hookOpts, err := newConversionSourcesClientHook(ctx, clientHookParams{})
327 if err != nil {
328 return nil, err
329 }
330 clientOpts = append(clientOpts, hookOpts...)
331 }
332
333 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
334 if err != nil {
335 return nil, err
336 }
337 client := ConversionSourcesClient{CallOptions: defaultConversionSourcesCallOptions()}
338
339 c := &conversionSourcesGRPCClient{
340 connPool: connPool,
341 conversionSourcesClient: conversionspb.NewConversionSourcesServiceClient(connPool),
342 CallOptions: &client.CallOptions,
343 logger: internaloption.GetLogger(opts),
344 }
345 c.setGoogleClientInfo()
346
347 client.internalClient = c
348
349 return &client, nil
350 }
351
352 // Connection returns a connection to the API service.
353 //
354 // Deprecated: Connections are now pooled so this method does not always
355 // return the same resource.
356 func (c *conversionSourcesGRPCClient) Connection() *grpc.ClientConn {
357 return c.connPool.Conn()
358 }
359
360 // setGoogleClientInfo sets the name and version of the application in
361 // the `x-goog-api-client` header passed on each request. Intended for
362 // use by Google-written clients.
363 func (c *conversionSourcesGRPCClient) setGoogleClientInfo(keyval ...string) {
364 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
365 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
366 c.xGoogHeaders = []string{
367 "x-goog-api-client", gax.XGoogHeader(kv...),
368 }
369 }
370
371 // Close closes the connection to the API service. The user should invoke this when
372 // the client is no longer required.
373 func (c *conversionSourcesGRPCClient) Close() error {
374 return c.connPool.Close()
375 }
376
377 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
378 type conversionSourcesRESTClient struct {
379 // The http endpoint to connect to.
380 endpoint string
381
382 // The http client.
383 httpClient *http.Client
384
385 // The x-goog-* headers to be sent with each request.
386 xGoogHeaders []string
387
388 // Points back to the CallOptions field of the containing ConversionSourcesClient
389 CallOptions **ConversionSourcesCallOptions
390
391 logger *slog.Logger
392 }
393
394 // NewConversionSourcesRESTClient creates a new conversion sources service rest client.
395 //
396 // Service for managing conversion sources for a merchant account.
397 func NewConversionSourcesRESTClient(ctx context.Context, opts ...option.ClientOption) (*ConversionSourcesClient, error) {
398 clientOpts := append(defaultConversionSourcesRESTClientOptions(), opts...)
399 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
400 if err != nil {
401 return nil, err
402 }
403
404 callOpts := defaultConversionSourcesRESTCallOptions()
405 c := &conversionSourcesRESTClient{
406 endpoint: endpoint,
407 httpClient: httpClient,
408 CallOptions: &callOpts,
409 logger: internaloption.GetLogger(opts),
410 }
411 c.setGoogleClientInfo()
412
413 return &ConversionSourcesClient{internalClient: c, CallOptions: callOpts}, nil
414 }
415
416 func defaultConversionSourcesRESTClientOptions() []option.ClientOption {
417 return []option.ClientOption{
418 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
419 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
420 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
421 internaloption.WithDefaultUniverseDomain("googleapis.com"),
422 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
423 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
424 internaloption.EnableNewAuthLibrary(),
425 }
426 }
427
428 // setGoogleClientInfo sets the name and version of the application in
429 // the `x-goog-api-client` header passed on each request. Intended for
430 // use by Google-written clients.
431 func (c *conversionSourcesRESTClient) setGoogleClientInfo(keyval ...string) {
432 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
433 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
434 c.xGoogHeaders = []string{
435 "x-goog-api-client", gax.XGoogHeader(kv...),
436 }
437 }
438
439 // Close closes the connection to the API service. The user should invoke this when
440 // the client is no longer required.
441 func (c *conversionSourcesRESTClient) Close() error {
442 // Replace httpClient with nil to force cleanup.
443 c.httpClient = nil
444 return nil
445 }
446
447 // Connection returns a connection to the API service.
448 //
449 // Deprecated: This method always returns nil.
450 func (c *conversionSourcesRESTClient) Connection() *grpc.ClientConn {
451 return nil
452 }
453 func (c *conversionSourcesGRPCClient) CreateConversionSource(ctx context.Context, req *conversionspb.CreateConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, 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).CreateConversionSource[0:len((*c.CallOptions).CreateConversionSource):len((*c.CallOptions).CreateConversionSource)], opts...)
459 var resp *conversionspb.ConversionSource
460 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
461 var err error
462 resp, err = executeRPC(ctx, c.conversionSourcesClient.CreateConversionSource, req, settings.GRPC, c.logger, "CreateConversionSource")
463 return err
464 }, opts...)
465 if err != nil {
466 return nil, err
467 }
468 return resp, nil
469 }
470
471 func (c *conversionSourcesGRPCClient) UpdateConversionSource(ctx context.Context, req *conversionspb.UpdateConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
472 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "conversion_source.name", url.QueryEscape(req.GetConversionSource().GetName()))}
473
474 hds = append(c.xGoogHeaders, hds...)
475 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
476 opts = append((*c.CallOptions).UpdateConversionSource[0:len((*c.CallOptions).UpdateConversionSource):len((*c.CallOptions).UpdateConversionSource)], opts...)
477 var resp *conversionspb.ConversionSource
478 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
479 var err error
480 resp, err = executeRPC(ctx, c.conversionSourcesClient.UpdateConversionSource, req, settings.GRPC, c.logger, "UpdateConversionSource")
481 return err
482 }, opts...)
483 if err != nil {
484 return nil, err
485 }
486 return resp, nil
487 }
488
489 func (c *conversionSourcesGRPCClient) DeleteConversionSource(ctx context.Context, req *conversionspb.DeleteConversionSourceRequest, 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).DeleteConversionSource[0:len((*c.CallOptions).DeleteConversionSource):len((*c.CallOptions).DeleteConversionSource)], opts...)
495 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
496 var err error
497 _, err = executeRPC(ctx, c.conversionSourcesClient.DeleteConversionSource, req, settings.GRPC, c.logger, "DeleteConversionSource")
498 return err
499 }, opts...)
500 return err
501 }
502
503 func (c *conversionSourcesGRPCClient) UndeleteConversionSource(ctx context.Context, req *conversionspb.UndeleteConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
504 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
505
506 hds = append(c.xGoogHeaders, hds...)
507 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
508 opts = append((*c.CallOptions).UndeleteConversionSource[0:len((*c.CallOptions).UndeleteConversionSource):len((*c.CallOptions).UndeleteConversionSource)], opts...)
509 var resp *conversionspb.ConversionSource
510 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
511 var err error
512 resp, err = executeRPC(ctx, c.conversionSourcesClient.UndeleteConversionSource, req, settings.GRPC, c.logger, "UndeleteConversionSource")
513 return err
514 }, opts...)
515 if err != nil {
516 return nil, err
517 }
518 return resp, nil
519 }
520
521 func (c *conversionSourcesGRPCClient) GetConversionSource(ctx context.Context, req *conversionspb.GetConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
522 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
523
524 hds = append(c.xGoogHeaders, hds...)
525 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
526 opts = append((*c.CallOptions).GetConversionSource[0:len((*c.CallOptions).GetConversionSource):len((*c.CallOptions).GetConversionSource)], opts...)
527 var resp *conversionspb.ConversionSource
528 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
529 var err error
530 resp, err = executeRPC(ctx, c.conversionSourcesClient.GetConversionSource, req, settings.GRPC, c.logger, "GetConversionSource")
531 return err
532 }, opts...)
533 if err != nil {
534 return nil, err
535 }
536 return resp, nil
537 }
538
539 func (c *conversionSourcesGRPCClient) ListConversionSources(ctx context.Context, req *conversionspb.ListConversionSourcesRequest, opts ...gax.CallOption) *ConversionSourceIterator {
540 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
541
542 hds = append(c.xGoogHeaders, hds...)
543 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
544 opts = append((*c.CallOptions).ListConversionSources[0:len((*c.CallOptions).ListConversionSources):len((*c.CallOptions).ListConversionSources)], opts...)
545 it := &ConversionSourceIterator{}
546 req = proto.Clone(req).(*conversionspb.ListConversionSourcesRequest)
547 it.InternalFetch = func(pageSize int, pageToken string) ([]*conversionspb.ConversionSource, string, error) {
548 resp := &conversionspb.ListConversionSourcesResponse{}
549 if pageToken != "" {
550 req.PageToken = pageToken
551 }
552 if pageSize > math.MaxInt32 {
553 req.PageSize = math.MaxInt32
554 } else if pageSize != 0 {
555 req.PageSize = int32(pageSize)
556 }
557 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
558 var err error
559 resp, err = executeRPC(ctx, c.conversionSourcesClient.ListConversionSources, req, settings.GRPC, c.logger, "ListConversionSources")
560 return err
561 }, opts...)
562 if err != nil {
563 return nil, "", err
564 }
565
566 it.Response = resp
567 return resp.GetConversionSources(), resp.GetNextPageToken(), nil
568 }
569 fetch := func(pageSize int, pageToken string) (string, error) {
570 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
571 if err != nil {
572 return "", err
573 }
574 it.items = append(it.items, items...)
575 return nextPageToken, nil
576 }
577
578 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
579 it.pageInfo.MaxSize = int(req.GetPageSize())
580 it.pageInfo.Token = req.GetPageToken()
581
582 return it
583 }
584
585 // CreateConversionSource creates a new conversion source.
586 func (c *conversionSourcesRESTClient) CreateConversionSource(ctx context.Context, req *conversionspb.CreateConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
587 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
588 body := req.GetConversionSource()
589 jsonReq, err := m.Marshal(body)
590 if err != nil {
591 return nil, err
592 }
593
594 baseUrl, err := url.Parse(c.endpoint)
595 if err != nil {
596 return nil, err
597 }
598 baseUrl.Path += fmt.Sprintf("/conversions/v1/%v/conversionSources", req.GetParent())
599
600 params := url.Values{}
601 params.Add("$alt", "json;enum-encoding=int")
602
603 baseUrl.RawQuery = params.Encode()
604
605 // Build HTTP headers from client and context metadata.
606 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
607
608 hds = append(c.xGoogHeaders, hds...)
609 hds = append(hds, "Content-Type", "application/json")
610 headers := gax.BuildHeaders(ctx, hds...)
611 opts = append((*c.CallOptions).CreateConversionSource[0:len((*c.CallOptions).CreateConversionSource):len((*c.CallOptions).CreateConversionSource)], opts...)
612 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
613 resp := &conversionspb.ConversionSource{}
614 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
615 if settings.Path != "" {
616 baseUrl.Path = settings.Path
617 }
618 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
619 if err != nil {
620 return err
621 }
622 httpReq = httpReq.WithContext(ctx)
623 httpReq.Header = headers
624
625 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateConversionSource")
626 if err != nil {
627 return err
628 }
629
630 if err := unm.Unmarshal(buf, resp); err != nil {
631 return err
632 }
633
634 return nil
635 }, opts...)
636 if e != nil {
637 return nil, e
638 }
639 return resp, nil
640 }
641
642 // UpdateConversionSource updates information of an existing conversion source. Available only for
643 // Merchant Center Destination conversion sources.
644 func (c *conversionSourcesRESTClient) UpdateConversionSource(ctx context.Context, req *conversionspb.UpdateConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
645 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
646 body := req.GetConversionSource()
647 jsonReq, err := m.Marshal(body)
648 if err != nil {
649 return nil, err
650 }
651
652 baseUrl, err := url.Parse(c.endpoint)
653 if err != nil {
654 return nil, err
655 }
656 baseUrl.Path += fmt.Sprintf("/conversions/v1/%v", req.GetConversionSource().GetName())
657
658 params := url.Values{}
659 params.Add("$alt", "json;enum-encoding=int")
660 if req.GetUpdateMask() != nil {
661 field, err := protojson.Marshal(req.GetUpdateMask())
662 if err != nil {
663 return nil, err
664 }
665 params.Add("updateMask", string(field[1:len(field)-1]))
666 }
667
668 baseUrl.RawQuery = params.Encode()
669
670 // Build HTTP headers from client and context metadata.
671 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "conversion_source.name", url.QueryEscape(req.GetConversionSource().GetName()))}
672
673 hds = append(c.xGoogHeaders, hds...)
674 hds = append(hds, "Content-Type", "application/json")
675 headers := gax.BuildHeaders(ctx, hds...)
676 opts = append((*c.CallOptions).UpdateConversionSource[0:len((*c.CallOptions).UpdateConversionSource):len((*c.CallOptions).UpdateConversionSource)], opts...)
677 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
678 resp := &conversionspb.ConversionSource{}
679 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
680 if settings.Path != "" {
681 baseUrl.Path = settings.Path
682 }
683 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
684 if err != nil {
685 return err
686 }
687 httpReq = httpReq.WithContext(ctx)
688 httpReq.Header = headers
689
690 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateConversionSource")
691 if err != nil {
692 return err
693 }
694
695 if err := unm.Unmarshal(buf, resp); err != nil {
696 return err
697 }
698
699 return nil
700 }, opts...)
701 if e != nil {
702 return nil, e
703 }
704 return resp, nil
705 }
706
707 // DeleteConversionSource archives an existing conversion source. If the conversion source is a
708 // Merchant Center Destination, it will be recoverable for 30 days. If the
709 // conversion source is a Google Analytics Link, it will be deleted
710 // immediately and can be restored by creating a new one.
711 func (c *conversionSourcesRESTClient) DeleteConversionSource(ctx context.Context, req *conversionspb.DeleteConversionSourceRequest, opts ...gax.CallOption) error {
712 baseUrl, err := url.Parse(c.endpoint)
713 if err != nil {
714 return err
715 }
716 baseUrl.Path += fmt.Sprintf("/conversions/v1/%v", req.GetName())
717
718 params := url.Values{}
719 params.Add("$alt", "json;enum-encoding=int")
720
721 baseUrl.RawQuery = params.Encode()
722
723 // Build HTTP headers from client and context metadata.
724 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
725
726 hds = append(c.xGoogHeaders, hds...)
727 hds = append(hds, "Content-Type", "application/json")
728 headers := gax.BuildHeaders(ctx, hds...)
729 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
730 if settings.Path != "" {
731 baseUrl.Path = settings.Path
732 }
733 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
734 if err != nil {
735 return err
736 }
737 httpReq = httpReq.WithContext(ctx)
738 httpReq.Header = headers
739
740 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteConversionSource")
741 return err
742 }, opts...)
743 }
744
745 // UndeleteConversionSource re-enables an archived conversion source. Only Available for Merchant
746 // Center Destination conversion sources.
747 func (c *conversionSourcesRESTClient) UndeleteConversionSource(ctx context.Context, req *conversionspb.UndeleteConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
748 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
749 jsonReq, err := m.Marshal(req)
750 if err != nil {
751 return nil, err
752 }
753
754 baseUrl, err := url.Parse(c.endpoint)
755 if err != nil {
756 return nil, err
757 }
758 baseUrl.Path += fmt.Sprintf("/conversions/v1/%v:undelete", req.GetName())
759
760 params := url.Values{}
761 params.Add("$alt", "json;enum-encoding=int")
762
763 baseUrl.RawQuery = params.Encode()
764
765 // Build HTTP headers from client and context metadata.
766 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
767
768 hds = append(c.xGoogHeaders, hds...)
769 hds = append(hds, "Content-Type", "application/json")
770 headers := gax.BuildHeaders(ctx, hds...)
771 opts = append((*c.CallOptions).UndeleteConversionSource[0:len((*c.CallOptions).UndeleteConversionSource):len((*c.CallOptions).UndeleteConversionSource)], opts...)
772 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
773 resp := &conversionspb.ConversionSource{}
774 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
775 if settings.Path != "" {
776 baseUrl.Path = settings.Path
777 }
778 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
779 if err != nil {
780 return err
781 }
782 httpReq = httpReq.WithContext(ctx)
783 httpReq.Header = headers
784
785 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UndeleteConversionSource")
786 if err != nil {
787 return err
788 }
789
790 if err := unm.Unmarshal(buf, resp); err != nil {
791 return err
792 }
793
794 return nil
795 }, opts...)
796 if e != nil {
797 return nil, e
798 }
799 return resp, nil
800 }
801
802 // GetConversionSource fetches a conversion source.
803 func (c *conversionSourcesRESTClient) GetConversionSource(ctx context.Context, req *conversionspb.GetConversionSourceRequest, opts ...gax.CallOption) (*conversionspb.ConversionSource, error) {
804 baseUrl, err := url.Parse(c.endpoint)
805 if err != nil {
806 return nil, err
807 }
808 baseUrl.Path += fmt.Sprintf("/conversions/v1/%v", req.GetName())
809
810 params := url.Values{}
811 params.Add("$alt", "json;enum-encoding=int")
812
813 baseUrl.RawQuery = params.Encode()
814
815 // Build HTTP headers from client and context metadata.
816 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
817
818 hds = append(c.xGoogHeaders, hds...)
819 hds = append(hds, "Content-Type", "application/json")
820 headers := gax.BuildHeaders(ctx, hds...)
821 opts = append((*c.CallOptions).GetConversionSource[0:len((*c.CallOptions).GetConversionSource):len((*c.CallOptions).GetConversionSource)], opts...)
822 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
823 resp := &conversionspb.ConversionSource{}
824 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
825 if settings.Path != "" {
826 baseUrl.Path = settings.Path
827 }
828 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
829 if err != nil {
830 return err
831 }
832 httpReq = httpReq.WithContext(ctx)
833 httpReq.Header = headers
834
835 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetConversionSource")
836 if err != nil {
837 return err
838 }
839
840 if err := unm.Unmarshal(buf, resp); err != nil {
841 return err
842 }
843
844 return nil
845 }, opts...)
846 if e != nil {
847 return nil, e
848 }
849 return resp, nil
850 }
851
852 // ListConversionSources retrieves the list of conversion sources the caller has access to.
853 func (c *conversionSourcesRESTClient) ListConversionSources(ctx context.Context, req *conversionspb.ListConversionSourcesRequest, opts ...gax.CallOption) *ConversionSourceIterator {
854 it := &ConversionSourceIterator{}
855 req = proto.Clone(req).(*conversionspb.ListConversionSourcesRequest)
856 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
857 it.InternalFetch = func(pageSize int, pageToken string) ([]*conversionspb.ConversionSource, string, error) {
858 resp := &conversionspb.ListConversionSourcesResponse{}
859 if pageToken != "" {
860 req.PageToken = pageToken
861 }
862 if pageSize > math.MaxInt32 {
863 req.PageSize = math.MaxInt32
864 } else if pageSize != 0 {
865 req.PageSize = int32(pageSize)
866 }
867 baseUrl, err := url.Parse(c.endpoint)
868 if err != nil {
869 return nil, "", err
870 }
871 baseUrl.Path += fmt.Sprintf("/conversions/v1/%v/conversionSources", req.GetParent())
872
873 params := url.Values{}
874 params.Add("$alt", "json;enum-encoding=int")
875 if req.GetPageSize() != 0 {
876 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
877 }
878 if req.GetPageToken() != "" {
879 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
880 }
881 if req.GetShowDeleted() {
882 params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted()))
883 }
884
885 baseUrl.RawQuery = params.Encode()
886
887 // Build HTTP headers from client and context metadata.
888 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
889 headers := gax.BuildHeaders(ctx, hds...)
890 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
891 if settings.Path != "" {
892 baseUrl.Path = settings.Path
893 }
894 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
895 if err != nil {
896 return err
897 }
898 httpReq.Header = headers
899
900 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListConversionSources")
901 if err != nil {
902 return err
903 }
904 if err := unm.Unmarshal(buf, resp); err != nil {
905 return err
906 }
907
908 return nil
909 }, opts...)
910 if e != nil {
911 return nil, "", e
912 }
913 it.Response = resp
914 return resp.GetConversionSources(), resp.GetNextPageToken(), nil
915 }
916
917 fetch := func(pageSize int, pageToken string) (string, error) {
918 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
919 if err != nil {
920 return "", err
921 }
922 it.items = append(it.items, items...)
923 return nextPageToken, nil
924 }
925
926 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
927 it.pageInfo.MaxSize = int(req.GetPageSize())
928 it.pageInfo.Token = req.GetPageToken()
929
930 return it
931 }