Debian Codegraph @

shopping/merchant/accounts/apiv1/account_issue_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 accounts
18
19 import (
20 "context"
21 "fmt"
22 "log/slog"
23 "math"
24 "net/http"
25 "net/url"
26 "time"
27
28 accountspb "cloud.google.com/go/shopping/merchant/accounts/apiv1/accountspb"
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 newAccountIssueClientHook clientHook
42
43 // AccountIssueCallOptions contains the retry settings for each method of AccountIssueClient.
44 type AccountIssueCallOptions struct {
45 ListAccountIssues []gax.CallOption
46 }
47
48 func defaultAccountIssueGRPCClientOptions() []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 defaultAccountIssueCallOptions() *AccountIssueCallOptions {
64 return &AccountIssueCallOptions{
65 ListAccountIssues: []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 defaultAccountIssueRESTCallOptions() *AccountIssueCallOptions {
81 return &AccountIssueCallOptions{
82 ListAccountIssues: []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 // internalAccountIssueClient is an interface that defines the methods available from Merchant API.
97 type internalAccountIssueClient interface {
98 Close() error
99 setGoogleClientInfo(...string)
100 Connection() *grpc.ClientConn
101 ListAccountIssues(context.Context, *accountspb.ListAccountIssuesRequest, ...gax.CallOption) *AccountIssueIterator
102 }
103
104 // AccountIssueClient 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 support AccountIssueService API.
108 type AccountIssueClient struct {
109 // The internal transport-dependent client.
110 internalClient internalAccountIssueClient
111
112 // The call options for this service.
113 CallOptions *AccountIssueCallOptions
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 *AccountIssueClient) 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 *AccountIssueClient) 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 *AccountIssueClient) Connection() *grpc.ClientConn {
136 return c.internalClient.Connection()
137 }
138
139 // ListAccountIssues lists all account issues of a Merchant Center account.
140 //
141 // When called on a multi-client account, this method only returns issues
142 // belonging to that account, not its sub-accounts. To retrieve issues for
143 // sub-accounts, you must first call the
144 // accounts.listSubaccounts
145 // method to obtain a list of sub-accounts, and then call
146 // accounts.issues.list for each sub-account individually.
147 func (c *AccountIssueClient) ListAccountIssues(ctx context.Context, req *accountspb.ListAccountIssuesRequest, opts ...gax.CallOption) *AccountIssueIterator {
148 return c.internalClient.ListAccountIssues(ctx, req, opts...)
149 }
150
151 // accountIssueGRPCClient is a client for interacting with Merchant API over gRPC transport.
152 //
153 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
154 type accountIssueGRPCClient struct {
155 // Connection pool of gRPC connections to the service.
156 connPool gtransport.ConnPool
157
158 // Points back to the CallOptions field of the containing AccountIssueClient
159 CallOptions **AccountIssueCallOptions
160
161 // The gRPC API client.
162 accountIssueClient accountspb.AccountIssueServiceClient
163
164 // The x-goog-* metadata to be sent with each request.
165 xGoogHeaders []string
166
167 logger *slog.Logger
168 }
169
170 // NewAccountIssueClient creates a new account issue service client based on gRPC.
171 // The returned client must be Closed when it is done being used to clean up its underlying connections.
172 //
173 // Service to support AccountIssueService API.
174 func NewAccountIssueClient(ctx context.Context, opts ...option.ClientOption) (*AccountIssueClient, error) {
175 clientOpts := defaultAccountIssueGRPCClientOptions()
176 if newAccountIssueClientHook != nil {
177 hookOpts, err := newAccountIssueClientHook(ctx, clientHookParams{})
178 if err != nil {
179 return nil, err
180 }
181 clientOpts = append(clientOpts, hookOpts...)
182 }
183
184 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
185 if err != nil {
186 return nil, err
187 }
188 client := AccountIssueClient{CallOptions: defaultAccountIssueCallOptions()}
189
190 c := &accountIssueGRPCClient{
191 connPool: connPool,
192 accountIssueClient: accountspb.NewAccountIssueServiceClient(connPool),
193 CallOptions: &client.CallOptions,
194 logger: internaloption.GetLogger(opts),
195 }
196 c.setGoogleClientInfo()
197
198 client.internalClient = c
199
200 return &client, nil
201 }
202
203 // Connection returns a connection to the API service.
204 //
205 // Deprecated: Connections are now pooled so this method does not always
206 // return the same resource.
207 func (c *accountIssueGRPCClient) Connection() *grpc.ClientConn {
208 return c.connPool.Conn()
209 }
210
211 // setGoogleClientInfo sets the name and version of the application in
212 // the `x-goog-api-client` header passed on each request. Intended for
213 // use by Google-written clients.
214 func (c *accountIssueGRPCClient) setGoogleClientInfo(keyval ...string) {
215 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
216 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
217 c.xGoogHeaders = []string{
218 "x-goog-api-client", gax.XGoogHeader(kv...),
219 }
220 }
221
222 // Close closes the connection to the API service. The user should invoke this when
223 // the client is no longer required.
224 func (c *accountIssueGRPCClient) Close() error {
225 return c.connPool.Close()
226 }
227
228 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
229 type accountIssueRESTClient struct {
230 // The http endpoint to connect to.
231 endpoint string
232
233 // The http client.
234 httpClient *http.Client
235
236 // The x-goog-* headers to be sent with each request.
237 xGoogHeaders []string
238
239 // Points back to the CallOptions field of the containing AccountIssueClient
240 CallOptions **AccountIssueCallOptions
241
242 logger *slog.Logger
243 }
244
245 // NewAccountIssueRESTClient creates a new account issue service rest client.
246 //
247 // Service to support AccountIssueService API.
248 func NewAccountIssueRESTClient(ctx context.Context, opts ...option.ClientOption) (*AccountIssueClient, error) {
249 clientOpts := append(defaultAccountIssueRESTClientOptions(), opts...)
250 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
251 if err != nil {
252 return nil, err
253 }
254
255 callOpts := defaultAccountIssueRESTCallOptions()
256 c := &accountIssueRESTClient{
257 endpoint: endpoint,
258 httpClient: httpClient,
259 CallOptions: &callOpts,
260 logger: internaloption.GetLogger(opts),
261 }
262 c.setGoogleClientInfo()
263
264 return &AccountIssueClient{internalClient: c, CallOptions: callOpts}, nil
265 }
266
267 func defaultAccountIssueRESTClientOptions() []option.ClientOption {
268 return []option.ClientOption{
269 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
270 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
271 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
272 internaloption.WithDefaultUniverseDomain("googleapis.com"),
273 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
274 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
275 internaloption.EnableNewAuthLibrary(),
276 }
277 }
278
279 // setGoogleClientInfo sets the name and version of the application in
280 // the `x-goog-api-client` header passed on each request. Intended for
281 // use by Google-written clients.
282 func (c *accountIssueRESTClient) setGoogleClientInfo(keyval ...string) {
283 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
284 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
285 c.xGoogHeaders = []string{
286 "x-goog-api-client", gax.XGoogHeader(kv...),
287 }
288 }
289
290 // Close closes the connection to the API service. The user should invoke this when
291 // the client is no longer required.
292 func (c *accountIssueRESTClient) Close() error {
293 // Replace httpClient with nil to force cleanup.
294 c.httpClient = nil
295 return nil
296 }
297
298 // Connection returns a connection to the API service.
299 //
300 // Deprecated: This method always returns nil.
301 func (c *accountIssueRESTClient) Connection() *grpc.ClientConn {
302 return nil
303 }
304 func (c *accountIssueGRPCClient) ListAccountIssues(ctx context.Context, req *accountspb.ListAccountIssuesRequest, opts ...gax.CallOption) *AccountIssueIterator {
305 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
306
307 hds = append(c.xGoogHeaders, hds...)
308 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
309 opts = append((*c.CallOptions).ListAccountIssues[0:len((*c.CallOptions).ListAccountIssues):len((*c.CallOptions).ListAccountIssues)], opts...)
310 it := &AccountIssueIterator{}
311 req = proto.Clone(req).(*accountspb.ListAccountIssuesRequest)
312 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountIssue, string, error) {
313 resp := &accountspb.ListAccountIssuesResponse{}
314 if pageToken != "" {
315 req.PageToken = pageToken
316 }
317 if pageSize > math.MaxInt32 {
318 req.PageSize = math.MaxInt32
319 } else if pageSize != 0 {
320 req.PageSize = int32(pageSize)
321 }
322 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
323 var err error
324 resp, err = executeRPC(ctx, c.accountIssueClient.ListAccountIssues, req, settings.GRPC, c.logger, "ListAccountIssues")
325 return err
326 }, opts...)
327 if err != nil {
328 return nil, "", err
329 }
330
331 it.Response = resp
332 return resp.GetAccountIssues(), resp.GetNextPageToken(), nil
333 }
334 fetch := func(pageSize int, pageToken string) (string, error) {
335 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
336 if err != nil {
337 return "", err
338 }
339 it.items = append(it.items, items...)
340 return nextPageToken, nil
341 }
342
343 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
344 it.pageInfo.MaxSize = int(req.GetPageSize())
345 it.pageInfo.Token = req.GetPageToken()
346
347 return it
348 }
349
350 // ListAccountIssues lists all account issues of a Merchant Center account.
351 //
352 // When called on a multi-client account, this method only returns issues
353 // belonging to that account, not its sub-accounts. To retrieve issues for
354 // sub-accounts, you must first call the
355 // accounts.listSubaccounts
356 // method to obtain a list of sub-accounts, and then call
357 // accounts.issues.list for each sub-account individually.
358 func (c *accountIssueRESTClient) ListAccountIssues(ctx context.Context, req *accountspb.ListAccountIssuesRequest, opts ...gax.CallOption) *AccountIssueIterator {
359 it := &AccountIssueIterator{}
360 req = proto.Clone(req).(*accountspb.ListAccountIssuesRequest)
361 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
362 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountIssue, string, error) {
363 resp := &accountspb.ListAccountIssuesResponse{}
364 if pageToken != "" {
365 req.PageToken = pageToken
366 }
367 if pageSize > math.MaxInt32 {
368 req.PageSize = math.MaxInt32
369 } else if pageSize != 0 {
370 req.PageSize = int32(pageSize)
371 }
372 baseUrl, err := url.Parse(c.endpoint)
373 if err != nil {
374 return nil, "", err
375 }
376 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/issues", req.GetParent())
377
378 params := url.Values{}
379 params.Add("$alt", "json;enum-encoding=int")
380 if req.GetLanguageCode() != "" {
381 params.Add("languageCode", fmt.Sprintf("%v", req.GetLanguageCode()))
382 }
383 if req.GetPageSize() != 0 {
384 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
385 }
386 if req.GetPageToken() != "" {
387 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
388 }
389 if req.GetTimeZone() != "" {
390 params.Add("timeZone", fmt.Sprintf("%v", req.GetTimeZone()))
391 }
392
393 baseUrl.RawQuery = params.Encode()
394
395 // Build HTTP headers from client and context metadata.
396 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
397 headers := gax.BuildHeaders(ctx, hds...)
398 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
399 if settings.Path != "" {
400 baseUrl.Path = settings.Path
401 }
402 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
403 if err != nil {
404 return err
405 }
406 httpReq.Header = headers
407
408 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAccountIssues")
409 if err != nil {
410 return err
411 }
412 if err := unm.Unmarshal(buf, resp); err != nil {
413 return err
414 }
415
416 return nil
417 }, opts...)
418 if e != nil {
419 return nil, "", e
420 }
421 it.Response = resp
422 return resp.GetAccountIssues(), resp.GetNextPageToken(), nil
423 }
424
425 fetch := func(pageSize int, pageToken string) (string, error) {
426 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
427 if err != nil {
428 return "", err
429 }
430 it.items = append(it.items, items...)
431 return nextPageToken, nil
432 }
433
434 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
435 it.pageInfo.MaxSize = int(req.GetPageSize())
436 it.pageInfo.Token = req.GetPageToken()
437
438 return it
439 }