Debian Codegraph @

shopping/css/apiv1/css_product_inputs_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 css
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 csspb "cloud.google.com/go/shopping/css/apiv1/csspb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/option"
32 "google.golang.org/api/option/internaloption"
33 gtransport "google.golang.org/api/transport/grpc"
34 httptransport "google.golang.org/api/transport/http"
35 "google.golang.org/grpc"
36 "google.golang.org/protobuf/encoding/protojson"
37 )
38
39 var newCssProductInputsClientHook clientHook
40
41 // CssProductInputsCallOptions contains the retry settings for each method of CssProductInputsClient.
42 type CssProductInputsCallOptions struct {
43 InsertCssProductInput []gax.CallOption
44 UpdateCssProductInput []gax.CallOption
45 DeleteCssProductInput []gax.CallOption
46 }
47
48 func defaultCssProductInputsGRPCClientOptions() []option.ClientOption {
49 return []option.ClientOption{
50 internaloption.WithDefaultEndpoint("css.googleapis.com:443"),
51 internaloption.WithDefaultEndpointTemplate("css.UNIVERSE_DOMAIN:443"),
52 internaloption.WithDefaultMTLSEndpoint("css.mtls.googleapis.com:443"),
53 internaloption.WithDefaultUniverseDomain("googleapis.com"),
54 internaloption.WithDefaultAudience("https://css.googleapis.com/"),
55 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
56 internaloption.EnableJwtWithScope(),
57 internaloption.EnableNewAuthLibrary(),
58 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
59 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
60 }
61 }
62
63 func defaultCssProductInputsCallOptions() *CssProductInputsCallOptions {
64 return &CssProductInputsCallOptions{
65 InsertCssProductInput: []gax.CallOption{
66 gax.WithTimeout(60000 * time.Millisecond),
67 },
68 UpdateCssProductInput: []gax.CallOption{
69 gax.WithTimeout(60000 * time.Millisecond),
70 },
71 DeleteCssProductInput: []gax.CallOption{
72 gax.WithTimeout(60000 * time.Millisecond),
73 },
74 }
75 }
76
77 func defaultCssProductInputsRESTCallOptions() *CssProductInputsCallOptions {
78 return &CssProductInputsCallOptions{
79 InsertCssProductInput: []gax.CallOption{
80 gax.WithTimeout(60000 * time.Millisecond),
81 },
82 UpdateCssProductInput: []gax.CallOption{
83 gax.WithTimeout(60000 * time.Millisecond),
84 },
85 DeleteCssProductInput: []gax.CallOption{
86 gax.WithTimeout(60000 * time.Millisecond),
87 },
88 }
89 }
90
91 // internalCssProductInputsClient is an interface that defines the methods available from CSS API.
92 type internalCssProductInputsClient interface {
93 Close() error
94 setGoogleClientInfo(...string)
95 Connection() *grpc.ClientConn
96 InsertCssProductInput(context.Context, *csspb.InsertCssProductInputRequest, ...gax.CallOption) (*csspb.CssProductInput, error)
97 UpdateCssProductInput(context.Context, *csspb.UpdateCssProductInputRequest, ...gax.CallOption) (*csspb.CssProductInput, error)
98 DeleteCssProductInput(context.Context, *csspb.DeleteCssProductInputRequest, ...gax.CallOption) error
99 }
100
101 // CssProductInputsClient is a client for interacting with CSS API.
102 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
103 //
104 // Service to use CssProductInput resource.
105 // This service helps to insert/update/delete CSS Products.
106 type CssProductInputsClient struct {
107 // The internal transport-dependent client.
108 internalClient internalCssProductInputsClient
109
110 // The call options for this service.
111 CallOptions *CssProductInputsCallOptions
112 }
113
114 // Wrapper methods routed to the internal client.
115
116 // Close closes the connection to the API service. The user should invoke this when
117 // the client is no longer required.
118 func (c *CssProductInputsClient) Close() error {
119 return c.internalClient.Close()
120 }
121
122 // setGoogleClientInfo sets the name and version of the application in
123 // the `x-goog-api-client` header passed on each request. Intended for
124 // use by Google-written clients.
125 func (c *CssProductInputsClient) setGoogleClientInfo(keyval ...string) {
126 c.internalClient.setGoogleClientInfo(keyval...)
127 }
128
129 // Connection returns a connection to the API service.
130 //
131 // Deprecated: Connections are now pooled so this method does not always
132 // return the same resource.
133 func (c *CssProductInputsClient) Connection() *grpc.ClientConn {
134 return c.internalClient.Connection()
135 }
136
137 // InsertCssProductInput uploads a CssProductInput to your CSS Center account. If an
138 // input with the same contentLanguage, identity, feedLabel and feedId already
139 // exists, this method replaces that entry.
140 //
141 // After inserting, updating, or deleting a CSS Product input, it may
142 // take several minutes before the processed CSS Product can be retrieved.
143 func (c *CssProductInputsClient) InsertCssProductInput(ctx context.Context, req *csspb.InsertCssProductInputRequest, opts ...gax.CallOption) (*csspb.CssProductInput, error) {
144 return c.internalClient.InsertCssProductInput(ctx, req, opts...)
145 }
146
147 // UpdateCssProductInput updates the existing Css Product input in your CSS Center account.
148 //
149 // After inserting, updating, or deleting a CSS Product input, it may take
150 // several minutes before the processed Css Product can be retrieved.
151 func (c *CssProductInputsClient) UpdateCssProductInput(ctx context.Context, req *csspb.UpdateCssProductInputRequest, opts ...gax.CallOption) (*csspb.CssProductInput, error) {
152 return c.internalClient.UpdateCssProductInput(ctx, req, opts...)
153 }
154
155 // DeleteCssProductInput deletes a CSS Product input from your CSS Center account.
156 //
157 // After a delete it may take several minutes until the input is no longer
158 // available.
159 func (c *CssProductInputsClient) DeleteCssProductInput(ctx context.Context, req *csspb.DeleteCssProductInputRequest, opts ...gax.CallOption) error {
160 return c.internalClient.DeleteCssProductInput(ctx, req, opts...)
161 }
162
163 // cssProductInputsGRPCClient is a client for interacting with CSS API over gRPC transport.
164 //
165 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
166 type cssProductInputsGRPCClient struct {
167 // Connection pool of gRPC connections to the service.
168 connPool gtransport.ConnPool
169
170 // Points back to the CallOptions field of the containing CssProductInputsClient
171 CallOptions **CssProductInputsCallOptions
172
173 // The gRPC API client.
174 cssProductInputsClient csspb.CssProductInputsServiceClient
175
176 // The x-goog-* metadata to be sent with each request.
177 xGoogHeaders []string
178
179 logger *slog.Logger
180 }
181
182 // NewCssProductInputsClient creates a new css product inputs service client based on gRPC.
183 // The returned client must be Closed when it is done being used to clean up its underlying connections.
184 //
185 // Service to use CssProductInput resource.
186 // This service helps to insert/update/delete CSS Products.
187 func NewCssProductInputsClient(ctx context.Context, opts ...option.ClientOption) (*CssProductInputsClient, error) {
188 clientOpts := defaultCssProductInputsGRPCClientOptions()
189 if newCssProductInputsClientHook != nil {
190 hookOpts, err := newCssProductInputsClientHook(ctx, clientHookParams{})
191 if err != nil {
192 return nil, err
193 }
194 clientOpts = append(clientOpts, hookOpts...)
195 }
196
197 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
198 if err != nil {
199 return nil, err
200 }
201 client := CssProductInputsClient{CallOptions: defaultCssProductInputsCallOptions()}
202
203 c := &cssProductInputsGRPCClient{
204 connPool: connPool,
205 cssProductInputsClient: csspb.NewCssProductInputsServiceClient(connPool),
206 CallOptions: &client.CallOptions,
207 logger: internaloption.GetLogger(opts),
208 }
209 c.setGoogleClientInfo()
210
211 client.internalClient = c
212
213 return &client, nil
214 }
215
216 // Connection returns a connection to the API service.
217 //
218 // Deprecated: Connections are now pooled so this method does not always
219 // return the same resource.
220 func (c *cssProductInputsGRPCClient) Connection() *grpc.ClientConn {
221 return c.connPool.Conn()
222 }
223
224 // setGoogleClientInfo sets the name and version of the application in
225 // the `x-goog-api-client` header passed on each request. Intended for
226 // use by Google-written clients.
227 func (c *cssProductInputsGRPCClient) setGoogleClientInfo(keyval ...string) {
228 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
229 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
230 c.xGoogHeaders = []string{
231 "x-goog-api-client", gax.XGoogHeader(kv...),
232 }
233 }
234
235 // Close closes the connection to the API service. The user should invoke this when
236 // the client is no longer required.
237 func (c *cssProductInputsGRPCClient) Close() error {
238 return c.connPool.Close()
239 }
240
241 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
242 type cssProductInputsRESTClient struct {
243 // The http endpoint to connect to.
244 endpoint string
245
246 // The http client.
247 httpClient *http.Client
248
249 // The x-goog-* headers to be sent with each request.
250 xGoogHeaders []string
251
252 // Points back to the CallOptions field of the containing CssProductInputsClient
253 CallOptions **CssProductInputsCallOptions
254
255 logger *slog.Logger
256 }
257
258 // NewCssProductInputsRESTClient creates a new css product inputs service rest client.
259 //
260 // Service to use CssProductInput resource.
261 // This service helps to insert/update/delete CSS Products.
262 func NewCssProductInputsRESTClient(ctx context.Context, opts ...option.ClientOption) (*CssProductInputsClient, error) {
263 clientOpts := append(defaultCssProductInputsRESTClientOptions(), opts...)
264 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
265 if err != nil {
266 return nil, err
267 }
268
269 callOpts := defaultCssProductInputsRESTCallOptions()
270 c := &cssProductInputsRESTClient{
271 endpoint: endpoint,
272 httpClient: httpClient,
273 CallOptions: &callOpts,
274 logger: internaloption.GetLogger(opts),
275 }
276 c.setGoogleClientInfo()
277
278 return &CssProductInputsClient{internalClient: c, CallOptions: callOpts}, nil
279 }
280
281 func defaultCssProductInputsRESTClientOptions() []option.ClientOption {
282 return []option.ClientOption{
283 internaloption.WithDefaultEndpoint("https://css.googleapis.com"),
284 internaloption.WithDefaultEndpointTemplate("https://css.UNIVERSE_DOMAIN"),
285 internaloption.WithDefaultMTLSEndpoint("https://css.mtls.googleapis.com"),
286 internaloption.WithDefaultUniverseDomain("googleapis.com"),
287 internaloption.WithDefaultAudience("https://css.googleapis.com/"),
288 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
289 internaloption.EnableNewAuthLibrary(),
290 }
291 }
292
293 // setGoogleClientInfo sets the name and version of the application in
294 // the `x-goog-api-client` header passed on each request. Intended for
295 // use by Google-written clients.
296 func (c *cssProductInputsRESTClient) setGoogleClientInfo(keyval ...string) {
297 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
298 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
299 c.xGoogHeaders = []string{
300 "x-goog-api-client", gax.XGoogHeader(kv...),
301 }
302 }
303
304 // Close closes the connection to the API service. The user should invoke this when
305 // the client is no longer required.
306 func (c *cssProductInputsRESTClient) Close() error {
307 // Replace httpClient with nil to force cleanup.
308 c.httpClient = nil
309 return nil
310 }
311
312 // Connection returns a connection to the API service.
313 //
314 // Deprecated: This method always returns nil.
315 func (c *cssProductInputsRESTClient) Connection() *grpc.ClientConn {
316 return nil
317 }
318 func (c *cssProductInputsGRPCClient) InsertCssProductInput(ctx context.Context, req *csspb.InsertCssProductInputRequest, opts ...gax.CallOption) (*csspb.CssProductInput, error) {
319 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
320
321 hds = append(c.xGoogHeaders, hds...)
322 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
323 opts = append((*c.CallOptions).InsertCssProductInput[0:len((*c.CallOptions).InsertCssProductInput):len((*c.CallOptions).InsertCssProductInput)], opts...)
324 var resp *csspb.CssProductInput
325 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
326 var err error
327 resp, err = executeRPC(ctx, c.cssProductInputsClient.InsertCssProductInput, req, settings.GRPC, c.logger, "InsertCssProductInput")
328 return err
329 }, opts...)
330 if err != nil {
331 return nil, err
332 }
333 return resp, nil
334 }
335
336 func (c *cssProductInputsGRPCClient) UpdateCssProductInput(ctx context.Context, req *csspb.UpdateCssProductInputRequest, opts ...gax.CallOption) (*csspb.CssProductInput, error) {
337 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "css_product_input.name", url.QueryEscape(req.GetCssProductInput().GetName()))}
338
339 hds = append(c.xGoogHeaders, hds...)
340 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
341 opts = append((*c.CallOptions).UpdateCssProductInput[0:len((*c.CallOptions).UpdateCssProductInput):len((*c.CallOptions).UpdateCssProductInput)], opts...)
342 var resp *csspb.CssProductInput
343 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
344 var err error
345 resp, err = executeRPC(ctx, c.cssProductInputsClient.UpdateCssProductInput, req, settings.GRPC, c.logger, "UpdateCssProductInput")
346 return err
347 }, opts...)
348 if err != nil {
349 return nil, err
350 }
351 return resp, nil
352 }
353
354 func (c *cssProductInputsGRPCClient) DeleteCssProductInput(ctx context.Context, req *csspb.DeleteCssProductInputRequest, opts ...gax.CallOption) error {
355 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
356
357 hds = append(c.xGoogHeaders, hds...)
358 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
359 opts = append((*c.CallOptions).DeleteCssProductInput[0:len((*c.CallOptions).DeleteCssProductInput):len((*c.CallOptions).DeleteCssProductInput)], opts...)
360 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
361 var err error
362 _, err = executeRPC(ctx, c.cssProductInputsClient.DeleteCssProductInput, req, settings.GRPC, c.logger, "DeleteCssProductInput")
363 return err
364 }, opts...)
365 return err
366 }
367
368 // InsertCssProductInput uploads a CssProductInput to your CSS Center account. If an
369 // input with the same contentLanguage, identity, feedLabel and feedId already
370 // exists, this method replaces that entry.
371 //
372 // After inserting, updating, or deleting a CSS Product input, it may
373 // take several minutes before the processed CSS Product can be retrieved.
374 func (c *cssProductInputsRESTClient) InsertCssProductInput(ctx context.Context, req *csspb.InsertCssProductInputRequest, opts ...gax.CallOption) (*csspb.CssProductInput, error) {
375 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
376 body := req.GetCssProductInput()
377 jsonReq, err := m.Marshal(body)
378 if err != nil {
379 return nil, err
380 }
381
382 baseUrl, err := url.Parse(c.endpoint)
383 if err != nil {
384 return nil, err
385 }
386 baseUrl.Path += fmt.Sprintf("/v1/%v/cssProductInputs:insert", req.GetParent())
387
388 params := url.Values{}
389 params.Add("$alt", "json;enum-encoding=int")
390 if req.GetFeedId() != 0 {
391 params.Add("feedId", fmt.Sprintf("%v", req.GetFeedId()))
392 }
393
394 baseUrl.RawQuery = params.Encode()
395
396 // Build HTTP headers from client and context metadata.
397 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
398
399 hds = append(c.xGoogHeaders, hds...)
400 hds = append(hds, "Content-Type", "application/json")
401 headers := gax.BuildHeaders(ctx, hds...)
402 opts = append((*c.CallOptions).InsertCssProductInput[0:len((*c.CallOptions).InsertCssProductInput):len((*c.CallOptions).InsertCssProductInput)], opts...)
403 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
404 resp := &csspb.CssProductInput{}
405 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
406 if settings.Path != "" {
407 baseUrl.Path = settings.Path
408 }
409 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
410 if err != nil {
411 return err
412 }
413 httpReq = httpReq.WithContext(ctx)
414 httpReq.Header = headers
415
416 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "InsertCssProductInput")
417 if err != nil {
418 return err
419 }
420
421 if err := unm.Unmarshal(buf, resp); err != nil {
422 return err
423 }
424
425 return nil
426 }, opts...)
427 if e != nil {
428 return nil, e
429 }
430 return resp, nil
431 }
432
433 // UpdateCssProductInput updates the existing Css Product input in your CSS Center account.
434 //
435 // After inserting, updating, or deleting a CSS Product input, it may take
436 // several minutes before the processed Css Product can be retrieved.
437 func (c *cssProductInputsRESTClient) UpdateCssProductInput(ctx context.Context, req *csspb.UpdateCssProductInputRequest, opts ...gax.CallOption) (*csspb.CssProductInput, error) {
438 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
439 body := req.GetCssProductInput()
440 jsonReq, err := m.Marshal(body)
441 if err != nil {
442 return nil, err
443 }
444
445 baseUrl, err := url.Parse(c.endpoint)
446 if err != nil {
447 return nil, err
448 }
449 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetCssProductInput().GetName())
450
451 params := url.Values{}
452 params.Add("$alt", "json;enum-encoding=int")
453 if req.GetUpdateMask() != nil {
454 field, err := protojson.Marshal(req.GetUpdateMask())
455 if err != nil {
456 return nil, err
457 }
458 params.Add("updateMask", string(field[1:len(field)-1]))
459 }
460
461 baseUrl.RawQuery = params.Encode()
462
463 // Build HTTP headers from client and context metadata.
464 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "css_product_input.name", url.QueryEscape(req.GetCssProductInput().GetName()))}
465
466 hds = append(c.xGoogHeaders, hds...)
467 hds = append(hds, "Content-Type", "application/json")
468 headers := gax.BuildHeaders(ctx, hds...)
469 opts = append((*c.CallOptions).UpdateCssProductInput[0:len((*c.CallOptions).UpdateCssProductInput):len((*c.CallOptions).UpdateCssProductInput)], opts...)
470 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
471 resp := &csspb.CssProductInput{}
472 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
473 if settings.Path != "" {
474 baseUrl.Path = settings.Path
475 }
476 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
477 if err != nil {
478 return err
479 }
480 httpReq = httpReq.WithContext(ctx)
481 httpReq.Header = headers
482
483 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateCssProductInput")
484 if err != nil {
485 return err
486 }
487
488 if err := unm.Unmarshal(buf, resp); err != nil {
489 return err
490 }
491
492 return nil
493 }, opts...)
494 if e != nil {
495 return nil, e
496 }
497 return resp, nil
498 }
499
500 // DeleteCssProductInput deletes a CSS Product input from your CSS Center account.
501 //
502 // After a delete it may take several minutes until the input is no longer
503 // available.
504 func (c *cssProductInputsRESTClient) DeleteCssProductInput(ctx context.Context, req *csspb.DeleteCssProductInputRequest, opts ...gax.CallOption) error {
505 baseUrl, err := url.Parse(c.endpoint)
506 if err != nil {
507 return err
508 }
509 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
510
511 params := url.Values{}
512 params.Add("$alt", "json;enum-encoding=int")
513 if req != nil && req.SupplementalFeedId != nil {
514 params.Add("supplementalFeedId", fmt.Sprintf("%v", req.GetSupplementalFeedId()))
515 }
516
517 baseUrl.RawQuery = params.Encode()
518
519 // Build HTTP headers from client and context metadata.
520 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
521
522 hds = append(c.xGoogHeaders, hds...)
523 hds = append(hds, "Content-Type", "application/json")
524 headers := gax.BuildHeaders(ctx, hds...)
525 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
526 if settings.Path != "" {
527 baseUrl.Path = settings.Path
528 }
529 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
530 if err != nil {
531 return err
532 }
533 httpReq = httpReq.WithContext(ctx)
534 httpReq.Header = headers
535
536 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteCssProductInput")
537 return err
538 }, opts...)
539 }