| 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 newRegionsClientHook clientHook |
| 43 |
|
| 44 |
// RegionsCallOptions contains the retry settings for each method of RegionsClient. |
| 45 |
type RegionsCallOptions struct { |
| 46 |
GetRegion []gax.CallOption |
| 47 |
CreateRegion []gax.CallOption |
| 48 |
BatchCreateRegions []gax.CallOption |
| 49 |
UpdateRegion []gax.CallOption |
| 50 |
BatchUpdateRegions []gax.CallOption |
| 51 |
DeleteRegion []gax.CallOption |
| 52 |
BatchDeleteRegions []gax.CallOption |
| 53 |
ListRegions []gax.CallOption |
| 54 |
} |
| 55 |
|
| 56 |
func defaultRegionsGRPCClientOptions() []option.ClientOption { |
| 57 |
return []option.ClientOption{ |
| 58 |
internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"), |
| 59 |
internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"), |
| 60 |
internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"), |
| 61 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 62 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 63 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 64 |
internaloption.EnableJwtWithScope(), |
| 65 |
internaloption.EnableNewAuthLibrary(), |
| 66 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 67 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
func defaultRegionsCallOptions() *RegionsCallOptions { |
| 72 |
return &RegionsCallOptions{ |
| 73 |
GetRegion: []gax.CallOption{ |
| 74 |
gax.WithTimeout(60000 * time.Millisecond), |
| 75 |
gax.WithRetry(func() gax.Retryer { |
| 76 |
return gax.OnCodes([]codes.Code{ |
| 77 |
codes.Unavailable, |
| 78 |
}, gax.Backoff{ |
| 79 |
Initial: 1000 * time.Millisecond, |
| 80 |
Max: 10000 * time.Millisecond, |
| 81 |
Multiplier: 1.30, |
| 82 |
}) |
| 83 |
}), |
| 84 |
}, |
| 85 |
CreateRegion: []gax.CallOption{ |
| 86 |
gax.WithTimeout(60000 * time.Millisecond), |
| 87 |
gax.WithRetry(func() gax.Retryer { |
| 88 |
return gax.OnCodes([]codes.Code{ |
| 89 |
codes.Unavailable, |
| 90 |
}, gax.Backoff{ |
| 91 |
Initial: 1000 * time.Millisecond, |
| 92 |
Max: 10000 * time.Millisecond, |
| 93 |
Multiplier: 1.30, |
| 94 |
}) |
| 95 |
}), |
| 96 |
}, |
| 97 |
BatchCreateRegions: []gax.CallOption{ |
| 98 |
gax.WithTimeout(60000 * time.Millisecond), |
| 99 |
gax.WithRetry(func() gax.Retryer { |
| 100 |
return gax.OnCodes([]codes.Code{ |
| 101 |
codes.Unavailable, |
| 102 |
}, gax.Backoff{ |
| 103 |
Initial: 1000 * time.Millisecond, |
| 104 |
Max: 10000 * time.Millisecond, |
| 105 |
Multiplier: 1.30, |
| 106 |
}) |
| 107 |
}), |
| 108 |
}, |
| 109 |
UpdateRegion: []gax.CallOption{ |
| 110 |
gax.WithTimeout(60000 * time.Millisecond), |
| 111 |
gax.WithRetry(func() gax.Retryer { |
| 112 |
return gax.OnCodes([]codes.Code{ |
| 113 |
codes.Unavailable, |
| 114 |
}, gax.Backoff{ |
| 115 |
Initial: 1000 * time.Millisecond, |
| 116 |
Max: 10000 * time.Millisecond, |
| 117 |
Multiplier: 1.30, |
| 118 |
}) |
| 119 |
}), |
| 120 |
}, |
| 121 |
BatchUpdateRegions: []gax.CallOption{ |
| 122 |
gax.WithTimeout(60000 * time.Millisecond), |
| 123 |
gax.WithRetry(func() gax.Retryer { |
| 124 |
return gax.OnCodes([]codes.Code{ |
| 125 |
codes.Unavailable, |
| 126 |
}, gax.Backoff{ |
| 127 |
Initial: 1000 * time.Millisecond, |
| 128 |
Max: 10000 * time.Millisecond, |
| 129 |
Multiplier: 1.30, |
| 130 |
}) |
| 131 |
}), |
| 132 |
}, |
| 133 |
DeleteRegion: []gax.CallOption{ |
| 134 |
gax.WithTimeout(60000 * time.Millisecond), |
| 135 |
gax.WithRetry(func() gax.Retryer { |
| 136 |
return gax.OnCodes([]codes.Code{ |
| 137 |
codes.Unavailable, |
| 138 |
}, gax.Backoff{ |
| 139 |
Initial: 1000 * time.Millisecond, |
| 140 |
Max: 10000 * time.Millisecond, |
| 141 |
Multiplier: 1.30, |
| 142 |
}) |
| 143 |
}), |
| 144 |
}, |
| 145 |
BatchDeleteRegions: []gax.CallOption{ |
| 146 |
gax.WithTimeout(60000 * time.Millisecond), |
| 147 |
gax.WithRetry(func() gax.Retryer { |
| 148 |
return gax.OnCodes([]codes.Code{ |
| 149 |
codes.Unavailable, |
| 150 |
}, gax.Backoff{ |
| 151 |
Initial: 1000 * time.Millisecond, |
| 152 |
Max: 10000 * time.Millisecond, |
| 153 |
Multiplier: 1.30, |
| 154 |
}) |
| 155 |
}), |
| 156 |
}, |
| 157 |
ListRegions: []gax.CallOption{ |
| 158 |
gax.WithTimeout(60000 * time.Millisecond), |
| 159 |
gax.WithRetry(func() gax.Retryer { |
| 160 |
return gax.OnCodes([]codes.Code{ |
| 161 |
codes.Unavailable, |
| 162 |
}, gax.Backoff{ |
| 163 |
Initial: 1000 * time.Millisecond, |
| 164 |
Max: 10000 * time.Millisecond, |
| 165 |
Multiplier: 1.30, |
| 166 |
}) |
| 167 |
}), |
| 168 |
}, |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
func defaultRegionsRESTCallOptions() *RegionsCallOptions { |
| 173 |
return &RegionsCallOptions{ |
| 174 |
GetRegion: []gax.CallOption{ |
| 175 |
gax.WithTimeout(60000 * time.Millisecond), |
| 176 |
gax.WithRetry(func() gax.Retryer { |
| 177 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 178 |
Initial: 1000 * time.Millisecond, |
| 179 |
Max: 10000 * time.Millisecond, |
| 180 |
Multiplier: 1.30, |
| 181 |
}, |
| 182 |
http.StatusServiceUnavailable) |
| 183 |
}), |
| 184 |
}, |
| 185 |
CreateRegion: []gax.CallOption{ |
| 186 |
gax.WithTimeout(60000 * time.Millisecond), |
| 187 |
gax.WithRetry(func() gax.Retryer { |
| 188 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 189 |
Initial: 1000 * time.Millisecond, |
| 190 |
Max: 10000 * time.Millisecond, |
| 191 |
Multiplier: 1.30, |
| 192 |
}, |
| 193 |
http.StatusServiceUnavailable) |
| 194 |
}), |
| 195 |
}, |
| 196 |
BatchCreateRegions: []gax.CallOption{ |
| 197 |
gax.WithTimeout(60000 * time.Millisecond), |
| 198 |
gax.WithRetry(func() gax.Retryer { |
| 199 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 200 |
Initial: 1000 * time.Millisecond, |
| 201 |
Max: 10000 * time.Millisecond, |
| 202 |
Multiplier: 1.30, |
| 203 |
}, |
| 204 |
http.StatusServiceUnavailable) |
| 205 |
}), |
| 206 |
}, |
| 207 |
UpdateRegion: []gax.CallOption{ |
| 208 |
gax.WithTimeout(60000 * time.Millisecond), |
| 209 |
gax.WithRetry(func() gax.Retryer { |
| 210 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 211 |
Initial: 1000 * time.Millisecond, |
| 212 |
Max: 10000 * time.Millisecond, |
| 213 |
Multiplier: 1.30, |
| 214 |
}, |
| 215 |
http.StatusServiceUnavailable) |
| 216 |
}), |
| 217 |
}, |
| 218 |
BatchUpdateRegions: []gax.CallOption{ |
| 219 |
gax.WithTimeout(60000 * time.Millisecond), |
| 220 |
gax.WithRetry(func() gax.Retryer { |
| 221 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 222 |
Initial: 1000 * time.Millisecond, |
| 223 |
Max: 10000 * time.Millisecond, |
| 224 |
Multiplier: 1.30, |
| 225 |
}, |
| 226 |
http.StatusServiceUnavailable) |
| 227 |
}), |
| 228 |
}, |
| 229 |
DeleteRegion: []gax.CallOption{ |
| 230 |
gax.WithTimeout(60000 * time.Millisecond), |
| 231 |
gax.WithRetry(func() gax.Retryer { |
| 232 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 233 |
Initial: 1000 * time.Millisecond, |
| 234 |
Max: 10000 * time.Millisecond, |
| 235 |
Multiplier: 1.30, |
| 236 |
}, |
| 237 |
http.StatusServiceUnavailable) |
| 238 |
}), |
| 239 |
}, |
| 240 |
BatchDeleteRegions: []gax.CallOption{ |
| 241 |
gax.WithTimeout(60000 * time.Millisecond), |
| 242 |
gax.WithRetry(func() gax.Retryer { |
| 243 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 244 |
Initial: 1000 * time.Millisecond, |
| 245 |
Max: 10000 * time.Millisecond, |
| 246 |
Multiplier: 1.30, |
| 247 |
}, |
| 248 |
http.StatusServiceUnavailable) |
| 249 |
}), |
| 250 |
}, |
| 251 |
ListRegions: []gax.CallOption{ |
| 252 |
gax.WithTimeout(60000 * time.Millisecond), |
| 253 |
gax.WithRetry(func() gax.Retryer { |
| 254 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 255 |
Initial: 1000 * time.Millisecond, |
| 256 |
Max: 10000 * time.Millisecond, |
| 257 |
Multiplier: 1.30, |
| 258 |
}, |
| 259 |
http.StatusServiceUnavailable) |
| 260 |
}), |
| 261 |
}, |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
// internalRegionsClient is an interface that defines the methods available from Merchant API. |
| 266 |
type internalRegionsClient interface { |
| 267 |
Close() error |
| 268 |
setGoogleClientInfo(...string) |
| 269 |
Connection() *grpc.ClientConn |
| 270 |
GetRegion(context.Context, *accountspb.GetRegionRequest, ...gax.CallOption) (*accountspb.Region, error) |
| 271 |
CreateRegion(context.Context, *accountspb.CreateRegionRequest, ...gax.CallOption) (*accountspb.Region, error) |
| 272 |
BatchCreateRegions(context.Context, *accountspb.BatchCreateRegionsRequest, ...gax.CallOption) (*accountspb.BatchCreateRegionsResponse, error) |
| 273 |
UpdateRegion(context.Context, *accountspb.UpdateRegionRequest, ...gax.CallOption) (*accountspb.Region, error) |
| 274 |
BatchUpdateRegions(context.Context, *accountspb.BatchUpdateRegionsRequest, ...gax.CallOption) (*accountspb.BatchUpdateRegionsResponse, error) |
| 275 |
DeleteRegion(context.Context, *accountspb.DeleteRegionRequest, ...gax.CallOption) error |
| 276 |
BatchDeleteRegions(context.Context, *accountspb.BatchDeleteRegionsRequest, ...gax.CallOption) error |
| 277 |
ListRegions(context.Context, *accountspb.ListRegionsRequest, ...gax.CallOption) *RegionIterator |
| 278 |
} |
| 279 |
|
| 280 |
// RegionsClient is a client for interacting with Merchant API. |
| 281 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 282 |
// |
| 283 |
// Manages regions configuration. |
| 284 |
// |
| 285 |
// This API defines the following resource model: |
| 286 |
// |
| 287 |
// Region |
| 288 |
type RegionsClient struct { |
| 289 |
// The internal transport-dependent client. |
| 290 |
internalClient internalRegionsClient |
| 291 |
|
| 292 |
// The call options for this service. |
| 293 |
CallOptions *RegionsCallOptions |
| 294 |
} |
| 295 |
|
| 296 |
// Wrapper methods routed to the internal client. |
| 297 |
|
| 298 |
// Close closes the connection to the API service. The user should invoke this when |
| 299 |
// the client is no longer required. |
| 300 |
func (c *RegionsClient) Close() error { |
| 301 |
return c.internalClient.Close() |
| 302 |
} |
| 303 |
|
| 304 |
// setGoogleClientInfo sets the name and version of the application in |
| 305 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 306 |
// use by Google-written clients. |
| 307 |
func (c *RegionsClient) setGoogleClientInfo(keyval ...string) { |
| 308 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 309 |
} |
| 310 |
|
| 311 |
// Connection returns a connection to the API service. |
| 312 |
// |
| 313 |
// Deprecated: Connections are now pooled so this method does not always |
| 314 |
// return the same resource. |
| 315 |
func (c *RegionsClient) Connection() *grpc.ClientConn { |
| 316 |
return c.internalClient.Connection() |
| 317 |
} |
| 318 |
|
| 319 |
// GetRegion retrieves a region defined in your Merchant Center account. |
| 320 |
func (c *RegionsClient) GetRegion(ctx context.Context, req *accountspb.GetRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 321 |
return c.internalClient.GetRegion(ctx, req, opts...) |
| 322 |
} |
| 323 |
|
| 324 |
// CreateRegion creates a region definition in your Merchant Center account. Executing this |
| 325 |
// method requires admin access. |
| 326 |
func (c *RegionsClient) CreateRegion(ctx context.Context, req *accountspb.CreateRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 327 |
return c.internalClient.CreateRegion(ctx, req, opts...) |
| 328 |
} |
| 329 |
|
| 330 |
// BatchCreateRegions creates one or more regions in your Merchant Center account. |
| 331 |
// Executing this method requires admin access. |
| 332 |
func (c *RegionsClient) BatchCreateRegions(ctx context.Context, req *accountspb.BatchCreateRegionsRequest, opts ...gax.CallOption) (*accountspb.BatchCreateRegionsResponse, error) { |
| 333 |
return c.internalClient.BatchCreateRegions(ctx, req, opts...) |
| 334 |
} |
| 335 |
|
| 336 |
// UpdateRegion updates a region definition in your Merchant Center account. |
| 337 |
// Executing this method requires admin access. |
| 338 |
func (c *RegionsClient) UpdateRegion(ctx context.Context, req *accountspb.UpdateRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 339 |
return c.internalClient.UpdateRegion(ctx, req, opts...) |
| 340 |
} |
| 341 |
|
| 342 |
// BatchUpdateRegions updates one or more regions in your Merchant Center account. |
| 343 |
// Executing this method requires admin access. |
| 344 |
func (c *RegionsClient) BatchUpdateRegions(ctx context.Context, req *accountspb.BatchUpdateRegionsRequest, opts ...gax.CallOption) (*accountspb.BatchUpdateRegionsResponse, error) { |
| 345 |
return c.internalClient.BatchUpdateRegions(ctx, req, opts...) |
| 346 |
} |
| 347 |
|
| 348 |
// DeleteRegion deletes a region definition from your Merchant Center account. Executing |
| 349 |
// this method requires admin access. |
| 350 |
func (c *RegionsClient) DeleteRegion(ctx context.Context, req *accountspb.DeleteRegionRequest, opts ...gax.CallOption) error { |
| 351 |
return c.internalClient.DeleteRegion(ctx, req, opts...) |
| 352 |
} |
| 353 |
|
| 354 |
// BatchDeleteRegions deletes multiple regions by name from your Merchant Center account. |
| 355 |
// Executing this method requires admin access. |
| 356 |
func (c *RegionsClient) BatchDeleteRegions(ctx context.Context, req *accountspb.BatchDeleteRegionsRequest, opts ...gax.CallOption) error { |
| 357 |
return c.internalClient.BatchDeleteRegions(ctx, req, opts...) |
| 358 |
} |
| 359 |
|
| 360 |
// ListRegions lists the regions in your Merchant Center account. |
| 361 |
func (c *RegionsClient) ListRegions(ctx context.Context, req *accountspb.ListRegionsRequest, opts ...gax.CallOption) *RegionIterator { |
| 362 |
return c.internalClient.ListRegions(ctx, req, opts...) |
| 363 |
} |
| 364 |
|
| 365 |
// regionsGRPCClient is a client for interacting with Merchant API over gRPC transport. |
| 366 |
// |
| 367 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 368 |
type regionsGRPCClient struct { |
| 369 |
// Connection pool of gRPC connections to the service. |
| 370 |
connPool gtransport.ConnPool |
| 371 |
|
| 372 |
// Points back to the CallOptions field of the containing RegionsClient |
| 373 |
CallOptions **RegionsCallOptions |
| 374 |
|
| 375 |
// The gRPC API client. |
| 376 |
regionsClient accountspb.RegionsServiceClient |
| 377 |
|
| 378 |
// The x-goog-* metadata to be sent with each request. |
| 379 |
xGoogHeaders []string |
| 380 |
|
| 381 |
logger *slog.Logger |
| 382 |
} |
| 383 |
|
| 384 |
// NewRegionsClient creates a new regions service client based on gRPC. |
| 385 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 386 |
// |
| 387 |
// Manages regions configuration. |
| 388 |
// |
| 389 |
// This API defines the following resource model: |
| 390 |
// |
| 391 |
// Region |
| 392 |
func NewRegionsClient(ctx context.Context, opts ...option.ClientOption) (*RegionsClient, error) { |
| 393 |
clientOpts := defaultRegionsGRPCClientOptions() |
| 394 |
if newRegionsClientHook != nil { |
| 395 |
hookOpts, err := newRegionsClientHook(ctx, clientHookParams{}) |
| 396 |
if err != nil { |
| 397 |
return nil, err |
| 398 |
} |
| 399 |
clientOpts = append(clientOpts, hookOpts...) |
| 400 |
} |
| 401 |
|
| 402 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 403 |
if err != nil { |
| 404 |
return nil, err |
| 405 |
} |
| 406 |
client := RegionsClient{CallOptions: defaultRegionsCallOptions()} |
| 407 |
|
| 408 |
c := ®ionsGRPCClient{ |
| 409 |
connPool: connPool, |
| 410 |
regionsClient: accountspb.NewRegionsServiceClient(connPool), |
| 411 |
CallOptions: &client.CallOptions, |
| 412 |
logger: internaloption.GetLogger(opts), |
| 413 |
} |
| 414 |
c.setGoogleClientInfo() |
| 415 |
|
| 416 |
client.internalClient = c |
| 417 |
|
| 418 |
return &client, nil |
| 419 |
} |
| 420 |
|
| 421 |
// Connection returns a connection to the API service. |
| 422 |
// |
| 423 |
// Deprecated: Connections are now pooled so this method does not always |
| 424 |
// return the same resource. |
| 425 |
func (c *regionsGRPCClient) Connection() *grpc.ClientConn { |
| 426 |
return c.connPool.Conn() |
| 427 |
} |
| 428 |
|
| 429 |
// setGoogleClientInfo sets the name and version of the application in |
| 430 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 431 |
// use by Google-written clients. |
| 432 |
func (c *regionsGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 433 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 434 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 435 |
c.xGoogHeaders = []string{ |
| 436 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
// Close closes the connection to the API service. The user should invoke this when |
| 441 |
// the client is no longer required. |
| 442 |
func (c *regionsGRPCClient) Close() error { |
| 443 |
return c.connPool.Close() |
| 444 |
} |
| 445 |
|
| 446 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 447 |
type regionsRESTClient struct { |
| 448 |
// The http endpoint to connect to. |
| 449 |
endpoint string |
| 450 |
|
| 451 |
// The http client. |
| 452 |
httpClient *http.Client |
| 453 |
|
| 454 |
// The x-goog-* headers to be sent with each request. |
| 455 |
xGoogHeaders []string |
| 456 |
|
| 457 |
// Points back to the CallOptions field of the containing RegionsClient |
| 458 |
CallOptions **RegionsCallOptions |
| 459 |
|
| 460 |
logger *slog.Logger |
| 461 |
} |
| 462 |
|
| 463 |
// NewRegionsRESTClient creates a new regions service rest client. |
| 464 |
// |
| 465 |
// Manages regions configuration. |
| 466 |
// |
| 467 |
// This API defines the following resource model: |
| 468 |
// |
| 469 |
// Region |
| 470 |
func NewRegionsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionsClient, error) { |
| 471 |
clientOpts := append(defaultRegionsRESTClientOptions(), opts...) |
| 472 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 473 |
if err != nil { |
| 474 |
return nil, err |
| 475 |
} |
| 476 |
|
| 477 |
callOpts := defaultRegionsRESTCallOptions() |
| 478 |
c := ®ionsRESTClient{ |
| 479 |
endpoint: endpoint, |
| 480 |
httpClient: httpClient, |
| 481 |
CallOptions: &callOpts, |
| 482 |
logger: internaloption.GetLogger(opts), |
| 483 |
} |
| 484 |
c.setGoogleClientInfo() |
| 485 |
|
| 486 |
return &RegionsClient{internalClient: c, CallOptions: callOpts}, nil |
| 487 |
} |
| 488 |
|
| 489 |
func defaultRegionsRESTClientOptions() []option.ClientOption { |
| 490 |
return []option.ClientOption{ |
| 491 |
internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"), |
| 492 |
internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"), |
| 493 |
internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"), |
| 494 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 495 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 496 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 497 |
internaloption.EnableNewAuthLibrary(), |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
// setGoogleClientInfo sets the name and version of the application in |
| 502 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 503 |
// use by Google-written clients. |
| 504 |
func (c *regionsRESTClient) setGoogleClientInfo(keyval ...string) { |
| 505 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 506 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 507 |
c.xGoogHeaders = []string{ |
| 508 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
// Close closes the connection to the API service. The user should invoke this when |
| 513 |
// the client is no longer required. |
| 514 |
func (c *regionsRESTClient) Close() error { |
| 515 |
// Replace httpClient with nil to force cleanup. |
| 516 |
c.httpClient = nil |
| 517 |
return nil |
| 518 |
} |
| 519 |
|
| 520 |
// Connection returns a connection to the API service. |
| 521 |
// |
| 522 |
// Deprecated: This method always returns nil. |
| 523 |
func (c *regionsRESTClient) Connection() *grpc.ClientConn { |
| 524 |
return nil |
| 525 |
} |
| 526 |
func (c *regionsGRPCClient) GetRegion(ctx context.Context, req *accountspb.GetRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 527 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 528 |
|
| 529 |
hds = append(c.xGoogHeaders, hds...) |
| 530 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 531 |
opts = append((*c.CallOptions).GetRegion[0:len((*c.CallOptions).GetRegion):len((*c.CallOptions).GetRegion)], opts...) |
| 532 |
var resp *accountspb.Region |
| 533 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 534 |
var err error |
| 535 |
resp, err = executeRPC(ctx, c.regionsClient.GetRegion, req, settings.GRPC, c.logger, "GetRegion") |
| 536 |
return err |
| 537 |
}, opts...) |
| 538 |
if err != nil { |
| 539 |
return nil, err |
| 540 |
} |
| 541 |
return resp, nil |
| 542 |
} |
| 543 |
|
| 544 |
func (c *regionsGRPCClient) CreateRegion(ctx context.Context, req *accountspb.CreateRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 545 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 546 |
|
| 547 |
hds = append(c.xGoogHeaders, hds...) |
| 548 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 549 |
opts = append((*c.CallOptions).CreateRegion[0:len((*c.CallOptions).CreateRegion):len((*c.CallOptions).CreateRegion)], opts...) |
| 550 |
var resp *accountspb.Region |
| 551 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 552 |
var err error |
| 553 |
resp, err = executeRPC(ctx, c.regionsClient.CreateRegion, req, settings.GRPC, c.logger, "CreateRegion") |
| 554 |
return err |
| 555 |
}, opts...) |
| 556 |
if err != nil { |
| 557 |
return nil, err |
| 558 |
} |
| 559 |
return resp, nil |
| 560 |
} |
| 561 |
|
| 562 |
func (c *regionsGRPCClient) BatchCreateRegions(ctx context.Context, req *accountspb.BatchCreateRegionsRequest, opts ...gax.CallOption) (*accountspb.BatchCreateRegionsResponse, error) { |
| 563 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 564 |
|
| 565 |
hds = append(c.xGoogHeaders, hds...) |
| 566 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 567 |
opts = append((*c.CallOptions).BatchCreateRegions[0:len((*c.CallOptions).BatchCreateRegions):len((*c.CallOptions).BatchCreateRegions)], opts...) |
| 568 |
var resp *accountspb.BatchCreateRegionsResponse |
| 569 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 570 |
var err error |
| 571 |
resp, err = executeRPC(ctx, c.regionsClient.BatchCreateRegions, req, settings.GRPC, c.logger, "BatchCreateRegions") |
| 572 |
return err |
| 573 |
}, opts...) |
| 574 |
if err != nil { |
| 575 |
return nil, err |
| 576 |
} |
| 577 |
return resp, nil |
| 578 |
} |
| 579 |
|
| 580 |
func (c *regionsGRPCClient) UpdateRegion(ctx context.Context, req *accountspb.UpdateRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 581 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "region.name", url.QueryEscape(req.GetRegion().GetName()))} |
| 582 |
|
| 583 |
hds = append(c.xGoogHeaders, hds...) |
| 584 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 585 |
opts = append((*c.CallOptions).UpdateRegion[0:len((*c.CallOptions).UpdateRegion):len((*c.CallOptions).UpdateRegion)], opts...) |
| 586 |
var resp *accountspb.Region |
| 587 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 588 |
var err error |
| 589 |
resp, err = executeRPC(ctx, c.regionsClient.UpdateRegion, req, settings.GRPC, c.logger, "UpdateRegion") |
| 590 |
return err |
| 591 |
}, opts...) |
| 592 |
if err != nil { |
| 593 |
return nil, err |
| 594 |
} |
| 595 |
return resp, nil |
| 596 |
} |
| 597 |
|
| 598 |
func (c *regionsGRPCClient) BatchUpdateRegions(ctx context.Context, req *accountspb.BatchUpdateRegionsRequest, opts ...gax.CallOption) (*accountspb.BatchUpdateRegionsResponse, error) { |
| 599 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 600 |
|
| 601 |
hds = append(c.xGoogHeaders, hds...) |
| 602 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 603 |
opts = append((*c.CallOptions).BatchUpdateRegions[0:len((*c.CallOptions).BatchUpdateRegions):len((*c.CallOptions).BatchUpdateRegions)], opts...) |
| 604 |
var resp *accountspb.BatchUpdateRegionsResponse |
| 605 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 606 |
var err error |
| 607 |
resp, err = executeRPC(ctx, c.regionsClient.BatchUpdateRegions, req, settings.GRPC, c.logger, "BatchUpdateRegions") |
| 608 |
return err |
| 609 |
}, opts...) |
| 610 |
if err != nil { |
| 611 |
return nil, err |
| 612 |
} |
| 613 |
return resp, nil |
| 614 |
} |
| 615 |
|
| 616 |
func (c *regionsGRPCClient) DeleteRegion(ctx context.Context, req *accountspb.DeleteRegionRequest, opts ...gax.CallOption) error { |
| 617 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 618 |
|
| 619 |
hds = append(c.xGoogHeaders, hds...) |
| 620 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 621 |
opts = append((*c.CallOptions).DeleteRegion[0:len((*c.CallOptions).DeleteRegion):len((*c.CallOptions).DeleteRegion)], opts...) |
| 622 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 623 |
var err error |
| 624 |
_, err = executeRPC(ctx, c.regionsClient.DeleteRegion, req, settings.GRPC, c.logger, "DeleteRegion") |
| 625 |
return err |
| 626 |
}, opts...) |
| 627 |
return err |
| 628 |
} |
| 629 |
|
| 630 |
func (c *regionsGRPCClient) BatchDeleteRegions(ctx context.Context, req *accountspb.BatchDeleteRegionsRequest, opts ...gax.CallOption) error { |
| 631 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 632 |
|
| 633 |
hds = append(c.xGoogHeaders, hds...) |
| 634 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 635 |
opts = append((*c.CallOptions).BatchDeleteRegions[0:len((*c.CallOptions).BatchDeleteRegions):len((*c.CallOptions).BatchDeleteRegions)], opts...) |
| 636 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 637 |
var err error |
| 638 |
_, err = executeRPC(ctx, c.regionsClient.BatchDeleteRegions, req, settings.GRPC, c.logger, "BatchDeleteRegions") |
| 639 |
return err |
| 640 |
}, opts...) |
| 641 |
return err |
| 642 |
} |
| 643 |
|
| 644 |
func (c *regionsGRPCClient) ListRegions(ctx context.Context, req *accountspb.ListRegionsRequest, opts ...gax.CallOption) *RegionIterator { |
| 645 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 646 |
|
| 647 |
hds = append(c.xGoogHeaders, hds...) |
| 648 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 649 |
opts = append((*c.CallOptions).ListRegions[0:len((*c.CallOptions).ListRegions):len((*c.CallOptions).ListRegions)], opts...) |
| 650 |
it := &RegionIterator{} |
| 651 |
req = proto.Clone(req).(*accountspb.ListRegionsRequest) |
| 652 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Region, string, error) { |
| 653 |
resp := &accountspb.ListRegionsResponse{} |
| 654 |
if pageToken != "" { |
| 655 |
req.PageToken = pageToken |
| 656 |
} |
| 657 |
if pageSize > math.MaxInt32 { |
| 658 |
req.PageSize = math.MaxInt32 |
| 659 |
} else if pageSize != 0 { |
| 660 |
req.PageSize = int32(pageSize) |
| 661 |
} |
| 662 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 663 |
var err error |
| 664 |
resp, err = executeRPC(ctx, c.regionsClient.ListRegions, req, settings.GRPC, c.logger, "ListRegions") |
| 665 |
return err |
| 666 |
}, opts...) |
| 667 |
if err != nil { |
| 668 |
return nil, "", err |
| 669 |
} |
| 670 |
|
| 671 |
it.Response = resp |
| 672 |
return resp.GetRegions(), resp.GetNextPageToken(), nil |
| 673 |
} |
| 674 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 675 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 676 |
if err != nil { |
| 677 |
return "", err |
| 678 |
} |
| 679 |
it.items = append(it.items, items...) |
| 680 |
return nextPageToken, nil |
| 681 |
} |
| 682 |
|
| 683 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 684 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 685 |
it.pageInfo.Token = req.GetPageToken() |
| 686 |
|
| 687 |
return it |
| 688 |
} |
| 689 |
|
| 690 |
// GetRegion retrieves a region defined in your Merchant Center account. |
| 691 |
func (c *regionsRESTClient) GetRegion(ctx context.Context, req *accountspb.GetRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 692 |
baseUrl, err := url.Parse(c.endpoint) |
| 693 |
if err != nil { |
| 694 |
return nil, err |
| 695 |
} |
| 696 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetName()) |
| 697 |
|
| 698 |
params := url.Values{} |
| 699 |
params.Add("$alt", "json;enum-encoding=int") |
| 700 |
|
| 701 |
baseUrl.RawQuery = params.Encode() |
| 702 |
|
| 703 |
// Build HTTP headers from client and context metadata. |
| 704 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 705 |
|
| 706 |
hds = append(c.xGoogHeaders, hds...) |
| 707 |
hds = append(hds, "Content-Type", "application/json") |
| 708 |
headers := gax.BuildHeaders(ctx, hds...) |
| 709 |
opts = append((*c.CallOptions).GetRegion[0:len((*c.CallOptions).GetRegion):len((*c.CallOptions).GetRegion)], opts...) |
| 710 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 711 |
resp := &accountspb.Region{} |
| 712 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 713 |
if settings.Path != "" { |
| 714 |
baseUrl.Path = settings.Path |
| 715 |
} |
| 716 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 717 |
if err != nil { |
| 718 |
return err |
| 719 |
} |
| 720 |
httpReq = httpReq.WithContext(ctx) |
| 721 |
httpReq.Header = headers |
| 722 |
|
| 723 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetRegion") |
| 724 |
if err != nil { |
| 725 |
return err |
| 726 |
} |
| 727 |
|
| 728 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 729 |
return err |
| 730 |
} |
| 731 |
|
| 732 |
return nil |
| 733 |
}, opts...) |
| 734 |
if e != nil { |
| 735 |
return nil, e |
| 736 |
} |
| 737 |
return resp, nil |
| 738 |
} |
| 739 |
|
| 740 |
// CreateRegion creates a region definition in your Merchant Center account. Executing this |
| 741 |
// method requires admin access. |
| 742 |
func (c *regionsRESTClient) CreateRegion(ctx context.Context, req *accountspb.CreateRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 743 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 744 |
body := req.GetRegion() |
| 745 |
jsonReq, err := m.Marshal(body) |
| 746 |
if err != nil { |
| 747 |
return nil, err |
| 748 |
} |
| 749 |
|
| 750 |
baseUrl, err := url.Parse(c.endpoint) |
| 751 |
if err != nil { |
| 752 |
return nil, err |
| 753 |
} |
| 754 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/regions", req.GetParent()) |
| 755 |
|
| 756 |
params := url.Values{} |
| 757 |
params.Add("$alt", "json;enum-encoding=int") |
| 758 |
params.Add("regionId", fmt.Sprintf("%v", req.GetRegionId())) |
| 759 |
|
| 760 |
baseUrl.RawQuery = params.Encode() |
| 761 |
|
| 762 |
// Build HTTP headers from client and context metadata. |
| 763 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 764 |
|
| 765 |
hds = append(c.xGoogHeaders, hds...) |
| 766 |
hds = append(hds, "Content-Type", "application/json") |
| 767 |
headers := gax.BuildHeaders(ctx, hds...) |
| 768 |
opts = append((*c.CallOptions).CreateRegion[0:len((*c.CallOptions).CreateRegion):len((*c.CallOptions).CreateRegion)], opts...) |
| 769 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 770 |
resp := &accountspb.Region{} |
| 771 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 772 |
if settings.Path != "" { |
| 773 |
baseUrl.Path = settings.Path |
| 774 |
} |
| 775 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 776 |
if err != nil { |
| 777 |
return err |
| 778 |
} |
| 779 |
httpReq = httpReq.WithContext(ctx) |
| 780 |
httpReq.Header = headers |
| 781 |
|
| 782 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateRegion") |
| 783 |
if err != nil { |
| 784 |
return err |
| 785 |
} |
| 786 |
|
| 787 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 788 |
return err |
| 789 |
} |
| 790 |
|
| 791 |
return nil |
| 792 |
}, opts...) |
| 793 |
if e != nil { |
| 794 |
return nil, e |
| 795 |
} |
| 796 |
return resp, nil |
| 797 |
} |
| 798 |
|
| 799 |
// BatchCreateRegions creates one or more regions in your Merchant Center account. |
| 800 |
// Executing this method requires admin access. |
| 801 |
func (c *regionsRESTClient) BatchCreateRegions(ctx context.Context, req *accountspb.BatchCreateRegionsRequest, opts ...gax.CallOption) (*accountspb.BatchCreateRegionsResponse, error) { |
| 802 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 803 |
jsonReq, err := m.Marshal(req) |
| 804 |
if err != nil { |
| 805 |
return nil, err |
| 806 |
} |
| 807 |
|
| 808 |
baseUrl, err := url.Parse(c.endpoint) |
| 809 |
if err != nil { |
| 810 |
return nil, err |
| 811 |
} |
| 812 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/regions:batchCreate", req.GetParent()) |
| 813 |
|
| 814 |
params := url.Values{} |
| 815 |
params.Add("$alt", "json;enum-encoding=int") |
| 816 |
|
| 817 |
baseUrl.RawQuery = params.Encode() |
| 818 |
|
| 819 |
// Build HTTP headers from client and context metadata. |
| 820 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 821 |
|
| 822 |
hds = append(c.xGoogHeaders, hds...) |
| 823 |
hds = append(hds, "Content-Type", "application/json") |
| 824 |
headers := gax.BuildHeaders(ctx, hds...) |
| 825 |
opts = append((*c.CallOptions).BatchCreateRegions[0:len((*c.CallOptions).BatchCreateRegions):len((*c.CallOptions).BatchCreateRegions)], opts...) |
| 826 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 827 |
resp := &accountspb.BatchCreateRegionsResponse{} |
| 828 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 829 |
if settings.Path != "" { |
| 830 |
baseUrl.Path = settings.Path |
| 831 |
} |
| 832 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 833 |
if err != nil { |
| 834 |
return err |
| 835 |
} |
| 836 |
httpReq = httpReq.WithContext(ctx) |
| 837 |
httpReq.Header = headers |
| 838 |
|
| 839 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchCreateRegions") |
| 840 |
if err != nil { |
| 841 |
return err |
| 842 |
} |
| 843 |
|
| 844 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 845 |
return err |
| 846 |
} |
| 847 |
|
| 848 |
return nil |
| 849 |
}, opts...) |
| 850 |
if e != nil { |
| 851 |
return nil, e |
| 852 |
} |
| 853 |
return resp, nil |
| 854 |
} |
| 855 |
|
| 856 |
// UpdateRegion updates a region definition in your Merchant Center account. |
| 857 |
// Executing this method requires admin access. |
| 858 |
func (c *regionsRESTClient) UpdateRegion(ctx context.Context, req *accountspb.UpdateRegionRequest, opts ...gax.CallOption) (*accountspb.Region, error) { |
| 859 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 860 |
body := req.GetRegion() |
| 861 |
jsonReq, err := m.Marshal(body) |
| 862 |
if err != nil { |
| 863 |
return nil, err |
| 864 |
} |
| 865 |
|
| 866 |
baseUrl, err := url.Parse(c.endpoint) |
| 867 |
if err != nil { |
| 868 |
return nil, err |
| 869 |
} |
| 870 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetRegion().GetName()) |
| 871 |
|
| 872 |
params := url.Values{} |
| 873 |
params.Add("$alt", "json;enum-encoding=int") |
| 874 |
if req.GetUpdateMask() != nil { |
| 875 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 876 |
if err != nil { |
| 877 |
return nil, err |
| 878 |
} |
| 879 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 880 |
} |
| 881 |
|
| 882 |
baseUrl.RawQuery = params.Encode() |
| 883 |
|
| 884 |
// Build HTTP headers from client and context metadata. |
| 885 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "region.name", url.QueryEscape(req.GetRegion().GetName()))} |
| 886 |
|
| 887 |
hds = append(c.xGoogHeaders, hds...) |
| 888 |
hds = append(hds, "Content-Type", "application/json") |
| 889 |
headers := gax.BuildHeaders(ctx, hds...) |
| 890 |
opts = append((*c.CallOptions).UpdateRegion[0:len((*c.CallOptions).UpdateRegion):len((*c.CallOptions).UpdateRegion)], opts...) |
| 891 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 892 |
resp := &accountspb.Region{} |
| 893 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 894 |
if settings.Path != "" { |
| 895 |
baseUrl.Path = settings.Path |
| 896 |
} |
| 897 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 898 |
if err != nil { |
| 899 |
return err |
| 900 |
} |
| 901 |
httpReq = httpReq.WithContext(ctx) |
| 902 |
httpReq.Header = headers |
| 903 |
|
| 904 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateRegion") |
| 905 |
if err != nil { |
| 906 |
return err |
| 907 |
} |
| 908 |
|
| 909 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 910 |
return err |
| 911 |
} |
| 912 |
|
| 913 |
return nil |
| 914 |
}, opts...) |
| 915 |
if e != nil { |
| 916 |
return nil, e |
| 917 |
} |
| 918 |
return resp, nil |
| 919 |
} |
| 920 |
|
| 921 |
// BatchUpdateRegions updates one or more regions in your Merchant Center account. |
| 922 |
// Executing this method requires admin access. |
| 923 |
func (c *regionsRESTClient) BatchUpdateRegions(ctx context.Context, req *accountspb.BatchUpdateRegionsRequest, opts ...gax.CallOption) (*accountspb.BatchUpdateRegionsResponse, error) { |
| 924 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 925 |
jsonReq, err := m.Marshal(req) |
| 926 |
if err != nil { |
| 927 |
return nil, err |
| 928 |
} |
| 929 |
|
| 930 |
baseUrl, err := url.Parse(c.endpoint) |
| 931 |
if err != nil { |
| 932 |
return nil, err |
| 933 |
} |
| 934 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/regions:batchUpdate", req.GetParent()) |
| 935 |
|
| 936 |
params := url.Values{} |
| 937 |
params.Add("$alt", "json;enum-encoding=int") |
| 938 |
|
| 939 |
baseUrl.RawQuery = params.Encode() |
| 940 |
|
| 941 |
// Build HTTP headers from client and context metadata. |
| 942 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 943 |
|
| 944 |
hds = append(c.xGoogHeaders, hds...) |
| 945 |
hds = append(hds, "Content-Type", "application/json") |
| 946 |
headers := gax.BuildHeaders(ctx, hds...) |
| 947 |
opts = append((*c.CallOptions).BatchUpdateRegions[0:len((*c.CallOptions).BatchUpdateRegions):len((*c.CallOptions).BatchUpdateRegions)], opts...) |
| 948 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 949 |
resp := &accountspb.BatchUpdateRegionsResponse{} |
| 950 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 951 |
if settings.Path != "" { |
| 952 |
baseUrl.Path = settings.Path |
| 953 |
} |
| 954 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 955 |
if err != nil { |
| 956 |
return err |
| 957 |
} |
| 958 |
httpReq = httpReq.WithContext(ctx) |
| 959 |
httpReq.Header = headers |
| 960 |
|
| 961 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchUpdateRegions") |
| 962 |
if err != nil { |
| 963 |
return err |
| 964 |
} |
| 965 |
|
| 966 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 967 |
return err |
| 968 |
} |
| 969 |
|
| 970 |
return nil |
| 971 |
}, opts...) |
| 972 |
if e != nil { |
| 973 |
return nil, e |
| 974 |
} |
| 975 |
return resp, nil |
| 976 |
} |
| 977 |
|
| 978 |
// DeleteRegion deletes a region definition from your Merchant Center account. Executing |
| 979 |
// this method requires admin access. |
| 980 |
func (c *regionsRESTClient) DeleteRegion(ctx context.Context, req *accountspb.DeleteRegionRequest, opts ...gax.CallOption) error { |
| 981 |
baseUrl, err := url.Parse(c.endpoint) |
| 982 |
if err != nil { |
| 983 |
return err |
| 984 |
} |
| 985 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetName()) |
| 986 |
|
| 987 |
params := url.Values{} |
| 988 |
params.Add("$alt", "json;enum-encoding=int") |
| 989 |
|
| 990 |
baseUrl.RawQuery = params.Encode() |
| 991 |
|
| 992 |
// Build HTTP headers from client and context metadata. |
| 993 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 994 |
|
| 995 |
hds = append(c.xGoogHeaders, hds...) |
| 996 |
hds = append(hds, "Content-Type", "application/json") |
| 997 |
headers := gax.BuildHeaders(ctx, hds...) |
| 998 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 999 |
if settings.Path != "" { |
| 1000 |
baseUrl.Path = settings.Path |
| 1001 |
} |
| 1002 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1003 |
if err != nil { |
| 1004 |
return err |
| 1005 |
} |
| 1006 |
httpReq = httpReq.WithContext(ctx) |
| 1007 |
httpReq.Header = headers |
| 1008 |
|
| 1009 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteRegion") |
| 1010 |
return err |
| 1011 |
}, opts...) |
| 1012 |
} |
| 1013 |
|
| 1014 |
// BatchDeleteRegions deletes multiple regions by name from your Merchant Center account. |
| 1015 |
// Executing this method requires admin access. |
| 1016 |
func (c *regionsRESTClient) BatchDeleteRegions(ctx context.Context, req *accountspb.BatchDeleteRegionsRequest, opts ...gax.CallOption) error { |
| 1017 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1018 |
jsonReq, err := m.Marshal(req) |
| 1019 |
if err != nil { |
| 1020 |
return err |
| 1021 |
} |
| 1022 |
|
| 1023 |
baseUrl, err := url.Parse(c.endpoint) |
| 1024 |
if err != nil { |
| 1025 |
return err |
| 1026 |
} |
| 1027 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/regions:batchDelete", req.GetParent()) |
| 1028 |
|
| 1029 |
params := url.Values{} |
| 1030 |
params.Add("$alt", "json;enum-encoding=int") |
| 1031 |
|
| 1032 |
baseUrl.RawQuery = params.Encode() |
| 1033 |
|
| 1034 |
// Build HTTP headers from client and context metadata. |
| 1035 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1036 |
|
| 1037 |
hds = append(c.xGoogHeaders, hds...) |
| 1038 |
hds = append(hds, "Content-Type", "application/json") |
| 1039 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1040 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1041 |
if settings.Path != "" { |
| 1042 |
baseUrl.Path = settings.Path |
| 1043 |
} |
| 1044 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1045 |
if err != nil { |
| 1046 |
return err |
| 1047 |
} |
| 1048 |
httpReq = httpReq.WithContext(ctx) |
| 1049 |
httpReq.Header = headers |
| 1050 |
|
| 1051 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BatchDeleteRegions") |
| 1052 |
return err |
| 1053 |
}, opts...) |
| 1054 |
} |
| 1055 |
|
| 1056 |
// ListRegions lists the regions in your Merchant Center account. |
| 1057 |
func (c *regionsRESTClient) ListRegions(ctx context.Context, req *accountspb.ListRegionsRequest, opts ...gax.CallOption) *RegionIterator { |
| 1058 |
it := &RegionIterator{} |
| 1059 |
req = proto.Clone(req).(*accountspb.ListRegionsRequest) |
| 1060 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1061 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Region, string, error) { |
| 1062 |
resp := &accountspb.ListRegionsResponse{} |
| 1063 |
if pageToken != "" { |
| 1064 |
req.PageToken = pageToken |
| 1065 |
} |
| 1066 |
if pageSize > math.MaxInt32 { |
| 1067 |
req.PageSize = math.MaxInt32 |
| 1068 |
} else if pageSize != 0 { |
| 1069 |
req.PageSize = int32(pageSize) |
| 1070 |
} |
| 1071 |
baseUrl, err := url.Parse(c.endpoint) |
| 1072 |
if err != nil { |
| 1073 |
return nil, "", err |
| 1074 |
} |
| 1075 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/regions", req.GetParent()) |
| 1076 |
|
| 1077 |
params := url.Values{} |
| 1078 |
params.Add("$alt", "json;enum-encoding=int") |
| 1079 |
if req.GetPageSize() != 0 { |
| 1080 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1081 |
} |
| 1082 |
if req.GetPageToken() != "" { |
| 1083 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1084 |
} |
| 1085 |
|
| 1086 |
baseUrl.RawQuery = params.Encode() |
| 1087 |
|
| 1088 |
// Build HTTP headers from client and context metadata. |
| 1089 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1090 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1091 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1092 |
if settings.Path != "" { |
| 1093 |
baseUrl.Path = settings.Path |
| 1094 |
} |
| 1095 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1096 |
if err != nil { |
| 1097 |
return err |
| 1098 |
} |
| 1099 |
httpReq.Header = headers |
| 1100 |
|
| 1101 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListRegions") |
| 1102 |
if err != nil { |
| 1103 |
return err |
| 1104 |
} |
| 1105 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1106 |
return err |
| 1107 |
} |
| 1108 |
|
| 1109 |
return nil |
| 1110 |
}, opts...) |
| 1111 |
if e != nil { |
| 1112 |
return nil, "", e |
| 1113 |
} |
| 1114 |
it.Response = resp |
| 1115 |
return resp.GetRegions(), resp.GetNextPageToken(), nil |
| 1116 |
} |
| 1117 |
|
| 1118 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1119 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1120 |
if err != nil { |
| 1121 |
return "", err |
| 1122 |
} |
| 1123 |
it.items = append(it.items, items...) |
| 1124 |
return nextPageToken, nil |
| 1125 |
} |
| 1126 |
|
| 1127 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1128 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1129 |
it.pageInfo.Token = req.GetPageToken() |
| 1130 |
|
| 1131 |
return it |
| 1132 |
} |