Debian Codegraph @

shopping/merchant/issueresolution/apiv1beta/aggregate_product_statuses_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 issueresolution
18
19 import (
20 "context"
21 "fmt"
22 "log/slog"
23 "math"
24 "net/http"
25 "net/url"
26 "time"
27
28 issueresolutionpb "cloud.google.com/go/shopping/merchant/issueresolution/apiv1beta/issueresolutionpb"
29 gax "github.com/googleapis/gax-go/v2"
30 "google.golang.org/api/iterator"
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/grpc/codes"
37 "google.golang.org/protobuf/encoding/protojson"
38 "google.golang.org/protobuf/proto"
39 )
40
41 var newAggregateProductStatusesClientHook clientHook
42
43 // AggregateProductStatusesCallOptions contains the retry settings for each method of AggregateProductStatusesClient.
44 type AggregateProductStatusesCallOptions struct {
45 ListAggregateProductStatuses []gax.CallOption
46 }
47
48 func defaultAggregateProductStatusesGRPCClientOptions() []option.ClientOption {
49 return []option.ClientOption{
50 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
51 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
52 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
53 internaloption.WithDefaultUniverseDomain("googleapis.com"),
54 internaloption.WithDefaultAudience("https://merchantapi.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 defaultAggregateProductStatusesCallOptions() *AggregateProductStatusesCallOptions {
64 return &AggregateProductStatusesCallOptions{
65 ListAggregateProductStatuses: []gax.CallOption{
66 gax.WithTimeout(60000 * time.Millisecond),
67 gax.WithRetry(func() gax.Retryer {
68 return gax.OnCodes([]codes.Code{
69 codes.Unavailable,
70 }, gax.Backoff{
71 Initial: 1000 * time.Millisecond,
72 Max: 10000 * time.Millisecond,
73 Multiplier: 1.30,
74 })
75 }),
76 },
77 }
78 }
79
80 func defaultAggregateProductStatusesRESTCallOptions() *AggregateProductStatusesCallOptions {
81 return &AggregateProductStatusesCallOptions{
82 ListAggregateProductStatuses: []gax.CallOption{
83 gax.WithTimeout(60000 * time.Millisecond),
84 gax.WithRetry(func() gax.Retryer {
85 return gax.OnHTTPCodes(gax.Backoff{
86 Initial: 1000 * time.Millisecond,
87 Max: 10000 * time.Millisecond,
88 Multiplier: 1.30,
89 },
90 http.StatusServiceUnavailable)
91 }),
92 },
93 }
94 }
95
96 // internalAggregateProductStatusesClient is an interface that defines the methods available from Merchant API.
97 type internalAggregateProductStatusesClient interface {
98 Close() error
99 setGoogleClientInfo(...string)
100 Connection() *grpc.ClientConn
101 ListAggregateProductStatuses(context.Context, *issueresolutionpb.ListAggregateProductStatusesRequest, ...gax.CallOption) *AggregateProductStatusIterator
102 }
103
104 // AggregateProductStatusesClient is a client for interacting with Merchant API.
105 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
106 //
107 // Service to manage aggregate product statuses.
108 type AggregateProductStatusesClient struct {
109 // The internal transport-dependent client.
110 internalClient internalAggregateProductStatusesClient
111
112 // The call options for this service.
113 CallOptions *AggregateProductStatusesCallOptions
114 }
115
116 // Wrapper methods routed to the internal client.
117
118 // Close closes the connection to the API service. The user should invoke this when
119 // the client is no longer required.
120 func (c *AggregateProductStatusesClient) Close() error {
121 return c.internalClient.Close()
122 }
123
124 // setGoogleClientInfo sets the name and version of the application in
125 // the `x-goog-api-client` header passed on each request. Intended for
126 // use by Google-written clients.
127 func (c *AggregateProductStatusesClient) setGoogleClientInfo(keyval ...string) {
128 c.internalClient.setGoogleClientInfo(keyval...)
129 }
130
131 // Connection returns a connection to the API service.
132 //
133 // Deprecated: Connections are now pooled so this method does not always
134 // return the same resource.
135 func (c *AggregateProductStatusesClient) Connection() *grpc.ClientConn {
136 return c.internalClient.Connection()
137 }
138
139 // ListAggregateProductStatuses lists the AggregateProductStatuses resources for your merchant account.
140 // The response might contain fewer items than specified by pageSize.
141 // If pageToken was returned in previous request, it can be used to obtain
142 // additional results.
143 func (c *AggregateProductStatusesClient) ListAggregateProductStatuses(ctx context.Context, req *issueresolutionpb.ListAggregateProductStatusesRequest, opts ...gax.CallOption) *AggregateProductStatusIterator {
144 return c.internalClient.ListAggregateProductStatuses(ctx, req, opts...)
145 }
146
147 // aggregateProductStatusesGRPCClient is a client for interacting with Merchant API over gRPC transport.
148 //
149 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
150 type aggregateProductStatusesGRPCClient struct {
151 // Connection pool of gRPC connections to the service.
152 connPool gtransport.ConnPool
153
154 // Points back to the CallOptions field of the containing AggregateProductStatusesClient
155 CallOptions **AggregateProductStatusesCallOptions
156
157 // The gRPC API client.
158 aggregateProductStatusesClient issueresolutionpb.AggregateProductStatusesServiceClient
159
160 // The x-goog-* metadata to be sent with each request.
161 xGoogHeaders []string
162
163 logger *slog.Logger
164 }
165
166 // NewAggregateProductStatusesClient creates a new aggregate product statuses service client based on gRPC.
167 // The returned client must be Closed when it is done being used to clean up its underlying connections.
168 //
169 // Service to manage aggregate product statuses.
170 func NewAggregateProductStatusesClient(ctx context.Context, opts ...option.ClientOption) (*AggregateProductStatusesClient, error) {
171 clientOpts := defaultAggregateProductStatusesGRPCClientOptions()
172 if newAggregateProductStatusesClientHook != nil {
173 hookOpts, err := newAggregateProductStatusesClientHook(ctx, clientHookParams{})
174 if err != nil {
175 return nil, err
176 }
177 clientOpts = append(clientOpts, hookOpts...)
178 }
179
180 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
181 if err != nil {
182 return nil, err
183 }
184 client := AggregateProductStatusesClient{CallOptions: defaultAggregateProductStatusesCallOptions()}
185
186 c := &aggregateProductStatusesGRPCClient{
187 connPool: connPool,
188 aggregateProductStatusesClient: issueresolutionpb.NewAggregateProductStatusesServiceClient(connPool),
189 CallOptions: &client.CallOptions,
190 logger: internaloption.GetLogger(opts),
191 }
192 c.setGoogleClientInfo()
193
194 client.internalClient = c
195
196 return &client, nil
197 }
198
199 // Connection returns a connection to the API service.
200 //
201 // Deprecated: Connections are now pooled so this method does not always
202 // return the same resource.
203 func (c *aggregateProductStatusesGRPCClient) Connection() *grpc.ClientConn {
204 return c.connPool.Conn()
205 }
206
207 // setGoogleClientInfo sets the name and version of the application in
208 // the `x-goog-api-client` header passed on each request. Intended for
209 // use by Google-written clients.
210 func (c *aggregateProductStatusesGRPCClient) setGoogleClientInfo(keyval ...string) {
211 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
212 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
213 c.xGoogHeaders = []string{
214 "x-goog-api-client", gax.XGoogHeader(kv...),
215 }
216 }
217
218 // Close closes the connection to the API service. The user should invoke this when
219 // the client is no longer required.
220 func (c *aggregateProductStatusesGRPCClient) Close() error {
221 return c.connPool.Close()
222 }
223
224 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
225 type aggregateProductStatusesRESTClient struct {
226 // The http endpoint to connect to.
227 endpoint string
228
229 // The http client.
230 httpClient *http.Client
231
232 // The x-goog-* headers to be sent with each request.
233 xGoogHeaders []string
234
235 // Points back to the CallOptions field of the containing AggregateProductStatusesClient
236 CallOptions **AggregateProductStatusesCallOptions
237
238 logger *slog.Logger
239 }
240
241 // NewAggregateProductStatusesRESTClient creates a new aggregate product statuses service rest client.
242 //
243 // Service to manage aggregate product statuses.
244 func NewAggregateProductStatusesRESTClient(ctx context.Context, opts ...option.ClientOption) (*AggregateProductStatusesClient, error) {
245 clientOpts := append(defaultAggregateProductStatusesRESTClientOptions(), opts...)
246 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
247 if err != nil {
248 return nil, err
249 }
250
251 callOpts := defaultAggregateProductStatusesRESTCallOptions()
252 c := &aggregateProductStatusesRESTClient{
253 endpoint: endpoint,
254 httpClient: httpClient,
255 CallOptions: &callOpts,
256 logger: internaloption.GetLogger(opts),
257 }
258 c.setGoogleClientInfo()
259
260 return &AggregateProductStatusesClient{internalClient: c, CallOptions: callOpts}, nil
261 }
262
263 func defaultAggregateProductStatusesRESTClientOptions() []option.ClientOption {
264 return []option.ClientOption{
265 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
266 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
267 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
268 internaloption.WithDefaultUniverseDomain("googleapis.com"),
269 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
270 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
271 internaloption.EnableNewAuthLibrary(),
272 }
273 }
274
275 // setGoogleClientInfo sets the name and version of the application in
276 // the `x-goog-api-client` header passed on each request. Intended for
277 // use by Google-written clients.
278 func (c *aggregateProductStatusesRESTClient) setGoogleClientInfo(keyval ...string) {
279 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
280 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
281 c.xGoogHeaders = []string{
282 "x-goog-api-client", gax.XGoogHeader(kv...),
283 }
284 }
285
286 // Close closes the connection to the API service. The user should invoke this when
287 // the client is no longer required.
288 func (c *aggregateProductStatusesRESTClient) Close() error {
289 // Replace httpClient with nil to force cleanup.
290 c.httpClient = nil
291 return nil
292 }
293
294 // Connection returns a connection to the API service.
295 //
296 // Deprecated: This method always returns nil.
297 func (c *aggregateProductStatusesRESTClient) Connection() *grpc.ClientConn {
298 return nil
299 }
300 func (c *aggregateProductStatusesGRPCClient) ListAggregateProductStatuses(ctx context.Context, req *issueresolutionpb.ListAggregateProductStatusesRequest, opts ...gax.CallOption) *AggregateProductStatusIterator {
301 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
302
303 hds = append(c.xGoogHeaders, hds...)
304 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
305 opts = append((*c.CallOptions).ListAggregateProductStatuses[0:len((*c.CallOptions).ListAggregateProductStatuses):len((*c.CallOptions).ListAggregateProductStatuses)], opts...)
306 it := &AggregateProductStatusIterator{}
307 req = proto.Clone(req).(*issueresolutionpb.ListAggregateProductStatusesRequest)
308 it.InternalFetch = func(pageSize int, pageToken string) ([]*issueresolutionpb.AggregateProductStatus, string, error) {
309 resp := &issueresolutionpb.ListAggregateProductStatusesResponse{}
310 if pageToken != "" {
311 req.PageToken = pageToken
312 }
313 if pageSize > math.MaxInt32 {
314 req.PageSize = math.MaxInt32
315 } else if pageSize != 0 {
316 req.PageSize = int32(pageSize)
317 }
318 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
319 var err error
320 resp, err = executeRPC(ctx, c.aggregateProductStatusesClient.ListAggregateProductStatuses, req, settings.GRPC, c.logger, "ListAggregateProductStatuses")
321 return err
322 }, opts...)
323 if err != nil {
324 return nil, "", err
325 }
326
327 it.Response = resp
328 return resp.GetAggregateProductStatuses(), resp.GetNextPageToken(), nil
329 }
330 fetch := func(pageSize int, pageToken string) (string, error) {
331 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
332 if err != nil {
333 return "", err
334 }
335 it.items = append(it.items, items...)
336 return nextPageToken, nil
337 }
338
339 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
340 it.pageInfo.MaxSize = int(req.GetPageSize())
341 it.pageInfo.Token = req.GetPageToken()
342
343 return it
344 }
345
346 // ListAggregateProductStatuses lists the AggregateProductStatuses resources for your merchant account.
347 // The response might contain fewer items than specified by pageSize.
348 // If pageToken was returned in previous request, it can be used to obtain
349 // additional results.
350 func (c *aggregateProductStatusesRESTClient) ListAggregateProductStatuses(ctx context.Context, req *issueresolutionpb.ListAggregateProductStatusesRequest, opts ...gax.CallOption) *AggregateProductStatusIterator {
351 it := &AggregateProductStatusIterator{}
352 req = proto.Clone(req).(*issueresolutionpb.ListAggregateProductStatusesRequest)
353 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
354 it.InternalFetch = func(pageSize int, pageToken string) ([]*issueresolutionpb.AggregateProductStatus, string, error) {
355 resp := &issueresolutionpb.ListAggregateProductStatusesResponse{}
356 if pageToken != "" {
357 req.PageToken = pageToken
358 }
359 if pageSize > math.MaxInt32 {
360 req.PageSize = math.MaxInt32
361 } else if pageSize != 0 {
362 req.PageSize = int32(pageSize)
363 }
364 baseUrl, err := url.Parse(c.endpoint)
365 if err != nil {
366 return nil, "", err
367 }
368 baseUrl.Path += fmt.Sprintf("/issueresolution/v1beta/%v/aggregateProductStatuses", req.GetParent())
369
370 params := url.Values{}
371 params.Add("$alt", "json;enum-encoding=int")
372 if req.GetFilter() != "" {
373 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
374 }
375 if req.GetPageSize() != 0 {
376 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
377 }
378 if req.GetPageToken() != "" {
379 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
380 }
381
382 baseUrl.RawQuery = params.Encode()
383
384 // Build HTTP headers from client and context metadata.
385 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
386 headers := gax.BuildHeaders(ctx, hds...)
387 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
388 if settings.Path != "" {
389 baseUrl.Path = settings.Path
390 }
391 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
392 if err != nil {
393 return err
394 }
395 httpReq.Header = headers
396
397 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAggregateProductStatuses")
398 if err != nil {
399 return err
400 }
401 if err := unm.Unmarshal(buf, resp); err != nil {
402 return err
403 }
404
405 return nil
406 }, opts...)
407 if e != nil {
408 return nil, "", e
409 }
410 it.Response = resp
411 return resp.GetAggregateProductStatuses(), resp.GetNextPageToken(), nil
412 }
413
414 fetch := func(pageSize int, pageToken string) (string, error) {
415 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
416 if err != nil {
417 return "", err
418 }
419 it.items = append(it.items, items...)
420 return nextPageToken, nil
421 }
422
423 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
424 it.pageInfo.MaxSize = int(req.GetPageSize())
425 it.pageInfo.Token = req.GetPageToken()
426
427 return it
428 }