Debian Codegraph @

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