Debian Codegraph @

shopping/merchant/accounts/apiv1beta/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/apiv1beta/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 merchant 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. In case of failure, a canonical error message will be returned:
230 // * PERMISSION_DENIED: user doesn’t have the necessary permissions on this
231 // MC account;
232 // * FAILED_PRECONDITION:
233 // - The account is not a Merchant Center account;
234 // - MC account doesn’t have a homepage;
235 // - claiming failed (in this case the error message will contain more
236 // details).
237 func (c *HomepageClient) ClaimHomepage(ctx context.Context, req *accountspb.ClaimHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
238 return c.internalClient.ClaimHomepage(ctx, req, opts...)
239 }
240
241 // UnclaimHomepage unclaims a store’s homepage. Executing this method requires admin access.
242 func (c *HomepageClient) UnclaimHomepage(ctx context.Context, req *accountspb.UnclaimHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
243 return c.internalClient.UnclaimHomepage(ctx, req, opts...)
244 }
245
246 // homepageGRPCClient is a client for interacting with Merchant API over gRPC transport.
247 //
248 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
249 type homepageGRPCClient struct {
250 // Connection pool of gRPC connections to the service.
251 connPool gtransport.ConnPool
252
253 // Points back to the CallOptions field of the containing HomepageClient
254 CallOptions **HomepageCallOptions
255
256 // The gRPC API client.
257 homepageClient accountspb.HomepageServiceClient
258
259 // The x-goog-* metadata to be sent with each request.
260 xGoogHeaders []string
261
262 logger *slog.Logger
263 }
264
265 // NewHomepageClient creates a new homepage service client based on gRPC.
266 // The returned client must be Closed when it is done being used to clean up its underlying connections.
267 //
268 // Service to support an API for a store’s homepage.
269 func NewHomepageClient(ctx context.Context, opts ...option.ClientOption) (*HomepageClient, error) {
270 clientOpts := defaultHomepageGRPCClientOptions()
271 if newHomepageClientHook != nil {
272 hookOpts, err := newHomepageClientHook(ctx, clientHookParams{})
273 if err != nil {
274 return nil, err
275 }
276 clientOpts = append(clientOpts, hookOpts...)
277 }
278
279 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
280 if err != nil {
281 return nil, err
282 }
283 client := HomepageClient{CallOptions: defaultHomepageCallOptions()}
284
285 c := &homepageGRPCClient{
286 connPool: connPool,
287 homepageClient: accountspb.NewHomepageServiceClient(connPool),
288 CallOptions: &client.CallOptions,
289 logger: internaloption.GetLogger(opts),
290 }
291 c.setGoogleClientInfo()
292
293 client.internalClient = c
294
295 return &client, nil
296 }
297
298 // Connection returns a connection to the API service.
299 //
300 // Deprecated: Connections are now pooled so this method does not always
301 // return the same resource.
302 func (c *homepageGRPCClient) Connection() *grpc.ClientConn {
303 return c.connPool.Conn()
304 }
305
306 // setGoogleClientInfo sets the name and version of the application in
307 // the `x-goog-api-client` header passed on each request. Intended for
308 // use by Google-written clients.
309 func (c *homepageGRPCClient) setGoogleClientInfo(keyval ...string) {
310 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
311 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
312 c.xGoogHeaders = []string{
313 "x-goog-api-client", gax.XGoogHeader(kv...),
314 }
315 }
316
317 // Close closes the connection to the API service. The user should invoke this when
318 // the client is no longer required.
319 func (c *homepageGRPCClient) Close() error {
320 return c.connPool.Close()
321 }
322
323 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
324 type homepageRESTClient struct {
325 // The http endpoint to connect to.
326 endpoint string
327
328 // The http client.
329 httpClient *http.Client
330
331 // The x-goog-* headers to be sent with each request.
332 xGoogHeaders []string
333
334 // Points back to the CallOptions field of the containing HomepageClient
335 CallOptions **HomepageCallOptions
336
337 logger *slog.Logger
338 }
339
340 // NewHomepageRESTClient creates a new homepage service rest client.
341 //
342 // Service to support an API for a store’s homepage.
343 func NewHomepageRESTClient(ctx context.Context, opts ...option.ClientOption) (*HomepageClient, error) {
344 clientOpts := append(defaultHomepageRESTClientOptions(), opts...)
345 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
346 if err != nil {
347 return nil, err
348 }
349
350 callOpts := defaultHomepageRESTCallOptions()
351 c := &homepageRESTClient{
352 endpoint: endpoint,
353 httpClient: httpClient,
354 CallOptions: &callOpts,
355 logger: internaloption.GetLogger(opts),
356 }
357 c.setGoogleClientInfo()
358
359 return &HomepageClient{internalClient: c, CallOptions: callOpts}, nil
360 }
361
362 func defaultHomepageRESTClientOptions() []option.ClientOption {
363 return []option.ClientOption{
364 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
365 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
366 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
367 internaloption.WithDefaultUniverseDomain("googleapis.com"),
368 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
369 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
370 internaloption.EnableNewAuthLibrary(),
371 }
372 }
373
374 // setGoogleClientInfo sets the name and version of the application in
375 // the `x-goog-api-client` header passed on each request. Intended for
376 // use by Google-written clients.
377 func (c *homepageRESTClient) setGoogleClientInfo(keyval ...string) {
378 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
379 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
380 c.xGoogHeaders = []string{
381 "x-goog-api-client", gax.XGoogHeader(kv...),
382 }
383 }
384
385 // Close closes the connection to the API service. The user should invoke this when
386 // the client is no longer required.
387 func (c *homepageRESTClient) Close() error {
388 // Replace httpClient with nil to force cleanup.
389 c.httpClient = nil
390 return nil
391 }
392
393 // Connection returns a connection to the API service.
394 //
395 // Deprecated: This method always returns nil.
396 func (c *homepageRESTClient) Connection() *grpc.ClientConn {
397 return nil
398 }
399 func (c *homepageGRPCClient) GetHomepage(ctx context.Context, req *accountspb.GetHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
400 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
401
402 hds = append(c.xGoogHeaders, hds...)
403 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
404 opts = append((*c.CallOptions).GetHomepage[0:len((*c.CallOptions).GetHomepage):len((*c.CallOptions).GetHomepage)], opts...)
405 var resp *accountspb.Homepage
406 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
407 var err error
408 resp, err = executeRPC(ctx, c.homepageClient.GetHomepage, req, settings.GRPC, c.logger, "GetHomepage")
409 return err
410 }, opts...)
411 if err != nil {
412 return nil, err
413 }
414 return resp, nil
415 }
416
417 func (c *homepageGRPCClient) UpdateHomepage(ctx context.Context, req *accountspb.UpdateHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
418 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "homepage.name", url.QueryEscape(req.GetHomepage().GetName()))}
419
420 hds = append(c.xGoogHeaders, hds...)
421 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
422 opts = append((*c.CallOptions).UpdateHomepage[0:len((*c.CallOptions).UpdateHomepage):len((*c.CallOptions).UpdateHomepage)], opts...)
423 var resp *accountspb.Homepage
424 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
425 var err error
426 resp, err = executeRPC(ctx, c.homepageClient.UpdateHomepage, req, settings.GRPC, c.logger, "UpdateHomepage")
427 return err
428 }, opts...)
429 if err != nil {
430 return nil, err
431 }
432 return resp, nil
433 }
434
435 func (c *homepageGRPCClient) ClaimHomepage(ctx context.Context, req *accountspb.ClaimHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
436 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
437
438 hds = append(c.xGoogHeaders, hds...)
439 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
440 opts = append((*c.CallOptions).ClaimHomepage[0:len((*c.CallOptions).ClaimHomepage):len((*c.CallOptions).ClaimHomepage)], opts...)
441 var resp *accountspb.Homepage
442 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
443 var err error
444 resp, err = executeRPC(ctx, c.homepageClient.ClaimHomepage, req, settings.GRPC, c.logger, "ClaimHomepage")
445 return err
446 }, opts...)
447 if err != nil {
448 return nil, err
449 }
450 return resp, nil
451 }
452
453 func (c *homepageGRPCClient) UnclaimHomepage(ctx context.Context, req *accountspb.UnclaimHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
454 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
455
456 hds = append(c.xGoogHeaders, hds...)
457 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
458 opts = append((*c.CallOptions).UnclaimHomepage[0:len((*c.CallOptions).UnclaimHomepage):len((*c.CallOptions).UnclaimHomepage)], opts...)
459 var resp *accountspb.Homepage
460 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
461 var err error
462 resp, err = executeRPC(ctx, c.homepageClient.UnclaimHomepage, req, settings.GRPC, c.logger, "UnclaimHomepage")
463 return err
464 }, opts...)
465 if err != nil {
466 return nil, err
467 }
468 return resp, nil
469 }
470
471 // GetHomepage retrieves a store’s homepage.
472 func (c *homepageRESTClient) GetHomepage(ctx context.Context, req *accountspb.GetHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
473 baseUrl, err := url.Parse(c.endpoint)
474 if err != nil {
475 return nil, err
476 }
477 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName())
478
479 params := url.Values{}
480 params.Add("$alt", "json;enum-encoding=int")
481
482 baseUrl.RawQuery = params.Encode()
483
484 // Build HTTP headers from client and context metadata.
485 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
486
487 hds = append(c.xGoogHeaders, hds...)
488 hds = append(hds, "Content-Type", "application/json")
489 headers := gax.BuildHeaders(ctx, hds...)
490 opts = append((*c.CallOptions).GetHomepage[0:len((*c.CallOptions).GetHomepage):len((*c.CallOptions).GetHomepage)], opts...)
491 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
492 resp := &accountspb.Homepage{}
493 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
494 if settings.Path != "" {
495 baseUrl.Path = settings.Path
496 }
497 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
498 if err != nil {
499 return err
500 }
501 httpReq = httpReq.WithContext(ctx)
502 httpReq.Header = headers
503
504 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetHomepage")
505 if err != nil {
506 return err
507 }
508
509 if err := unm.Unmarshal(buf, resp); err != nil {
510 return err
511 }
512
513 return nil
514 }, opts...)
515 if e != nil {
516 return nil, e
517 }
518 return resp, nil
519 }
520
521 // UpdateHomepage updates a store’s homepage. Executing this method requires admin access.
522 func (c *homepageRESTClient) UpdateHomepage(ctx context.Context, req *accountspb.UpdateHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
523 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
524 body := req.GetHomepage()
525 jsonReq, err := m.Marshal(body)
526 if err != nil {
527 return nil, err
528 }
529
530 baseUrl, err := url.Parse(c.endpoint)
531 if err != nil {
532 return nil, err
533 }
534 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetHomepage().GetName())
535
536 params := url.Values{}
537 params.Add("$alt", "json;enum-encoding=int")
538 if req.GetUpdateMask() != nil {
539 field, err := protojson.Marshal(req.GetUpdateMask())
540 if err != nil {
541 return nil, err
542 }
543 params.Add("updateMask", string(field[1:len(field)-1]))
544 }
545
546 baseUrl.RawQuery = params.Encode()
547
548 // Build HTTP headers from client and context metadata.
549 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "homepage.name", url.QueryEscape(req.GetHomepage().GetName()))}
550
551 hds = append(c.xGoogHeaders, hds...)
552 hds = append(hds, "Content-Type", "application/json")
553 headers := gax.BuildHeaders(ctx, hds...)
554 opts = append((*c.CallOptions).UpdateHomepage[0:len((*c.CallOptions).UpdateHomepage):len((*c.CallOptions).UpdateHomepage)], opts...)
555 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
556 resp := &accountspb.Homepage{}
557 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
558 if settings.Path != "" {
559 baseUrl.Path = settings.Path
560 }
561 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
562 if err != nil {
563 return err
564 }
565 httpReq = httpReq.WithContext(ctx)
566 httpReq.Header = headers
567
568 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateHomepage")
569 if err != nil {
570 return err
571 }
572
573 if err := unm.Unmarshal(buf, resp); err != nil {
574 return err
575 }
576
577 return nil
578 }, opts...)
579 if e != nil {
580 return nil, e
581 }
582 return resp, nil
583 }
584
585 // ClaimHomepage claims a store’s homepage. Executing this method requires admin access.
586 //
587 // If the homepage is already claimed, this will recheck the
588 // verification (unless the merchant is exempted from claiming, which also
589 // exempts from verification) and return a successful response. If ownership
590 // can no longer be verified, it will return an error, but it won’t clear the
591 // claim. In case of failure, a canonical error message will be returned:
592 // * PERMISSION_DENIED: user doesn’t have the necessary permissions on this
593 // MC account;
594 // * FAILED_PRECONDITION:
595 // - The account is not a Merchant Center account;
596 // - MC account doesn’t have a homepage;
597 // - claiming failed (in this case the error message will contain more
598 // details).
599 func (c *homepageRESTClient) ClaimHomepage(ctx context.Context, req *accountspb.ClaimHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
600 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
601 jsonReq, err := m.Marshal(req)
602 if err != nil {
603 return nil, err
604 }
605
606 baseUrl, err := url.Parse(c.endpoint)
607 if err != nil {
608 return nil, err
609 }
610 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v:claim", req.GetName())
611
612 params := url.Values{}
613 params.Add("$alt", "json;enum-encoding=int")
614
615 baseUrl.RawQuery = params.Encode()
616
617 // Build HTTP headers from client and context metadata.
618 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
619
620 hds = append(c.xGoogHeaders, hds...)
621 hds = append(hds, "Content-Type", "application/json")
622 headers := gax.BuildHeaders(ctx, hds...)
623 opts = append((*c.CallOptions).ClaimHomepage[0:len((*c.CallOptions).ClaimHomepage):len((*c.CallOptions).ClaimHomepage)], opts...)
624 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
625 resp := &accountspb.Homepage{}
626 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
627 if settings.Path != "" {
628 baseUrl.Path = settings.Path
629 }
630 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
631 if err != nil {
632 return err
633 }
634 httpReq = httpReq.WithContext(ctx)
635 httpReq.Header = headers
636
637 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ClaimHomepage")
638 if err != nil {
639 return err
640 }
641
642 if err := unm.Unmarshal(buf, resp); err != nil {
643 return err
644 }
645
646 return nil
647 }, opts...)
648 if e != nil {
649 return nil, e
650 }
651 return resp, nil
652 }
653
654 // UnclaimHomepage unclaims a store’s homepage. Executing this method requires admin access.
655 func (c *homepageRESTClient) UnclaimHomepage(ctx context.Context, req *accountspb.UnclaimHomepageRequest, opts ...gax.CallOption) (*accountspb.Homepage, error) {
656 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
657 jsonReq, err := m.Marshal(req)
658 if err != nil {
659 return nil, err
660 }
661
662 baseUrl, err := url.Parse(c.endpoint)
663 if err != nil {
664 return nil, err
665 }
666 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v:unclaim", req.GetName())
667
668 params := url.Values{}
669 params.Add("$alt", "json;enum-encoding=int")
670
671 baseUrl.RawQuery = params.Encode()
672
673 // Build HTTP headers from client and context metadata.
674 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
675
676 hds = append(c.xGoogHeaders, hds...)
677 hds = append(hds, "Content-Type", "application/json")
678 headers := gax.BuildHeaders(ctx, hds...)
679 opts = append((*c.CallOptions).UnclaimHomepage[0:len((*c.CallOptions).UnclaimHomepage):len((*c.CallOptions).UnclaimHomepage)], opts...)
680 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
681 resp := &accountspb.Homepage{}
682 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
683 if settings.Path != "" {
684 baseUrl.Path = settings.Path
685 }
686 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
687 if err != nil {
688 return err
689 }
690 httpReq = httpReq.WithContext(ctx)
691 httpReq.Header = headers
692
693 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UnclaimHomepage")
694 if err != nil {
695 return err
696 }
697
698 if err := unm.Unmarshal(buf, resp); err != nil {
699 return err
700 }
701
702 return nil
703 }, opts...)
704 if e != nil {
705 return nil, e
706 }
707 return resp, nil
708 }