Debian Codegraph @

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