Debian Codegraph @

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