| 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/iterator" |
| 32 |
"google.golang.org/api/option" |
| 33 |
"google.golang.org/api/option/internaloption" |
| 34 |
gtransport "google.golang.org/api/transport/grpc" |
| 35 |
httptransport "google.golang.org/api/transport/http" |
| 36 |
"google.golang.org/grpc" |
| 37 |
"google.golang.org/grpc/codes" |
| 38 |
"google.golang.org/protobuf/encoding/protojson" |
| 39 |
"google.golang.org/protobuf/proto" |
| 40 |
) |
| 41 |
|
| 42 |
var newGbpAccountsClientHook clientHook |
| 43 |
|
| 44 |
// GbpAccountsCallOptions contains the retry settings for each method of GbpAccountsClient. |
| 45 |
type GbpAccountsCallOptions struct { |
| 46 |
ListGbpAccounts []gax.CallOption |
| 47 |
LinkGbpAccount []gax.CallOption |
| 48 |
} |
| 49 |
|
| 50 |
func defaultGbpAccountsGRPCClientOptions() []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 defaultGbpAccountsCallOptions() *GbpAccountsCallOptions { |
| 66 |
return &GbpAccountsCallOptions{ |
| 67 |
ListGbpAccounts: []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 |
LinkGbpAccount: []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 |
} |
| 92 |
} |
| 93 |
|
| 94 |
func defaultGbpAccountsRESTCallOptions() *GbpAccountsCallOptions { |
| 95 |
return &GbpAccountsCallOptions{ |
| 96 |
ListGbpAccounts: []gax.CallOption{ |
| 97 |
gax.WithTimeout(60000 * time.Millisecond), |
| 98 |
gax.WithRetry(func() gax.Retryer { |
| 99 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 100 |
Initial: 1000 * time.Millisecond, |
| 101 |
Max: 10000 * time.Millisecond, |
| 102 |
Multiplier: 1.30, |
| 103 |
}, |
| 104 |
http.StatusServiceUnavailable) |
| 105 |
}), |
| 106 |
}, |
| 107 |
LinkGbpAccount: []gax.CallOption{ |
| 108 |
gax.WithTimeout(60000 * time.Millisecond), |
| 109 |
gax.WithRetry(func() gax.Retryer { |
| 110 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 111 |
Initial: 1000 * time.Millisecond, |
| 112 |
Max: 10000 * time.Millisecond, |
| 113 |
Multiplier: 1.30, |
| 114 |
}, |
| 115 |
http.StatusServiceUnavailable) |
| 116 |
}), |
| 117 |
}, |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
// internalGbpAccountsClient is an interface that defines the methods available from Merchant API. |
| 122 |
type internalGbpAccountsClient interface { |
| 123 |
Close() error |
| 124 |
setGoogleClientInfo(...string) |
| 125 |
Connection() *grpc.ClientConn |
| 126 |
ListGbpAccounts(context.Context, *accountspb.ListGbpAccountsRequest, ...gax.CallOption) *GbpAccountIterator |
| 127 |
LinkGbpAccount(context.Context, *accountspb.LinkGbpAccountRequest, ...gax.CallOption) (*accountspb.LinkGbpAccountResponse, error) |
| 128 |
} |
| 129 |
|
| 130 |
// GbpAccountsClient is a client for interacting with Merchant API. |
| 131 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 132 |
// |
| 133 |
// The service facilitates the management of a merchant’s Google Business |
| 134 |
// Profile (GBP) account settings. This API defines the following resource |
| 135 |
// model: |
| 136 |
// |
| 137 |
// GbpAccount |
| 138 |
type GbpAccountsClient struct { |
| 139 |
// The internal transport-dependent client. |
| 140 |
internalClient internalGbpAccountsClient |
| 141 |
|
| 142 |
// The call options for this service. |
| 143 |
CallOptions *GbpAccountsCallOptions |
| 144 |
} |
| 145 |
|
| 146 |
// Wrapper methods routed to the internal client. |
| 147 |
|
| 148 |
// Close closes the connection to the API service. The user should invoke this when |
| 149 |
// the client is no longer required. |
| 150 |
func (c *GbpAccountsClient) Close() error { |
| 151 |
return c.internalClient.Close() |
| 152 |
} |
| 153 |
|
| 154 |
// setGoogleClientInfo sets the name and version of the application in |
| 155 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 156 |
// use by Google-written clients. |
| 157 |
func (c *GbpAccountsClient) setGoogleClientInfo(keyval ...string) { |
| 158 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 159 |
} |
| 160 |
|
| 161 |
// Connection returns a connection to the API service. |
| 162 |
// |
| 163 |
// Deprecated: Connections are now pooled so this method does not always |
| 164 |
// return the same resource. |
| 165 |
func (c *GbpAccountsClient) Connection() *grpc.ClientConn { |
| 166 |
return c.internalClient.Connection() |
| 167 |
} |
| 168 |
|
| 169 |
// ListGbpAccounts list the GBP accounts for a given merchant. |
| 170 |
func (c *GbpAccountsClient) ListGbpAccounts(ctx context.Context, req *accountspb.ListGbpAccountsRequest, opts ...gax.CallOption) *GbpAccountIterator { |
| 171 |
return c.internalClient.ListGbpAccounts(ctx, req, opts...) |
| 172 |
} |
| 173 |
|
| 174 |
// LinkGbpAccount link the specified merchant to a GBP account for all countries. |
| 175 |
// |
| 176 |
// To run this method, you must have admin access to the Merchant Center |
| 177 |
// account. If you don’t have admin access, the request fails with the error |
| 178 |
// message User is not an administrator of account {ACCOUNT_ID}. |
| 179 |
func (c *GbpAccountsClient) LinkGbpAccount(ctx context.Context, req *accountspb.LinkGbpAccountRequest, opts ...gax.CallOption) (*accountspb.LinkGbpAccountResponse, error) { |
| 180 |
return c.internalClient.LinkGbpAccount(ctx, req, opts...) |
| 181 |
} |
| 182 |
|
| 183 |
// gbpAccountsGRPCClient is a client for interacting with Merchant API over gRPC transport. |
| 184 |
// |
| 185 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 186 |
type gbpAccountsGRPCClient struct { |
| 187 |
// Connection pool of gRPC connections to the service. |
| 188 |
connPool gtransport.ConnPool |
| 189 |
|
| 190 |
// Points back to the CallOptions field of the containing GbpAccountsClient |
| 191 |
CallOptions **GbpAccountsCallOptions |
| 192 |
|
| 193 |
// The gRPC API client. |
| 194 |
gbpAccountsClient accountspb.GbpAccountsServiceClient |
| 195 |
|
| 196 |
// The x-goog-* metadata to be sent with each request. |
| 197 |
xGoogHeaders []string |
| 198 |
|
| 199 |
logger *slog.Logger |
| 200 |
} |
| 201 |
|
| 202 |
// NewGbpAccountsClient creates a new gbp accounts service client based on gRPC. |
| 203 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 204 |
// |
| 205 |
// The service facilitates the management of a merchant’s Google Business |
| 206 |
// Profile (GBP) account settings. This API defines the following resource |
| 207 |
// model: |
| 208 |
// |
| 209 |
// GbpAccount |
| 210 |
func NewGbpAccountsClient(ctx context.Context, opts ...option.ClientOption) (*GbpAccountsClient, error) { |
| 211 |
clientOpts := defaultGbpAccountsGRPCClientOptions() |
| 212 |
if newGbpAccountsClientHook != nil { |
| 213 |
hookOpts, err := newGbpAccountsClientHook(ctx, clientHookParams{}) |
| 214 |
if err != nil { |
| 215 |
return nil, err |
| 216 |
} |
| 217 |
clientOpts = append(clientOpts, hookOpts...) |
| 218 |
} |
| 219 |
|
| 220 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 221 |
if err != nil { |
| 222 |
return nil, err |
| 223 |
} |
| 224 |
client := GbpAccountsClient{CallOptions: defaultGbpAccountsCallOptions()} |
| 225 |
|
| 226 |
c := &gbpAccountsGRPCClient{ |
| 227 |
connPool: connPool, |
| 228 |
gbpAccountsClient: accountspb.NewGbpAccountsServiceClient(connPool), |
| 229 |
CallOptions: &client.CallOptions, |
| 230 |
logger: internaloption.GetLogger(opts), |
| 231 |
} |
| 232 |
c.setGoogleClientInfo() |
| 233 |
|
| 234 |
client.internalClient = c |
| 235 |
|
| 236 |
return &client, nil |
| 237 |
} |
| 238 |
|
| 239 |
// Connection returns a connection to the API service. |
| 240 |
// |
| 241 |
// Deprecated: Connections are now pooled so this method does not always |
| 242 |
// return the same resource. |
| 243 |
func (c *gbpAccountsGRPCClient) Connection() *grpc.ClientConn { |
| 244 |
return c.connPool.Conn() |
| 245 |
} |
| 246 |
|
| 247 |
// setGoogleClientInfo sets the name and version of the application in |
| 248 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 249 |
// use by Google-written clients. |
| 250 |
func (c *gbpAccountsGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 251 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 252 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 253 |
c.xGoogHeaders = []string{ |
| 254 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
// Close closes the connection to the API service. The user should invoke this when |
| 259 |
// the client is no longer required. |
| 260 |
func (c *gbpAccountsGRPCClient) Close() error { |
| 261 |
return c.connPool.Close() |
| 262 |
} |
| 263 |
|
| 264 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 265 |
type gbpAccountsRESTClient struct { |
| 266 |
// The http endpoint to connect to. |
| 267 |
endpoint string |
| 268 |
|
| 269 |
// The http client. |
| 270 |
httpClient *http.Client |
| 271 |
|
| 272 |
// The x-goog-* headers to be sent with each request. |
| 273 |
xGoogHeaders []string |
| 274 |
|
| 275 |
// Points back to the CallOptions field of the containing GbpAccountsClient |
| 276 |
CallOptions **GbpAccountsCallOptions |
| 277 |
|
| 278 |
logger *slog.Logger |
| 279 |
} |
| 280 |
|
| 281 |
// NewGbpAccountsRESTClient creates a new gbp accounts service rest client. |
| 282 |
// |
| 283 |
// The service facilitates the management of a merchant’s Google Business |
| 284 |
// Profile (GBP) account settings. This API defines the following resource |
| 285 |
// model: |
| 286 |
// |
| 287 |
// GbpAccount |
| 288 |
func NewGbpAccountsRESTClient(ctx context.Context, opts ...option.ClientOption) (*GbpAccountsClient, error) { |
| 289 |
clientOpts := append(defaultGbpAccountsRESTClientOptions(), opts...) |
| 290 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 291 |
if err != nil { |
| 292 |
return nil, err |
| 293 |
} |
| 294 |
|
| 295 |
callOpts := defaultGbpAccountsRESTCallOptions() |
| 296 |
c := &gbpAccountsRESTClient{ |
| 297 |
endpoint: endpoint, |
| 298 |
httpClient: httpClient, |
| 299 |
CallOptions: &callOpts, |
| 300 |
logger: internaloption.GetLogger(opts), |
| 301 |
} |
| 302 |
c.setGoogleClientInfo() |
| 303 |
|
| 304 |
return &GbpAccountsClient{internalClient: c, CallOptions: callOpts}, nil |
| 305 |
} |
| 306 |
|
| 307 |
func defaultGbpAccountsRESTClientOptions() []option.ClientOption { |
| 308 |
return []option.ClientOption{ |
| 309 |
internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"), |
| 310 |
internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"), |
| 311 |
internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"), |
| 312 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 313 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 314 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 315 |
internaloption.EnableNewAuthLibrary(), |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
// setGoogleClientInfo sets the name and version of the application in |
| 320 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 321 |
// use by Google-written clients. |
| 322 |
func (c *gbpAccountsRESTClient) setGoogleClientInfo(keyval ...string) { |
| 323 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 324 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 325 |
c.xGoogHeaders = []string{ |
| 326 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
// Close closes the connection to the API service. The user should invoke this when |
| 331 |
// the client is no longer required. |
| 332 |
func (c *gbpAccountsRESTClient) Close() error { |
| 333 |
// Replace httpClient with nil to force cleanup. |
| 334 |
c.httpClient = nil |
| 335 |
return nil |
| 336 |
} |
| 337 |
|
| 338 |
// Connection returns a connection to the API service. |
| 339 |
// |
| 340 |
// Deprecated: This method always returns nil. |
| 341 |
func (c *gbpAccountsRESTClient) Connection() *grpc.ClientConn { |
| 342 |
return nil |
| 343 |
} |
| 344 |
func (c *gbpAccountsGRPCClient) ListGbpAccounts(ctx context.Context, req *accountspb.ListGbpAccountsRequest, opts ...gax.CallOption) *GbpAccountIterator { |
| 345 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 346 |
|
| 347 |
hds = append(c.xGoogHeaders, hds...) |
| 348 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 349 |
opts = append((*c.CallOptions).ListGbpAccounts[0:len((*c.CallOptions).ListGbpAccounts):len((*c.CallOptions).ListGbpAccounts)], opts...) |
| 350 |
it := &GbpAccountIterator{} |
| 351 |
req = proto.Clone(req).(*accountspb.ListGbpAccountsRequest) |
| 352 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.GbpAccount, string, error) { |
| 353 |
resp := &accountspb.ListGbpAccountsResponse{} |
| 354 |
if pageToken != "" { |
| 355 |
req.PageToken = pageToken |
| 356 |
} |
| 357 |
if pageSize > math.MaxInt32 { |
| 358 |
req.PageSize = math.MaxInt32 |
| 359 |
} else if pageSize != 0 { |
| 360 |
req.PageSize = int32(pageSize) |
| 361 |
} |
| 362 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 363 |
var err error |
| 364 |
resp, err = executeRPC(ctx, c.gbpAccountsClient.ListGbpAccounts, req, settings.GRPC, c.logger, "ListGbpAccounts") |
| 365 |
return err |
| 366 |
}, opts...) |
| 367 |
if err != nil { |
| 368 |
return nil, "", err |
| 369 |
} |
| 370 |
|
| 371 |
it.Response = resp |
| 372 |
return resp.GetGbpAccounts(), resp.GetNextPageToken(), nil |
| 373 |
} |
| 374 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 375 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 376 |
if err != nil { |
| 377 |
return "", err |
| 378 |
} |
| 379 |
it.items = append(it.items, items...) |
| 380 |
return nextPageToken, nil |
| 381 |
} |
| 382 |
|
| 383 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 384 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 385 |
it.pageInfo.Token = req.GetPageToken() |
| 386 |
|
| 387 |
return it |
| 388 |
} |
| 389 |
|
| 390 |
func (c *gbpAccountsGRPCClient) LinkGbpAccount(ctx context.Context, req *accountspb.LinkGbpAccountRequest, opts ...gax.CallOption) (*accountspb.LinkGbpAccountResponse, error) { |
| 391 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 392 |
|
| 393 |
hds = append(c.xGoogHeaders, hds...) |
| 394 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 395 |
opts = append((*c.CallOptions).LinkGbpAccount[0:len((*c.CallOptions).LinkGbpAccount):len((*c.CallOptions).LinkGbpAccount)], opts...) |
| 396 |
var resp *accountspb.LinkGbpAccountResponse |
| 397 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 398 |
var err error |
| 399 |
resp, err = executeRPC(ctx, c.gbpAccountsClient.LinkGbpAccount, req, settings.GRPC, c.logger, "LinkGbpAccount") |
| 400 |
return err |
| 401 |
}, opts...) |
| 402 |
if err != nil { |
| 403 |
return nil, err |
| 404 |
} |
| 405 |
return resp, nil |
| 406 |
} |
| 407 |
|
| 408 |
// ListGbpAccounts list the GBP accounts for a given merchant. |
| 409 |
func (c *gbpAccountsRESTClient) ListGbpAccounts(ctx context.Context, req *accountspb.ListGbpAccountsRequest, opts ...gax.CallOption) *GbpAccountIterator { |
| 410 |
it := &GbpAccountIterator{} |
| 411 |
req = proto.Clone(req).(*accountspb.ListGbpAccountsRequest) |
| 412 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 413 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.GbpAccount, string, error) { |
| 414 |
resp := &accountspb.ListGbpAccountsResponse{} |
| 415 |
if pageToken != "" { |
| 416 |
req.PageToken = pageToken |
| 417 |
} |
| 418 |
if pageSize > math.MaxInt32 { |
| 419 |
req.PageSize = math.MaxInt32 |
| 420 |
} else if pageSize != 0 { |
| 421 |
req.PageSize = int32(pageSize) |
| 422 |
} |
| 423 |
baseUrl, err := url.Parse(c.endpoint) |
| 424 |
if err != nil { |
| 425 |
return nil, "", err |
| 426 |
} |
| 427 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/gbpAccounts", req.GetParent()) |
| 428 |
|
| 429 |
params := url.Values{} |
| 430 |
params.Add("$alt", "json;enum-encoding=int") |
| 431 |
if req.GetPageSize() != 0 { |
| 432 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 433 |
} |
| 434 |
if req.GetPageToken() != "" { |
| 435 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 436 |
} |
| 437 |
|
| 438 |
baseUrl.RawQuery = params.Encode() |
| 439 |
|
| 440 |
// Build HTTP headers from client and context metadata. |
| 441 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 442 |
headers := gax.BuildHeaders(ctx, hds...) |
| 443 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 444 |
if settings.Path != "" { |
| 445 |
baseUrl.Path = settings.Path |
| 446 |
} |
| 447 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 448 |
if err != nil { |
| 449 |
return err |
| 450 |
} |
| 451 |
httpReq.Header = headers |
| 452 |
|
| 453 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListGbpAccounts") |
| 454 |
if err != nil { |
| 455 |
return err |
| 456 |
} |
| 457 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 458 |
return err |
| 459 |
} |
| 460 |
|
| 461 |
return nil |
| 462 |
}, opts...) |
| 463 |
if e != nil { |
| 464 |
return nil, "", e |
| 465 |
} |
| 466 |
it.Response = resp |
| 467 |
return resp.GetGbpAccounts(), resp.GetNextPageToken(), nil |
| 468 |
} |
| 469 |
|
| 470 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 471 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 472 |
if err != nil { |
| 473 |
return "", err |
| 474 |
} |
| 475 |
it.items = append(it.items, items...) |
| 476 |
return nextPageToken, nil |
| 477 |
} |
| 478 |
|
| 479 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 480 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 481 |
it.pageInfo.Token = req.GetPageToken() |
| 482 |
|
| 483 |
return it |
| 484 |
} |
| 485 |
|
| 486 |
// LinkGbpAccount link the specified merchant to a GBP account for all countries. |
| 487 |
// |
| 488 |
// To run this method, you must have admin access to the Merchant Center |
| 489 |
// account. If you don’t have admin access, the request fails with the error |
| 490 |
// message User is not an administrator of account {ACCOUNT_ID}. |
| 491 |
func (c *gbpAccountsRESTClient) LinkGbpAccount(ctx context.Context, req *accountspb.LinkGbpAccountRequest, opts ...gax.CallOption) (*accountspb.LinkGbpAccountResponse, error) { |
| 492 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 493 |
jsonReq, err := m.Marshal(req) |
| 494 |
if err != nil { |
| 495 |
return nil, err |
| 496 |
} |
| 497 |
|
| 498 |
baseUrl, err := url.Parse(c.endpoint) |
| 499 |
if err != nil { |
| 500 |
return nil, err |
| 501 |
} |
| 502 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/gbpAccounts:linkGbpAccount", req.GetParent()) |
| 503 |
|
| 504 |
params := url.Values{} |
| 505 |
params.Add("$alt", "json;enum-encoding=int") |
| 506 |
|
| 507 |
baseUrl.RawQuery = params.Encode() |
| 508 |
|
| 509 |
// Build HTTP headers from client and context metadata. |
| 510 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 511 |
|
| 512 |
hds = append(c.xGoogHeaders, hds...) |
| 513 |
hds = append(hds, "Content-Type", "application/json") |
| 514 |
headers := gax.BuildHeaders(ctx, hds...) |
| 515 |
opts = append((*c.CallOptions).LinkGbpAccount[0:len((*c.CallOptions).LinkGbpAccount):len((*c.CallOptions).LinkGbpAccount)], opts...) |
| 516 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 517 |
resp := &accountspb.LinkGbpAccountResponse{} |
| 518 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 519 |
if settings.Path != "" { |
| 520 |
baseUrl.Path = settings.Path |
| 521 |
} |
| 522 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 523 |
if err != nil { |
| 524 |
return err |
| 525 |
} |
| 526 |
httpReq = httpReq.WithContext(ctx) |
| 527 |
httpReq.Header = headers |
| 528 |
|
| 529 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "LinkGbpAccount") |
| 530 |
if err != nil { |
| 531 |
return err |
| 532 |
} |
| 533 |
|
| 534 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 535 |
return err |
| 536 |
} |
| 537 |
|
| 538 |
return nil |
| 539 |
}, opts...) |
| 540 |
if e != nil { |
| 541 |
return nil, e |
| 542 |
} |
| 543 |
return resp, nil |
| 544 |
} |