Debian Codegraph @

shopping/merchant/reviews/apiv1beta/product_reviews_client.go

raw symbols SCIP
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 reviews
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 reviewspb "cloud.google.com/go/shopping/merchant/reviews/apiv1beta/reviewspb"
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 newProductReviewsClientHook clientHook
43
44 // ProductReviewsCallOptions contains the retry settings for each method of ProductReviewsClient.
45 type ProductReviewsCallOptions struct {
46 GetProductReview []gax.CallOption
47 ListProductReviews []gax.CallOption
48 InsertProductReview []gax.CallOption
49 DeleteProductReview []gax.CallOption
50 }
51
52 func defaultProductReviewsGRPCClientOptions() []option.ClientOption {
53 return []option.ClientOption{
54 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
55 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
56 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
57 internaloption.WithDefaultUniverseDomain("googleapis.com"),
58 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
59 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
60 internaloption.EnableJwtWithScope(),
61 internaloption.EnableNewAuthLibrary(),
62 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
63 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
64 }
65 }
66
67 func defaultProductReviewsCallOptions() *ProductReviewsCallOptions {
68 return &ProductReviewsCallOptions{
69 GetProductReview: []gax.CallOption{
70 gax.WithTimeout(60000 * time.Millisecond),
71 gax.WithRetry(func() gax.Retryer {
72 return gax.OnCodes([]codes.Code{
73 codes.Unavailable,
74 }, gax.Backoff{
75 Initial: 1000 * time.Millisecond,
76 Max: 10000 * time.Millisecond,
77 Multiplier: 1.30,
78 })
79 }),
80 },
81 ListProductReviews: []gax.CallOption{
82 gax.WithTimeout(60000 * time.Millisecond),
83 gax.WithRetry(func() gax.Retryer {
84 return gax.OnCodes([]codes.Code{
85 codes.Unavailable,
86 }, gax.Backoff{
87 Initial: 1000 * time.Millisecond,
88 Max: 10000 * time.Millisecond,
89 Multiplier: 1.30,
90 })
91 }),
92 },
93 InsertProductReview: []gax.CallOption{
94 gax.WithTimeout(60000 * time.Millisecond),
95 gax.WithRetry(func() gax.Retryer {
96 return gax.OnCodes([]codes.Code{
97 codes.Unavailable,
98 }, gax.Backoff{
99 Initial: 1000 * time.Millisecond,
100 Max: 10000 * time.Millisecond,
101 Multiplier: 1.30,
102 })
103 }),
104 },
105 DeleteProductReview: []gax.CallOption{
106 gax.WithTimeout(60000 * time.Millisecond),
107 gax.WithRetry(func() gax.Retryer {
108 return gax.OnCodes([]codes.Code{
109 codes.Unavailable,
110 }, gax.Backoff{
111 Initial: 1000 * time.Millisecond,
112 Max: 10000 * time.Millisecond,
113 Multiplier: 1.30,
114 })
115 }),
116 },
117 }
118 }
119
120 func defaultProductReviewsRESTCallOptions() *ProductReviewsCallOptions {
121 return &ProductReviewsCallOptions{
122 GetProductReview: []gax.CallOption{
123 gax.WithTimeout(60000 * time.Millisecond),
124 gax.WithRetry(func() gax.Retryer {
125 return gax.OnHTTPCodes(gax.Backoff{
126 Initial: 1000 * time.Millisecond,
127 Max: 10000 * time.Millisecond,
128 Multiplier: 1.30,
129 },
130 http.StatusServiceUnavailable)
131 }),
132 },
133 ListProductReviews: []gax.CallOption{
134 gax.WithTimeout(60000 * time.Millisecond),
135 gax.WithRetry(func() gax.Retryer {
136 return gax.OnHTTPCodes(gax.Backoff{
137 Initial: 1000 * time.Millisecond,
138 Max: 10000 * time.Millisecond,
139 Multiplier: 1.30,
140 },
141 http.StatusServiceUnavailable)
142 }),
143 },
144 InsertProductReview: []gax.CallOption{
145 gax.WithTimeout(60000 * time.Millisecond),
146 gax.WithRetry(func() gax.Retryer {
147 return gax.OnHTTPCodes(gax.Backoff{
148 Initial: 1000 * time.Millisecond,
149 Max: 10000 * time.Millisecond,
150 Multiplier: 1.30,
151 },
152 http.StatusServiceUnavailable)
153 }),
154 },
155 DeleteProductReview: []gax.CallOption{
156 gax.WithTimeout(60000 * time.Millisecond),
157 gax.WithRetry(func() gax.Retryer {
158 return gax.OnHTTPCodes(gax.Backoff{
159 Initial: 1000 * time.Millisecond,
160 Max: 10000 * time.Millisecond,
161 Multiplier: 1.30,
162 },
163 http.StatusServiceUnavailable)
164 }),
165 },
166 }
167 }
168
169 // internalProductReviewsClient is an interface that defines the methods available from Merchant API.
170 type internalProductReviewsClient interface {
171 Close() error
172 setGoogleClientInfo(...string)
173 Connection() *grpc.ClientConn
174 GetProductReview(context.Context, *reviewspb.GetProductReviewRequest, ...gax.CallOption) (*reviewspb.ProductReview, error)
175 ListProductReviews(context.Context, *reviewspb.ListProductReviewsRequest, ...gax.CallOption) *ProductReviewIterator
176 InsertProductReview(context.Context, *reviewspb.InsertProductReviewRequest, ...gax.CallOption) (*reviewspb.ProductReview, error)
177 DeleteProductReview(context.Context, *reviewspb.DeleteProductReviewRequest, ...gax.CallOption) error
178 }
179
180 // ProductReviewsClient is a client for interacting with Merchant API.
181 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
182 //
183 // Service to manage product reviews.
184 type ProductReviewsClient struct {
185 // The internal transport-dependent client.
186 internalClient internalProductReviewsClient
187
188 // The call options for this service.
189 CallOptions *ProductReviewsCallOptions
190 }
191
192 // Wrapper methods routed to the internal client.
193
194 // Close closes the connection to the API service. The user should invoke this when
195 // the client is no longer required.
196 func (c *ProductReviewsClient) Close() error {
197 return c.internalClient.Close()
198 }
199
200 // setGoogleClientInfo sets the name and version of the application in
201 // the `x-goog-api-client` header passed on each request. Intended for
202 // use by Google-written clients.
203 func (c *ProductReviewsClient) setGoogleClientInfo(keyval ...string) {
204 c.internalClient.setGoogleClientInfo(keyval...)
205 }
206
207 // Connection returns a connection to the API service.
208 //
209 // Deprecated: Connections are now pooled so this method does not always
210 // return the same resource.
211 func (c *ProductReviewsClient) Connection() *grpc.ClientConn {
212 return c.internalClient.Connection()
213 }
214
215 // GetProductReview gets a product review.
216 func (c *ProductReviewsClient) GetProductReview(ctx context.Context, req *reviewspb.GetProductReviewRequest, opts ...gax.CallOption) (*reviewspb.ProductReview, error) {
217 return c.internalClient.GetProductReview(ctx, req, opts...)
218 }
219
220 // ListProductReviews lists product reviews.
221 func (c *ProductReviewsClient) ListProductReviews(ctx context.Context, req *reviewspb.ListProductReviewsRequest, opts ...gax.CallOption) *ProductReviewIterator {
222 return c.internalClient.ListProductReviews(ctx, req, opts...)
223 }
224
225 // InsertProductReview inserts a product review.
226 func (c *ProductReviewsClient) InsertProductReview(ctx context.Context, req *reviewspb.InsertProductReviewRequest, opts ...gax.CallOption) (*reviewspb.ProductReview, error) {
227 return c.internalClient.InsertProductReview(ctx, req, opts...)
228 }
229
230 // DeleteProductReview deletes a product review.
231 func (c *ProductReviewsClient) DeleteProductReview(ctx context.Context, req *reviewspb.DeleteProductReviewRequest, opts ...gax.CallOption) error {
232 return c.internalClient.DeleteProductReview(ctx, req, opts...)
233 }
234
235 // productReviewsGRPCClient is a client for interacting with Merchant API over gRPC transport.
236 //
237 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
238 type productReviewsGRPCClient struct {
239 // Connection pool of gRPC connections to the service.
240 connPool gtransport.ConnPool
241
242 // Points back to the CallOptions field of the containing ProductReviewsClient
243 CallOptions **ProductReviewsCallOptions
244
245 // The gRPC API client.
246 productReviewsClient reviewspb.ProductReviewsServiceClient
247
248 // The x-goog-* metadata to be sent with each request.
249 xGoogHeaders []string
250
251 logger *slog.Logger
252 }
253
254 // NewProductReviewsClient creates a new product reviews service client based on gRPC.
255 // The returned client must be Closed when it is done being used to clean up its underlying connections.
256 //
257 // Service to manage product reviews.
258 func NewProductReviewsClient(ctx context.Context, opts ...option.ClientOption) (*ProductReviewsClient, error) {
259 clientOpts := defaultProductReviewsGRPCClientOptions()
260 if newProductReviewsClientHook != nil {
261 hookOpts, err := newProductReviewsClientHook(ctx, clientHookParams{})
262 if err != nil {
263 return nil, err
264 }
265 clientOpts = append(clientOpts, hookOpts...)
266 }
267
268 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
269 if err != nil {
270 return nil, err
271 }
272 client := ProductReviewsClient{CallOptions: defaultProductReviewsCallOptions()}
273
274 c := &productReviewsGRPCClient{
275 connPool: connPool,
276 productReviewsClient: reviewspb.NewProductReviewsServiceClient(connPool),
277 CallOptions: &client.CallOptions,
278 logger: internaloption.GetLogger(opts),
279 }
280 c.setGoogleClientInfo()
281
282 client.internalClient = c
283
284 return &client, nil
285 }
286
287 // Connection returns a connection to the API service.
288 //
289 // Deprecated: Connections are now pooled so this method does not always
290 // return the same resource.
291 func (c *productReviewsGRPCClient) Connection() *grpc.ClientConn {
292 return c.connPool.Conn()
293 }
294
295 // setGoogleClientInfo sets the name and version of the application in
296 // the `x-goog-api-client` header passed on each request. Intended for
297 // use by Google-written clients.
298 func (c *productReviewsGRPCClient) setGoogleClientInfo(keyval ...string) {
299 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
300 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
301 c.xGoogHeaders = []string{
302 "x-goog-api-client", gax.XGoogHeader(kv...),
303 }
304 }
305
306 // Close closes the connection to the API service. The user should invoke this when
307 // the client is no longer required.
308 func (c *productReviewsGRPCClient) Close() error {
309 return c.connPool.Close()
310 }
311
312 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
313 type productReviewsRESTClient struct {
314 // The http endpoint to connect to.
315 endpoint string
316
317 // The http client.
318 httpClient *http.Client
319
320 // The x-goog-* headers to be sent with each request.
321 xGoogHeaders []string
322
323 // Points back to the CallOptions field of the containing ProductReviewsClient
324 CallOptions **ProductReviewsCallOptions
325
326 logger *slog.Logger
327 }
328
329 // NewProductReviewsRESTClient creates a new product reviews service rest client.
330 //
331 // Service to manage product reviews.
332 func NewProductReviewsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ProductReviewsClient, error) {
333 clientOpts := append(defaultProductReviewsRESTClientOptions(), opts...)
334 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
335 if err != nil {
336 return nil, err
337 }
338
339 callOpts := defaultProductReviewsRESTCallOptions()
340 c := &productReviewsRESTClient{
341 endpoint: endpoint,
342 httpClient: httpClient,
343 CallOptions: &callOpts,
344 logger: internaloption.GetLogger(opts),
345 }
346 c.setGoogleClientInfo()
347
348 return &ProductReviewsClient{internalClient: c, CallOptions: callOpts}, nil
349 }
350
351 func defaultProductReviewsRESTClientOptions() []option.ClientOption {
352 return []option.ClientOption{
353 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
354 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
355 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
356 internaloption.WithDefaultUniverseDomain("googleapis.com"),
357 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
358 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
359 internaloption.EnableNewAuthLibrary(),
360 }
361 }
362
363 // setGoogleClientInfo sets the name and version of the application in
364 // the `x-goog-api-client` header passed on each request. Intended for
365 // use by Google-written clients.
366 func (c *productReviewsRESTClient) setGoogleClientInfo(keyval ...string) {
367 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
368 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
369 c.xGoogHeaders = []string{
370 "x-goog-api-client", gax.XGoogHeader(kv...),
371 }
372 }
373
374 // Close closes the connection to the API service. The user should invoke this when
375 // the client is no longer required.
376 func (c *productReviewsRESTClient) Close() error {
377 // Replace httpClient with nil to force cleanup.
378 c.httpClient = nil
379 return nil
380 }
381
382 // Connection returns a connection to the API service.
383 //
384 // Deprecated: This method always returns nil.
385 func (c *productReviewsRESTClient) Connection() *grpc.ClientConn {
386 return nil
387 }
388 func (c *productReviewsGRPCClient) GetProductReview(ctx context.Context, req *reviewspb.GetProductReviewRequest, opts ...gax.CallOption) (*reviewspb.ProductReview, error) {
389 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
390
391 hds = append(c.xGoogHeaders, hds...)
392 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
393 opts = append((*c.CallOptions).GetProductReview[0:len((*c.CallOptions).GetProductReview):len((*c.CallOptions).GetProductReview)], opts...)
394 var resp *reviewspb.ProductReview
395 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
396 var err error
397 resp, err = executeRPC(ctx, c.productReviewsClient.GetProductReview, req, settings.GRPC, c.logger, "GetProductReview")
398 return err
399 }, opts...)
400 if err != nil {
401 return nil, err
402 }
403 return resp, nil
404 }
405
406 func (c *productReviewsGRPCClient) ListProductReviews(ctx context.Context, req *reviewspb.ListProductReviewsRequest, opts ...gax.CallOption) *ProductReviewIterator {
407 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
408
409 hds = append(c.xGoogHeaders, hds...)
410 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
411 opts = append((*c.CallOptions).ListProductReviews[0:len((*c.CallOptions).ListProductReviews):len((*c.CallOptions).ListProductReviews)], opts...)
412 it := &ProductReviewIterator{}
413 req = proto.Clone(req).(*reviewspb.ListProductReviewsRequest)
414 it.InternalFetch = func(pageSize int, pageToken string) ([]*reviewspb.ProductReview, string, error) {
415 resp := &reviewspb.ListProductReviewsResponse{}
416 if pageToken != "" {
417 req.PageToken = pageToken
418 }
419 if pageSize > math.MaxInt32 {
420 req.PageSize = math.MaxInt32
421 } else if pageSize != 0 {
422 req.PageSize = int32(pageSize)
423 }
424 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
425 var err error
426 resp, err = executeRPC(ctx, c.productReviewsClient.ListProductReviews, req, settings.GRPC, c.logger, "ListProductReviews")
427 return err
428 }, opts...)
429 if err != nil {
430 return nil, "", err
431 }
432
433 it.Response = resp
434 return resp.GetProductReviews(), resp.GetNextPageToken(), nil
435 }
436 fetch := func(pageSize int, pageToken string) (string, error) {
437 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
438 if err != nil {
439 return "", err
440 }
441 it.items = append(it.items, items...)
442 return nextPageToken, nil
443 }
444
445 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
446 it.pageInfo.MaxSize = int(req.GetPageSize())
447 it.pageInfo.Token = req.GetPageToken()
448
449 return it
450 }
451
452 func (c *productReviewsGRPCClient) InsertProductReview(ctx context.Context, req *reviewspb.InsertProductReviewRequest, opts ...gax.CallOption) (*reviewspb.ProductReview, error) {
453 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
454
455 hds = append(c.xGoogHeaders, hds...)
456 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
457 opts = append((*c.CallOptions).InsertProductReview[0:len((*c.CallOptions).InsertProductReview):len((*c.CallOptions).InsertProductReview)], opts...)
458 var resp *reviewspb.ProductReview
459 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
460 var err error
461 resp, err = executeRPC(ctx, c.productReviewsClient.InsertProductReview, req, settings.GRPC, c.logger, "InsertProductReview")
462 return err
463 }, opts...)
464 if err != nil {
465 return nil, err
466 }
467 return resp, nil
468 }
469
470 func (c *productReviewsGRPCClient) DeleteProductReview(ctx context.Context, req *reviewspb.DeleteProductReviewRequest, opts ...gax.CallOption) error {
471 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
472
473 hds = append(c.xGoogHeaders, hds...)
474 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
475 opts = append((*c.CallOptions).DeleteProductReview[0:len((*c.CallOptions).DeleteProductReview):len((*c.CallOptions).DeleteProductReview)], opts...)
476 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
477 var err error
478 _, err = executeRPC(ctx, c.productReviewsClient.DeleteProductReview, req, settings.GRPC, c.logger, "DeleteProductReview")
479 return err
480 }, opts...)
481 return err
482 }
483
484 // GetProductReview gets a product review.
485 func (c *productReviewsRESTClient) GetProductReview(ctx context.Context, req *reviewspb.GetProductReviewRequest, opts ...gax.CallOption) (*reviewspb.ProductReview, error) {
486 baseUrl, err := url.Parse(c.endpoint)
487 if err != nil {
488 return nil, err
489 }
490 baseUrl.Path += fmt.Sprintf("/reviews/v1beta/%v", req.GetName())
491
492 params := url.Values{}
493 params.Add("$alt", "json;enum-encoding=int")
494
495 baseUrl.RawQuery = params.Encode()
496
497 // Build HTTP headers from client and context metadata.
498 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
499
500 hds = append(c.xGoogHeaders, hds...)
501 hds = append(hds, "Content-Type", "application/json")
502 headers := gax.BuildHeaders(ctx, hds...)
503 opts = append((*c.CallOptions).GetProductReview[0:len((*c.CallOptions).GetProductReview):len((*c.CallOptions).GetProductReview)], opts...)
504 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
505 resp := &reviewspb.ProductReview{}
506 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
507 if settings.Path != "" {
508 baseUrl.Path = settings.Path
509 }
510 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
511 if err != nil {
512 return err
513 }
514 httpReq = httpReq.WithContext(ctx)
515 httpReq.Header = headers
516
517 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetProductReview")
518 if err != nil {
519 return err
520 }
521
522 if err := unm.Unmarshal(buf, resp); err != nil {
523 return err
524 }
525
526 return nil
527 }, opts...)
528 if e != nil {
529 return nil, e
530 }
531 return resp, nil
532 }
533
534 // ListProductReviews lists product reviews.
535 func (c *productReviewsRESTClient) ListProductReviews(ctx context.Context, req *reviewspb.ListProductReviewsRequest, opts ...gax.CallOption) *ProductReviewIterator {
536 it := &ProductReviewIterator{}
537 req = proto.Clone(req).(*reviewspb.ListProductReviewsRequest)
538 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
539 it.InternalFetch = func(pageSize int, pageToken string) ([]*reviewspb.ProductReview, string, error) {
540 resp := &reviewspb.ListProductReviewsResponse{}
541 if pageToken != "" {
542 req.PageToken = pageToken
543 }
544 if pageSize > math.MaxInt32 {
545 req.PageSize = math.MaxInt32
546 } else if pageSize != 0 {
547 req.PageSize = int32(pageSize)
548 }
549 baseUrl, err := url.Parse(c.endpoint)
550 if err != nil {
551 return nil, "", err
552 }
553 baseUrl.Path += fmt.Sprintf("/reviews/v1beta/%v/productReviews", req.GetParent())
554
555 params := url.Values{}
556 params.Add("$alt", "json;enum-encoding=int")
557 if req.GetPageSize() != 0 {
558 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
559 }
560 if req.GetPageToken() != "" {
561 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
562 }
563
564 baseUrl.RawQuery = params.Encode()
565
566 // Build HTTP headers from client and context metadata.
567 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
568 headers := gax.BuildHeaders(ctx, hds...)
569 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
570 if settings.Path != "" {
571 baseUrl.Path = settings.Path
572 }
573 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
574 if err != nil {
575 return err
576 }
577 httpReq.Header = headers
578
579 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListProductReviews")
580 if err != nil {
581 return err
582 }
583 if err := unm.Unmarshal(buf, resp); err != nil {
584 return err
585 }
586
587 return nil
588 }, opts...)
589 if e != nil {
590 return nil, "", e
591 }
592 it.Response = resp
593 return resp.GetProductReviews(), resp.GetNextPageToken(), nil
594 }
595
596 fetch := func(pageSize int, pageToken string) (string, error) {
597 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
598 if err != nil {
599 return "", err
600 }
601 it.items = append(it.items, items...)
602 return nextPageToken, nil
603 }
604
605 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
606 it.pageInfo.MaxSize = int(req.GetPageSize())
607 it.pageInfo.Token = req.GetPageToken()
608
609 return it
610 }
611
612 // InsertProductReview inserts a product review.
613 func (c *productReviewsRESTClient) InsertProductReview(ctx context.Context, req *reviewspb.InsertProductReviewRequest, opts ...gax.CallOption) (*reviewspb.ProductReview, error) {
614 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
615 body := req.GetProductReview()
616 jsonReq, err := m.Marshal(body)
617 if err != nil {
618 return nil, err
619 }
620
621 baseUrl, err := url.Parse(c.endpoint)
622 if err != nil {
623 return nil, err
624 }
625 baseUrl.Path += fmt.Sprintf("/reviews/v1beta/%v/productReviews:insert", req.GetParent())
626
627 params := url.Values{}
628 params.Add("$alt", "json;enum-encoding=int")
629 params.Add("dataSource", fmt.Sprintf("%v", req.GetDataSource()))
630
631 baseUrl.RawQuery = params.Encode()
632
633 // Build HTTP headers from client and context metadata.
634 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
635
636 hds = append(c.xGoogHeaders, hds...)
637 hds = append(hds, "Content-Type", "application/json")
638 headers := gax.BuildHeaders(ctx, hds...)
639 opts = append((*c.CallOptions).InsertProductReview[0:len((*c.CallOptions).InsertProductReview):len((*c.CallOptions).InsertProductReview)], opts...)
640 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
641 resp := &reviewspb.ProductReview{}
642 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
643 if settings.Path != "" {
644 baseUrl.Path = settings.Path
645 }
646 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
647 if err != nil {
648 return err
649 }
650 httpReq = httpReq.WithContext(ctx)
651 httpReq.Header = headers
652
653 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "InsertProductReview")
654 if err != nil {
655 return err
656 }
657
658 if err := unm.Unmarshal(buf, resp); err != nil {
659 return err
660 }
661
662 return nil
663 }, opts...)
664 if e != nil {
665 return nil, e
666 }
667 return resp, nil
668 }
669
670 // DeleteProductReview deletes a product review.
671 func (c *productReviewsRESTClient) DeleteProductReview(ctx context.Context, req *reviewspb.DeleteProductReviewRequest, opts ...gax.CallOption) error {
672 baseUrl, err := url.Parse(c.endpoint)
673 if err != nil {
674 return err
675 }
676 baseUrl.Path += fmt.Sprintf("/reviews/v1beta/%v", req.GetName())
677
678 params := url.Values{}
679 params.Add("$alt", "json;enum-encoding=int")
680
681 baseUrl.RawQuery = params.Encode()
682
683 // Build HTTP headers from client and context metadata.
684 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
685
686 hds = append(c.xGoogHeaders, hds...)
687 hds = append(hds, "Content-Type", "application/json")
688 headers := gax.BuildHeaders(ctx, hds...)
689 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
690 if settings.Path != "" {
691 baseUrl.Path = settings.Path
692 }
693 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
694 if err != nil {
695 return err
696 }
697 httpReq = httpReq.WithContext(ctx)
698 httpReq.Header = headers
699
700 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteProductReview")
701 return err
702 }, opts...)
703 }