| 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 inventories |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
inventoriespb "cloud.google.com/go/shopping/merchant/inventories/apiv1beta/inventoriespb" |
| 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 newLocalInventoryClientHook clientHook |
| 43 |
|
| 44 |
// LocalInventoryCallOptions contains the retry settings for each method of LocalInventoryClient. |
| 45 |
type LocalInventoryCallOptions struct { |
| 46 |
ListLocalInventories []gax.CallOption |
| 47 |
InsertLocalInventory []gax.CallOption |
| 48 |
DeleteLocalInventory []gax.CallOption |
| 49 |
} |
| 50 |
|
| 51 |
func defaultLocalInventoryGRPCClientOptions() []option.ClientOption { |
| 52 |
return []option.ClientOption{ |
| 53 |
internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"), |
| 54 |
internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"), |
| 55 |
internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"), |
| 56 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 57 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 58 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 59 |
internaloption.EnableJwtWithScope(), |
| 60 |
internaloption.EnableNewAuthLibrary(), |
| 61 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 62 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
func defaultLocalInventoryCallOptions() *LocalInventoryCallOptions { |
| 67 |
return &LocalInventoryCallOptions{ |
| 68 |
ListLocalInventories: []gax.CallOption{ |
| 69 |
gax.WithTimeout(60000 * time.Millisecond), |
| 70 |
gax.WithRetry(func() gax.Retryer { |
| 71 |
return gax.OnCodes([]codes.Code{ |
| 72 |
codes.Unavailable, |
| 73 |
}, gax.Backoff{ |
| 74 |
Initial: 1000 * time.Millisecond, |
| 75 |
Max: 10000 * time.Millisecond, |
| 76 |
Multiplier: 1.30, |
| 77 |
}) |
| 78 |
}), |
| 79 |
}, |
| 80 |
InsertLocalInventory: []gax.CallOption{ |
| 81 |
gax.WithTimeout(60000 * time.Millisecond), |
| 82 |
gax.WithRetry(func() gax.Retryer { |
| 83 |
return gax.OnCodes([]codes.Code{ |
| 84 |
codes.Unavailable, |
| 85 |
}, gax.Backoff{ |
| 86 |
Initial: 1000 * time.Millisecond, |
| 87 |
Max: 10000 * time.Millisecond, |
| 88 |
Multiplier: 1.30, |
| 89 |
}) |
| 90 |
}), |
| 91 |
}, |
| 92 |
DeleteLocalInventory: []gax.CallOption{ |
| 93 |
gax.WithTimeout(60000 * time.Millisecond), |
| 94 |
gax.WithRetry(func() gax.Retryer { |
| 95 |
return gax.OnCodes([]codes.Code{ |
| 96 |
codes.Unavailable, |
| 97 |
}, gax.Backoff{ |
| 98 |
Initial: 1000 * time.Millisecond, |
| 99 |
Max: 10000 * time.Millisecond, |
| 100 |
Multiplier: 1.30, |
| 101 |
}) |
| 102 |
}), |
| 103 |
}, |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
func defaultLocalInventoryRESTCallOptions() *LocalInventoryCallOptions { |
| 108 |
return &LocalInventoryCallOptions{ |
| 109 |
ListLocalInventories: []gax.CallOption{ |
| 110 |
gax.WithTimeout(60000 * time.Millisecond), |
| 111 |
gax.WithRetry(func() gax.Retryer { |
| 112 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 113 |
Initial: 1000 * time.Millisecond, |
| 114 |
Max: 10000 * time.Millisecond, |
| 115 |
Multiplier: 1.30, |
| 116 |
}, |
| 117 |
http.StatusServiceUnavailable) |
| 118 |
}), |
| 119 |
}, |
| 120 |
InsertLocalInventory: []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 |
DeleteLocalInventory: []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 |
} |
| 143 |
} |
| 144 |
|
| 145 |
// internalLocalInventoryClient is an interface that defines the methods available from Merchant API. |
| 146 |
type internalLocalInventoryClient interface { |
| 147 |
Close() error |
| 148 |
setGoogleClientInfo(...string) |
| 149 |
Connection() *grpc.ClientConn |
| 150 |
ListLocalInventories(context.Context, *inventoriespb.ListLocalInventoriesRequest, ...gax.CallOption) *LocalInventoryIterator |
| 151 |
InsertLocalInventory(context.Context, *inventoriespb.InsertLocalInventoryRequest, ...gax.CallOption) (*inventoriespb.LocalInventory, error) |
| 152 |
DeleteLocalInventory(context.Context, *inventoriespb.DeleteLocalInventoryRequest, ...gax.CallOption) error |
| 153 |
} |
| 154 |
|
| 155 |
// LocalInventoryClient is a client for interacting with Merchant API. |
| 156 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 157 |
// |
| 158 |
// Service to manage local inventory for products |
| 159 |
type LocalInventoryClient struct { |
| 160 |
// The internal transport-dependent client. |
| 161 |
internalClient internalLocalInventoryClient |
| 162 |
|
| 163 |
// The call options for this service. |
| 164 |
CallOptions *LocalInventoryCallOptions |
| 165 |
} |
| 166 |
|
| 167 |
// Wrapper methods routed to the internal client. |
| 168 |
|
| 169 |
// Close closes the connection to the API service. The user should invoke this when |
| 170 |
// the client is no longer required. |
| 171 |
func (c *LocalInventoryClient) Close() error { |
| 172 |
return c.internalClient.Close() |
| 173 |
} |
| 174 |
|
| 175 |
// setGoogleClientInfo sets the name and version of the application in |
| 176 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 177 |
// use by Google-written clients. |
| 178 |
func (c *LocalInventoryClient) setGoogleClientInfo(keyval ...string) { |
| 179 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 180 |
} |
| 181 |
|
| 182 |
// Connection returns a connection to the API service. |
| 183 |
// |
| 184 |
// Deprecated: Connections are now pooled so this method does not always |
| 185 |
// return the same resource. |
| 186 |
func (c *LocalInventoryClient) Connection() *grpc.ClientConn { |
| 187 |
return c.internalClient.Connection() |
| 188 |
} |
| 189 |
|
| 190 |
// ListLocalInventories lists the LocalInventory resources for the given product in your merchant |
| 191 |
// account. The response might contain fewer items than specified by |
| 192 |
// pageSize. If pageToken was returned in previous request, it can be used |
| 193 |
// to obtain additional results. |
| 194 |
// |
| 195 |
// LocalInventory resources are listed per product for a given account. |
| 196 |
func (c *LocalInventoryClient) ListLocalInventories(ctx context.Context, req *inventoriespb.ListLocalInventoriesRequest, opts ...gax.CallOption) *LocalInventoryIterator { |
| 197 |
return c.internalClient.ListLocalInventories(ctx, req, opts...) |
| 198 |
} |
| 199 |
|
| 200 |
// InsertLocalInventory inserts a LocalInventory resource to a product in your merchant |
| 201 |
// account. |
| 202 |
// |
| 203 |
// Replaces the full LocalInventory resource if an entry with the same |
| 204 |
// [storeCode][google.shopping.merchant.inventories.v1beta.LocalInventory.store_code] |
| 205 |
// already exists for the product. |
| 206 |
// |
| 207 |
// It might take up to 30 minutes for the new or updated LocalInventory |
| 208 |
// resource to appear in products. |
| 209 |
func (c *LocalInventoryClient) InsertLocalInventory(ctx context.Context, req *inventoriespb.InsertLocalInventoryRequest, opts ...gax.CallOption) (*inventoriespb.LocalInventory, error) { |
| 210 |
return c.internalClient.InsertLocalInventory(ctx, req, opts...) |
| 211 |
} |
| 212 |
|
| 213 |
// DeleteLocalInventory deletes the specified LocalInventory from the given product in your |
| 214 |
// merchant account. It might take a up to an hour for the |
| 215 |
// LocalInventory to be deleted from the specific product. |
| 216 |
// Once you have received a successful delete response, wait for that |
| 217 |
// period before attempting a delete again. |
| 218 |
func (c *LocalInventoryClient) DeleteLocalInventory(ctx context.Context, req *inventoriespb.DeleteLocalInventoryRequest, opts ...gax.CallOption) error { |
| 219 |
return c.internalClient.DeleteLocalInventory(ctx, req, opts...) |
| 220 |
} |
| 221 |
|
| 222 |
// localInventoryGRPCClient is a client for interacting with Merchant API over gRPC transport. |
| 223 |
// |
| 224 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 225 |
type localInventoryGRPCClient struct { |
| 226 |
// Connection pool of gRPC connections to the service. |
| 227 |
connPool gtransport.ConnPool |
| 228 |
|
| 229 |
// Points back to the CallOptions field of the containing LocalInventoryClient |
| 230 |
CallOptions **LocalInventoryCallOptions |
| 231 |
|
| 232 |
// The gRPC API client. |
| 233 |
localInventoryClient inventoriespb.LocalInventoryServiceClient |
| 234 |
|
| 235 |
// The x-goog-* metadata to be sent with each request. |
| 236 |
xGoogHeaders []string |
| 237 |
|
| 238 |
logger *slog.Logger |
| 239 |
} |
| 240 |
|
| 241 |
// NewLocalInventoryClient creates a new local inventory service client based on gRPC. |
| 242 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 243 |
// |
| 244 |
// Service to manage local inventory for products |
| 245 |
func NewLocalInventoryClient(ctx context.Context, opts ...option.ClientOption) (*LocalInventoryClient, error) { |
| 246 |
clientOpts := defaultLocalInventoryGRPCClientOptions() |
| 247 |
if newLocalInventoryClientHook != nil { |
| 248 |
hookOpts, err := newLocalInventoryClientHook(ctx, clientHookParams{}) |
| 249 |
if err != nil { |
| 250 |
return nil, err |
| 251 |
} |
| 252 |
clientOpts = append(clientOpts, hookOpts...) |
| 253 |
} |
| 254 |
|
| 255 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 256 |
if err != nil { |
| 257 |
return nil, err |
| 258 |
} |
| 259 |
client := LocalInventoryClient{CallOptions: defaultLocalInventoryCallOptions()} |
| 260 |
|
| 261 |
c := &localInventoryGRPCClient{ |
| 262 |
connPool: connPool, |
| 263 |
localInventoryClient: inventoriespb.NewLocalInventoryServiceClient(connPool), |
| 264 |
CallOptions: &client.CallOptions, |
| 265 |
logger: internaloption.GetLogger(opts), |
| 266 |
} |
| 267 |
c.setGoogleClientInfo() |
| 268 |
|
| 269 |
client.internalClient = c |
| 270 |
|
| 271 |
return &client, nil |
| 272 |
} |
| 273 |
|
| 274 |
// Connection returns a connection to the API service. |
| 275 |
// |
| 276 |
// Deprecated: Connections are now pooled so this method does not always |
| 277 |
// return the same resource. |
| 278 |
func (c *localInventoryGRPCClient) Connection() *grpc.ClientConn { |
| 279 |
return c.connPool.Conn() |
| 280 |
} |
| 281 |
|
| 282 |
// setGoogleClientInfo sets the name and version of the application in |
| 283 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 284 |
// use by Google-written clients. |
| 285 |
func (c *localInventoryGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 286 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 287 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 288 |
c.xGoogHeaders = []string{ |
| 289 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
// Close closes the connection to the API service. The user should invoke this when |
| 294 |
// the client is no longer required. |
| 295 |
func (c *localInventoryGRPCClient) Close() error { |
| 296 |
return c.connPool.Close() |
| 297 |
} |
| 298 |
|
| 299 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 300 |
type localInventoryRESTClient struct { |
| 301 |
// The http endpoint to connect to. |
| 302 |
endpoint string |
| 303 |
|
| 304 |
// The http client. |
| 305 |
httpClient *http.Client |
| 306 |
|
| 307 |
// The x-goog-* headers to be sent with each request. |
| 308 |
xGoogHeaders []string |
| 309 |
|
| 310 |
// Points back to the CallOptions field of the containing LocalInventoryClient |
| 311 |
CallOptions **LocalInventoryCallOptions |
| 312 |
|
| 313 |
logger *slog.Logger |
| 314 |
} |
| 315 |
|
| 316 |
// NewLocalInventoryRESTClient creates a new local inventory service rest client. |
| 317 |
// |
| 318 |
// Service to manage local inventory for products |
| 319 |
func NewLocalInventoryRESTClient(ctx context.Context, opts ...option.ClientOption) (*LocalInventoryClient, error) { |
| 320 |
clientOpts := append(defaultLocalInventoryRESTClientOptions(), opts...) |
| 321 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 322 |
if err != nil { |
| 323 |
return nil, err |
| 324 |
} |
| 325 |
|
| 326 |
callOpts := defaultLocalInventoryRESTCallOptions() |
| 327 |
c := &localInventoryRESTClient{ |
| 328 |
endpoint: endpoint, |
| 329 |
httpClient: httpClient, |
| 330 |
CallOptions: &callOpts, |
| 331 |
logger: internaloption.GetLogger(opts), |
| 332 |
} |
| 333 |
c.setGoogleClientInfo() |
| 334 |
|
| 335 |
return &LocalInventoryClient{internalClient: c, CallOptions: callOpts}, nil |
| 336 |
} |
| 337 |
|
| 338 |
func defaultLocalInventoryRESTClientOptions() []option.ClientOption { |
| 339 |
return []option.ClientOption{ |
| 340 |
internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"), |
| 341 |
internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"), |
| 342 |
internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"), |
| 343 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 344 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 345 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 346 |
internaloption.EnableNewAuthLibrary(), |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
// setGoogleClientInfo sets the name and version of the application in |
| 351 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 352 |
// use by Google-written clients. |
| 353 |
func (c *localInventoryRESTClient) setGoogleClientInfo(keyval ...string) { |
| 354 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 355 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 356 |
c.xGoogHeaders = []string{ |
| 357 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
// Close closes the connection to the API service. The user should invoke this when |
| 362 |
// the client is no longer required. |
| 363 |
func (c *localInventoryRESTClient) Close() error { |
| 364 |
// Replace httpClient with nil to force cleanup. |
| 365 |
c.httpClient = nil |
| 366 |
return nil |
| 367 |
} |
| 368 |
|
| 369 |
// Connection returns a connection to the API service. |
| 370 |
// |
| 371 |
// Deprecated: This method always returns nil. |
| 372 |
func (c *localInventoryRESTClient) Connection() *grpc.ClientConn { |
| 373 |
return nil |
| 374 |
} |
| 375 |
func (c *localInventoryGRPCClient) ListLocalInventories(ctx context.Context, req *inventoriespb.ListLocalInventoriesRequest, opts ...gax.CallOption) *LocalInventoryIterator { |
| 376 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 377 |
|
| 378 |
hds = append(c.xGoogHeaders, hds...) |
| 379 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 380 |
opts = append((*c.CallOptions).ListLocalInventories[0:len((*c.CallOptions).ListLocalInventories):len((*c.CallOptions).ListLocalInventories)], opts...) |
| 381 |
it := &LocalInventoryIterator{} |
| 382 |
req = proto.Clone(req).(*inventoriespb.ListLocalInventoriesRequest) |
| 383 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*inventoriespb.LocalInventory, string, error) { |
| 384 |
resp := &inventoriespb.ListLocalInventoriesResponse{} |
| 385 |
if pageToken != "" { |
| 386 |
req.PageToken = pageToken |
| 387 |
} |
| 388 |
if pageSize > math.MaxInt32 { |
| 389 |
req.PageSize = math.MaxInt32 |
| 390 |
} else if pageSize != 0 { |
| 391 |
req.PageSize = int32(pageSize) |
| 392 |
} |
| 393 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 394 |
var err error |
| 395 |
resp, err = executeRPC(ctx, c.localInventoryClient.ListLocalInventories, req, settings.GRPC, c.logger, "ListLocalInventories") |
| 396 |
return err |
| 397 |
}, opts...) |
| 398 |
if err != nil { |
| 399 |
return nil, "", err |
| 400 |
} |
| 401 |
|
| 402 |
it.Response = resp |
| 403 |
return resp.GetLocalInventories(), resp.GetNextPageToken(), nil |
| 404 |
} |
| 405 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 406 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 407 |
if err != nil { |
| 408 |
return "", err |
| 409 |
} |
| 410 |
it.items = append(it.items, items...) |
| 411 |
return nextPageToken, nil |
| 412 |
} |
| 413 |
|
| 414 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 415 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 416 |
it.pageInfo.Token = req.GetPageToken() |
| 417 |
|
| 418 |
return it |
| 419 |
} |
| 420 |
|
| 421 |
func (c *localInventoryGRPCClient) InsertLocalInventory(ctx context.Context, req *inventoriespb.InsertLocalInventoryRequest, opts ...gax.CallOption) (*inventoriespb.LocalInventory, error) { |
| 422 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 423 |
|
| 424 |
hds = append(c.xGoogHeaders, hds...) |
| 425 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 426 |
opts = append((*c.CallOptions).InsertLocalInventory[0:len((*c.CallOptions).InsertLocalInventory):len((*c.CallOptions).InsertLocalInventory)], opts...) |
| 427 |
var resp *inventoriespb.LocalInventory |
| 428 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 429 |
var err error |
| 430 |
resp, err = executeRPC(ctx, c.localInventoryClient.InsertLocalInventory, req, settings.GRPC, c.logger, "InsertLocalInventory") |
| 431 |
return err |
| 432 |
}, opts...) |
| 433 |
if err != nil { |
| 434 |
return nil, err |
| 435 |
} |
| 436 |
return resp, nil |
| 437 |
} |
| 438 |
|
| 439 |
func (c *localInventoryGRPCClient) DeleteLocalInventory(ctx context.Context, req *inventoriespb.DeleteLocalInventoryRequest, opts ...gax.CallOption) error { |
| 440 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 441 |
|
| 442 |
hds = append(c.xGoogHeaders, hds...) |
| 443 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 444 |
opts = append((*c.CallOptions).DeleteLocalInventory[0:len((*c.CallOptions).DeleteLocalInventory):len((*c.CallOptions).DeleteLocalInventory)], opts...) |
| 445 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 446 |
var err error |
| 447 |
_, err = executeRPC(ctx, c.localInventoryClient.DeleteLocalInventory, req, settings.GRPC, c.logger, "DeleteLocalInventory") |
| 448 |
return err |
| 449 |
}, opts...) |
| 450 |
return err |
| 451 |
} |
| 452 |
|
| 453 |
// ListLocalInventories lists the LocalInventory resources for the given product in your merchant |
| 454 |
// account. The response might contain fewer items than specified by |
| 455 |
// pageSize. If pageToken was returned in previous request, it can be used |
| 456 |
// to obtain additional results. |
| 457 |
// |
| 458 |
// LocalInventory resources are listed per product for a given account. |
| 459 |
func (c *localInventoryRESTClient) ListLocalInventories(ctx context.Context, req *inventoriespb.ListLocalInventoriesRequest, opts ...gax.CallOption) *LocalInventoryIterator { |
| 460 |
it := &LocalInventoryIterator{} |
| 461 |
req = proto.Clone(req).(*inventoriespb.ListLocalInventoriesRequest) |
| 462 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 463 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*inventoriespb.LocalInventory, string, error) { |
| 464 |
resp := &inventoriespb.ListLocalInventoriesResponse{} |
| 465 |
if pageToken != "" { |
| 466 |
req.PageToken = pageToken |
| 467 |
} |
| 468 |
if pageSize > math.MaxInt32 { |
| 469 |
req.PageSize = math.MaxInt32 |
| 470 |
} else if pageSize != 0 { |
| 471 |
req.PageSize = int32(pageSize) |
| 472 |
} |
| 473 |
baseUrl, err := url.Parse(c.endpoint) |
| 474 |
if err != nil { |
| 475 |
return nil, "", err |
| 476 |
} |
| 477 |
baseUrl.Path += fmt.Sprintf("/inventories/v1beta/%v/localInventories", req.GetParent()) |
| 478 |
|
| 479 |
params := url.Values{} |
| 480 |
params.Add("$alt", "json;enum-encoding=int") |
| 481 |
if req.GetPageSize() != 0 { |
| 482 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 483 |
} |
| 484 |
if req.GetPageToken() != "" { |
| 485 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 486 |
} |
| 487 |
|
| 488 |
baseUrl.RawQuery = params.Encode() |
| 489 |
|
| 490 |
// Build HTTP headers from client and context metadata. |
| 491 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 492 |
headers := gax.BuildHeaders(ctx, hds...) |
| 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.Header = headers |
| 502 |
|
| 503 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocalInventories") |
| 504 |
if err != nil { |
| 505 |
return err |
| 506 |
} |
| 507 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 508 |
return err |
| 509 |
} |
| 510 |
|
| 511 |
return nil |
| 512 |
}, opts...) |
| 513 |
if e != nil { |
| 514 |
return nil, "", e |
| 515 |
} |
| 516 |
it.Response = resp |
| 517 |
return resp.GetLocalInventories(), resp.GetNextPageToken(), nil |
| 518 |
} |
| 519 |
|
| 520 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 521 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 522 |
if err != nil { |
| 523 |
return "", err |
| 524 |
} |
| 525 |
it.items = append(it.items, items...) |
| 526 |
return nextPageToken, nil |
| 527 |
} |
| 528 |
|
| 529 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 530 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 531 |
it.pageInfo.Token = req.GetPageToken() |
| 532 |
|
| 533 |
return it |
| 534 |
} |
| 535 |
|
| 536 |
// InsertLocalInventory inserts a LocalInventory resource to a product in your merchant |
| 537 |
// account. |
| 538 |
// |
| 539 |
// Replaces the full LocalInventory resource if an entry with the same |
| 540 |
// [storeCode][google.shopping.merchant.inventories.v1beta.LocalInventory.store_code] |
| 541 |
// already exists for the product. |
| 542 |
// |
| 543 |
// It might take up to 30 minutes for the new or updated LocalInventory |
| 544 |
// resource to appear in products. |
| 545 |
func (c *localInventoryRESTClient) InsertLocalInventory(ctx context.Context, req *inventoriespb.InsertLocalInventoryRequest, opts ...gax.CallOption) (*inventoriespb.LocalInventory, error) { |
| 546 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 547 |
body := req.GetLocalInventory() |
| 548 |
jsonReq, err := m.Marshal(body) |
| 549 |
if err != nil { |
| 550 |
return nil, err |
| 551 |
} |
| 552 |
|
| 553 |
baseUrl, err := url.Parse(c.endpoint) |
| 554 |
if err != nil { |
| 555 |
return nil, err |
| 556 |
} |
| 557 |
baseUrl.Path += fmt.Sprintf("/inventories/v1beta/%v/localInventories:insert", req.GetParent()) |
| 558 |
|
| 559 |
params := url.Values{} |
| 560 |
params.Add("$alt", "json;enum-encoding=int") |
| 561 |
|
| 562 |
baseUrl.RawQuery = params.Encode() |
| 563 |
|
| 564 |
// Build HTTP headers from client and context metadata. |
| 565 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 566 |
|
| 567 |
hds = append(c.xGoogHeaders, hds...) |
| 568 |
hds = append(hds, "Content-Type", "application/json") |
| 569 |
headers := gax.BuildHeaders(ctx, hds...) |
| 570 |
opts = append((*c.CallOptions).InsertLocalInventory[0:len((*c.CallOptions).InsertLocalInventory):len((*c.CallOptions).InsertLocalInventory)], opts...) |
| 571 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 572 |
resp := &inventoriespb.LocalInventory{} |
| 573 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 574 |
if settings.Path != "" { |
| 575 |
baseUrl.Path = settings.Path |
| 576 |
} |
| 577 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 578 |
if err != nil { |
| 579 |
return err |
| 580 |
} |
| 581 |
httpReq = httpReq.WithContext(ctx) |
| 582 |
httpReq.Header = headers |
| 583 |
|
| 584 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "InsertLocalInventory") |
| 585 |
if err != nil { |
| 586 |
return err |
| 587 |
} |
| 588 |
|
| 589 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 590 |
return err |
| 591 |
} |
| 592 |
|
| 593 |
return nil |
| 594 |
}, opts...) |
| 595 |
if e != nil { |
| 596 |
return nil, e |
| 597 |
} |
| 598 |
return resp, nil |
| 599 |
} |
| 600 |
|
| 601 |
// DeleteLocalInventory deletes the specified LocalInventory from the given product in your |
| 602 |
// merchant account. It might take a up to an hour for the |
| 603 |
// LocalInventory to be deleted from the specific product. |
| 604 |
// Once you have received a successful delete response, wait for that |
| 605 |
// period before attempting a delete again. |
| 606 |
func (c *localInventoryRESTClient) DeleteLocalInventory(ctx context.Context, req *inventoriespb.DeleteLocalInventoryRequest, opts ...gax.CallOption) error { |
| 607 |
baseUrl, err := url.Parse(c.endpoint) |
| 608 |
if err != nil { |
| 609 |
return err |
| 610 |
} |
| 611 |
baseUrl.Path += fmt.Sprintf("/inventories/v1beta/%v", req.GetName()) |
| 612 |
|
| 613 |
params := url.Values{} |
| 614 |
params.Add("$alt", "json;enum-encoding=int") |
| 615 |
|
| 616 |
baseUrl.RawQuery = params.Encode() |
| 617 |
|
| 618 |
// Build HTTP headers from client and context metadata. |
| 619 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 620 |
|
| 621 |
hds = append(c.xGoogHeaders, hds...) |
| 622 |
hds = append(hds, "Content-Type", "application/json") |
| 623 |
headers := gax.BuildHeaders(ctx, hds...) |
| 624 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 625 |
if settings.Path != "" { |
| 626 |
baseUrl.Path = settings.Path |
| 627 |
} |
| 628 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 629 |
if err != nil { |
| 630 |
return err |
| 631 |
} |
| 632 |
httpReq = httpReq.WithContext(ctx) |
| 633 |
httpReq.Header = headers |
| 634 |
|
| 635 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteLocalInventory") |
| 636 |
return err |
| 637 |
}, opts...) |
| 638 |
} |