feat(recommendationengine): start generating apiv1beta1 (#3686)
diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json
index 3d633ca..e1963fa 100644
--- a/internal/.repo-metadata-full.json
+++ b/internal/.repo-metadata-full.json
@@ -393,7 +393,7 @@
},
"cloud.google.com/go/errorreporting/apiv1beta1": {
"distribution_name": "cloud.google.com/go/errorreporting/apiv1beta1",
- "description": "Cloud Error Reporting API",
+ "description": "Error Reporting API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://pkg.go.dev/cloud.google.com/go/errorreporting/apiv1beta1",
@@ -703,6 +703,14 @@
"docs_url": "https://pkg.go.dev/cloud.google.com/go/recaptchaenterprise/apiv1beta1",
"release_level": "beta"
},
+ "cloud.google.com/go/recommendationengine/apiv1beta1": {
+ "distribution_name": "cloud.google.com/go/recommendationengine/apiv1beta1",
+ "description": "Recommendations AI",
+ "language": "Go",
+ "client_library_type": "generated",
+ "docs_url": "https://pkg.go.dev/cloud.google.com/go/recommendationengine/apiv1beta1",
+ "release_level": "beta"
+ },
"cloud.google.com/go/recommender/apiv1": {
"distribution_name": "cloud.google.com/go/recommender/apiv1",
"description": "Recommender API",
diff --git a/internal/gapicgen/cmd/genbot/README.md b/internal/gapicgen/cmd/genbot/README.md
index 455fd5f..b601ca8 100644
--- a/internal/gapicgen/cmd/genbot/README.md
+++ b/internal/gapicgen/cmd/genbot/README.md
@@ -93,7 +93,7 @@
-e ONLY_GAPICS=true \
-e GOCLOUD_DIR=/gapicgen \
-e GAPIC_TO_GENERATE=cloud.google.com/go/foo/apiv1 \
- genbot \
+ genbot
```
Note you can optionally mount in your Go module cache if you have Go installed.
diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go
index 81ff01f..54130f9 100644
--- a/internal/gapicgen/generator/config.go
+++ b/internal/gapicgen/generator/config.go
@@ -990,6 +990,14 @@
// GA after 2021/03/02
releaseLevel: "beta",
},
+ {
+ inputDirectoryPath: "google/cloud/recommendationengine/v1beta1",
+ pkg: "recommendationengine",
+ importPath: "cloud.google.com/go/recommendationengine/apiv1beta1",
+ gRPCServiceConfigPath: "google/cloud/recommendationengine/v1beta1/recommendationengine_grpc_service_config.json",
+ apiServiceConfigPath: "google/cloud/recommendationengine/v1beta1/recommendationengine_v1beta1.yaml",
+ releaseLevel: "beta",
+ },
// Non-Cloud APIs
{
diff --git a/recommendationengine/apiv1beta1/catalog_client.go b/recommendationengine/apiv1beta1/catalog_client.go
new file mode 100644
index 0000000..c1666f6
--- /dev/null
+++ b/recommendationengine/apiv1beta1/catalog_client.go
@@ -0,0 +1,503 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine
+
+import (
+ "context"
+ "fmt"
+ "math"
+ "net/url"
+ "time"
+
+ "cloud.google.com/go/longrunning"
+ lroauto "cloud.google.com/go/longrunning/autogen"
+ "github.com/golang/protobuf/proto"
+ gax "github.com/googleapis/gax-go/v2"
+ "google.golang.org/api/iterator"
+ "google.golang.org/api/option"
+ "google.golang.org/api/option/internaloption"
+ gtransport "google.golang.org/api/transport/grpc"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ longrunningpb "google.golang.org/genproto/googleapis/longrunning"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/metadata"
+)
+
+var newCatalogClientHook clientHook
+
+// CatalogCallOptions contains the retry settings for each method of CatalogClient.
+type CatalogCallOptions struct {
+ CreateCatalogItem []gax.CallOption
+ GetCatalogItem []gax.CallOption
+ ListCatalogItems []gax.CallOption
+ UpdateCatalogItem []gax.CallOption
+ DeleteCatalogItem []gax.CallOption
+ ImportCatalogItems []gax.CallOption
+}
+
+func defaultCatalogClientOptions() []option.ClientOption {
+ return []option.ClientOption{
+ internaloption.WithDefaultEndpoint("recommendationengine.googleapis.com:443"),
+ internaloption.WithDefaultMTLSEndpoint("recommendationengine.mtls.googleapis.com:443"),
+ internaloption.WithDefaultAudience("https://recommendationengine.googleapis.com/"),
+ internaloption.WithDefaultScopes(DefaultAuthScopes()...),
+ option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
+ option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
+ grpc.MaxCallRecvMsgSize(math.MaxInt32))),
+ }
+}
+
+func defaultCatalogCallOptions() *CatalogCallOptions {
+ return &CatalogCallOptions{
+ CreateCatalogItem: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ GetCatalogItem: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ ListCatalogItems: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ UpdateCatalogItem: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ DeleteCatalogItem: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ ImportCatalogItems: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ }
+}
+
+// CatalogClient is a client for interacting with Recommendations AI.
+//
+// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
+type CatalogClient struct {
+ // Connection pool of gRPC connections to the service.
+ connPool gtransport.ConnPool
+
+ // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
+ disableDeadlines bool
+
+ // The gRPC API client.
+ catalogClient recommendationenginepb.CatalogServiceClient
+
+ // LROClient is used internally to handle longrunning operations.
+ // It is exposed so that its CallOptions can be modified if required.
+ // Users should not Close this client.
+ LROClient *lroauto.OperationsClient
+
+ // The call options for this service.
+ CallOptions *CatalogCallOptions
+
+ // The x-goog-* metadata to be sent with each request.
+ xGoogMetadata metadata.MD
+}
+
+// NewCatalogClient creates a new catalog service client.
+//
+// Service for ingesting catalog information of the customer’s website.
+func NewCatalogClient(ctx context.Context, opts ...option.ClientOption) (*CatalogClient, error) {
+ clientOpts := defaultCatalogClientOptions()
+
+ if newCatalogClientHook != nil {
+ hookOpts, err := newCatalogClientHook(ctx, clientHookParams{})
+ if err != nil {
+ return nil, err
+ }
+ clientOpts = append(clientOpts, hookOpts...)
+ }
+
+ disableDeadlines, err := checkDisableDeadlines()
+ if err != nil {
+ return nil, err
+ }
+
+ connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
+ if err != nil {
+ return nil, err
+ }
+ c := &CatalogClient{
+ connPool: connPool,
+ disableDeadlines: disableDeadlines,
+ CallOptions: defaultCatalogCallOptions(),
+
+ catalogClient: recommendationenginepb.NewCatalogServiceClient(connPool),
+ }
+ c.setGoogleClientInfo()
+
+ c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
+ if err != nil {
+ // This error "should not happen", since we are just reusing old connection pool
+ // and never actually need to dial.
+ // If this does happen, we could leak connp. However, we cannot close conn:
+ // If the user invoked the constructor with option.WithGRPCConn,
+ // we would close a connection that's still in use.
+ // TODO: investigate error conditions.
+ return nil, err
+ }
+ return c, nil
+}
+
+// Connection returns a connection to the API service.
+//
+// Deprecated.
+func (c *CatalogClient) Connection() *grpc.ClientConn {
+ return c.connPool.Conn()
+}
+
+// Close closes the connection to the API service. The user should invoke this when
+// the client is no longer required.
+func (c *CatalogClient) Close() error {
+ return c.connPool.Close()
+}
+
+// setGoogleClientInfo sets the name and version of the application in
+// the `x-goog-api-client` header passed on each request. Intended for
+// use by Google-written clients.
+func (c *CatalogClient) setGoogleClientInfo(keyval ...string) {
+ kv := append([]string{"gl-go", versionGo()}, keyval...)
+ kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
+ c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
+}
+
+// CreateCatalogItem creates a catalog item.
+func (c *CatalogClient) CreateCatalogItem(ctx context.Context, req *recommendationenginepb.CreateCatalogItemRequest, opts ...gax.CallOption) (*recommendationenginepb.CatalogItem, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.CreateCatalogItem[0:len(c.CallOptions.CreateCatalogItem):len(c.CallOptions.CreateCatalogItem)], opts...)
+ var resp *recommendationenginepb.CatalogItem
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.catalogClient.CreateCatalogItem(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+// GetCatalogItem gets a specific catalog item.
+func (c *CatalogClient) GetCatalogItem(ctx context.Context, req *recommendationenginepb.GetCatalogItemRequest, opts ...gax.CallOption) (*recommendationenginepb.CatalogItem, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.GetCatalogItem[0:len(c.CallOptions.GetCatalogItem):len(c.CallOptions.GetCatalogItem)], opts...)
+ var resp *recommendationenginepb.CatalogItem
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.catalogClient.GetCatalogItem(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+// ListCatalogItems gets a list of catalog items.
+func (c *CatalogClient) ListCatalogItems(ctx context.Context, req *recommendationenginepb.ListCatalogItemsRequest, opts ...gax.CallOption) *CatalogItemIterator {
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.ListCatalogItems[0:len(c.CallOptions.ListCatalogItems):len(c.CallOptions.ListCatalogItems)], opts...)
+ it := &CatalogItemIterator{}
+ req = proto.Clone(req).(*recommendationenginepb.ListCatalogItemsRequest)
+ it.InternalFetch = func(pageSize int, pageToken string) ([]*recommendationenginepb.CatalogItem, string, error) {
+ var resp *recommendationenginepb.ListCatalogItemsResponse
+ req.PageToken = pageToken
+ if pageSize > math.MaxInt32 {
+ req.PageSize = math.MaxInt32
+ } else {
+ req.PageSize = int32(pageSize)
+ }
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.catalogClient.ListCatalogItems(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, "", err
+ }
+
+ it.Response = resp
+ return resp.GetCatalogItems(), resp.GetNextPageToken(), nil
+ }
+ fetch := func(pageSize int, pageToken string) (string, error) {
+ items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
+ if err != nil {
+ return "", err
+ }
+ it.items = append(it.items, items...)
+ return nextPageToken, nil
+ }
+ it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
+ it.pageInfo.MaxSize = int(req.GetPageSize())
+ it.pageInfo.Token = req.GetPageToken()
+ return it
+}
+
+// UpdateCatalogItem updates a catalog item. Partial updating is supported. Non-existing
+// items will be created.
+func (c *CatalogClient) UpdateCatalogItem(ctx context.Context, req *recommendationenginepb.UpdateCatalogItemRequest, opts ...gax.CallOption) (*recommendationenginepb.CatalogItem, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.UpdateCatalogItem[0:len(c.CallOptions.UpdateCatalogItem):len(c.CallOptions.UpdateCatalogItem)], opts...)
+ var resp *recommendationenginepb.CatalogItem
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.catalogClient.UpdateCatalogItem(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+// DeleteCatalogItem deletes a catalog item.
+func (c *CatalogClient) DeleteCatalogItem(ctx context.Context, req *recommendationenginepb.DeleteCatalogItemRequest, opts ...gax.CallOption) error {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.DeleteCatalogItem[0:len(c.CallOptions.DeleteCatalogItem):len(c.CallOptions.DeleteCatalogItem)], opts...)
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ _, err = c.catalogClient.DeleteCatalogItem(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ return err
+}
+
+// ImportCatalogItems bulk import of multiple catalog items. Request processing may be
+// synchronous. No partial updating supported. Non-existing items will be
+// created.
+//
+// Operation.response is of type ImportResponse. Note that it is
+// possible for a subset of the items to be successfully updated.
+func (c *CatalogClient) ImportCatalogItems(ctx context.Context, req *recommendationenginepb.ImportCatalogItemsRequest, opts ...gax.CallOption) (*ImportCatalogItemsOperation, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.ImportCatalogItems[0:len(c.CallOptions.ImportCatalogItems):len(c.CallOptions.ImportCatalogItems)], opts...)
+ var resp *longrunningpb.Operation
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.catalogClient.ImportCatalogItems(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return &ImportCatalogItemsOperation{
+ lro: longrunning.InternalNewOperation(c.LROClient, resp),
+ }, nil
+}
+
+// ImportCatalogItemsOperation manages a long-running operation from ImportCatalogItems.
+type ImportCatalogItemsOperation struct {
+ lro *longrunning.Operation
+}
+
+// ImportCatalogItemsOperation returns a new ImportCatalogItemsOperation from a given name.
+// The name must be that of a previously created ImportCatalogItemsOperation, possibly from a different process.
+func (c *CatalogClient) ImportCatalogItemsOperation(name string) *ImportCatalogItemsOperation {
+ return &ImportCatalogItemsOperation{
+ lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
+ }
+}
+
+// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
+//
+// See documentation of Poll for error-handling information.
+func (op *ImportCatalogItemsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*recommendationenginepb.ImportCatalogItemsResponse, error) {
+ var resp recommendationenginepb.ImportCatalogItemsResponse
+ if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
+ return nil, err
+ }
+ return &resp, nil
+}
+
+// Poll fetches the latest state of the long-running operation.
+//
+// Poll also fetches the latest metadata, which can be retrieved by Metadata.
+//
+// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
+// the operation has completed with failure, the error is returned and op.Done will return true.
+// If Poll succeeds and the operation has completed successfully,
+// op.Done will return true, and the response of the operation is returned.
+// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
+func (op *ImportCatalogItemsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*recommendationenginepb.ImportCatalogItemsResponse, error) {
+ var resp recommendationenginepb.ImportCatalogItemsResponse
+ if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
+ return nil, err
+ }
+ if !op.Done() {
+ return nil, nil
+ }
+ return &resp, nil
+}
+
+// Metadata returns metadata associated with the long-running operation.
+// Metadata itself does not contact the server, but Poll does.
+// To get the latest metadata, call this method after a successful call to Poll.
+// If the metadata is not available, the returned metadata and error are both nil.
+func (op *ImportCatalogItemsOperation) Metadata() (*recommendationenginepb.ImportMetadata, error) {
+ var meta recommendationenginepb.ImportMetadata
+ if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
+ return nil, nil
+ } else if err != nil {
+ return nil, err
+ }
+ return &meta, nil
+}
+
+// Done reports whether the long-running operation has completed.
+func (op *ImportCatalogItemsOperation) Done() bool {
+ return op.lro.Done()
+}
+
+// Name returns the name of the long-running operation.
+// The name is assigned by the server and is unique within the service from which the operation is created.
+func (op *ImportCatalogItemsOperation) Name() string {
+ return op.lro.Name()
+}
+
+// CatalogItemIterator manages a stream of *recommendationenginepb.CatalogItem.
+type CatalogItemIterator struct {
+ items []*recommendationenginepb.CatalogItem
+ pageInfo *iterator.PageInfo
+ nextFunc func() error
+
+ // Response is the raw response for the current page.
+ // It must be cast to the RPC response type.
+ // Calling Next() or InternalFetch() updates this value.
+ Response interface{}
+
+ // InternalFetch is for use by the Google Cloud Libraries only.
+ // It is not part of the stable interface of this package.
+ //
+ // InternalFetch returns results from a single call to the underlying RPC.
+ // The number of results is no greater than pageSize.
+ // If there are no more results, nextPageToken is empty and err is nil.
+ InternalFetch func(pageSize int, pageToken string) (results []*recommendationenginepb.CatalogItem, nextPageToken string, err error)
+}
+
+// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
+func (it *CatalogItemIterator) PageInfo() *iterator.PageInfo {
+ return it.pageInfo
+}
+
+// Next returns the next result. Its second return value is iterator.Done if there are no more
+// results. Once Next returns Done, all subsequent calls will return Done.
+func (it *CatalogItemIterator) Next() (*recommendationenginepb.CatalogItem, error) {
+ var item *recommendationenginepb.CatalogItem
+ if err := it.nextFunc(); err != nil {
+ return item, err
+ }
+ item = it.items[0]
+ it.items = it.items[1:]
+ return item, nil
+}
+
+func (it *CatalogItemIterator) bufLen() int {
+ return len(it.items)
+}
+
+func (it *CatalogItemIterator) takeBuf() interface{} {
+ b := it.items
+ it.items = nil
+ return b
+}
diff --git a/recommendationengine/apiv1beta1/catalog_client_example_test.go b/recommendationengine/apiv1beta1/catalog_client_example_test.go
new file mode 100644
index 0000000..6270605
--- /dev/null
+++ b/recommendationengine/apiv1beta1/catalog_client_example_test.go
@@ -0,0 +1,163 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine_test
+
+import (
+ "context"
+
+ recommendationengine "cloud.google.com/go/recommendationengine/apiv1beta1"
+ "google.golang.org/api/iterator"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+)
+
+func ExampleNewCatalogClient() {
+ ctx := context.Background()
+ c, err := recommendationengine.NewCatalogClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use client.
+ _ = c
+}
+
+func ExampleCatalogClient_CreateCatalogItem() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewCatalogClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.CreateCatalogItemRequest{
+ // TODO: Fill request struct fields.
+ }
+ resp, err := c.CreateCatalogItem(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
+
+func ExampleCatalogClient_GetCatalogItem() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewCatalogClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.GetCatalogItemRequest{
+ // TODO: Fill request struct fields.
+ }
+ resp, err := c.GetCatalogItem(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
+
+func ExampleCatalogClient_ListCatalogItems() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ // import "google.golang.org/api/iterator"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewCatalogClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.ListCatalogItemsRequest{
+ // TODO: Fill request struct fields.
+ }
+ it := c.ListCatalogItems(ctx, req)
+ for {
+ resp, err := it.Next()
+ if err == iterator.Done {
+ break
+ }
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+ }
+}
+
+func ExampleCatalogClient_UpdateCatalogItem() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewCatalogClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.UpdateCatalogItemRequest{
+ // TODO: Fill request struct fields.
+ }
+ resp, err := c.UpdateCatalogItem(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
+
+func ExampleCatalogClient_DeleteCatalogItem() {
+ ctx := context.Background()
+ c, err := recommendationengine.NewCatalogClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.DeleteCatalogItemRequest{
+ // TODO: Fill request struct fields.
+ }
+ err = c.DeleteCatalogItem(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+}
+
+func ExampleCatalogClient_ImportCatalogItems() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewCatalogClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.ImportCatalogItemsRequest{
+ // TODO: Fill request struct fields.
+ }
+ op, err := c.ImportCatalogItems(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ resp, err := op.Wait(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
diff --git a/recommendationengine/apiv1beta1/doc.go b/recommendationengine/apiv1beta1/doc.go
new file mode 100644
index 0000000..5b633b6
--- /dev/null
+++ b/recommendationengine/apiv1beta1/doc.go
@@ -0,0 +1,118 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+// Package recommendationengine is an auto-generated package for the
+// Recommendations AI.
+//
+// Recommendations AI service enables customers to build end-to-end
+// personalized recommendation systems without requiring a high level of
+// expertise in machine learning, recommendation system, or Google Cloud.
+//
+// Use of Context
+//
+// The ctx passed to NewClient is used for authentication requests and
+// for creating the underlying connection, but is not used for subsequent calls.
+// Individual methods on the client use the ctx given to them.
+//
+// To close the open connection, use the Close() method.
+//
+// For information about setting deadlines, reusing contexts, and more
+// please visit pkg.go.dev/cloud.google.com/go.
+package recommendationengine // import "cloud.google.com/go/recommendationengine/apiv1beta1"
+
+import (
+ "context"
+ "os"
+ "runtime"
+ "strconv"
+ "strings"
+ "unicode"
+
+ "google.golang.org/api/option"
+ "google.golang.org/grpc/metadata"
+)
+
+// For more information on implementing a client constructor hook, see
+// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
+type clientHookParams struct{}
+type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
+
+const versionClient = "20210209"
+
+func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
+ out, _ := metadata.FromOutgoingContext(ctx)
+ out = out.Copy()
+ for _, md := range mds {
+ for k, v := range md {
+ out[k] = append(out[k], v...)
+ }
+ }
+ return metadata.NewOutgoingContext(ctx, out)
+}
+
+func checkDisableDeadlines() (bool, error) {
+ raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
+ if !ok {
+ return false, nil
+ }
+
+ b, err := strconv.ParseBool(raw)
+ return b, err
+}
+
+// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
+func DefaultAuthScopes() []string {
+ return []string{
+ "https://www.googleapis.com/auth/cloud-platform",
+ }
+}
+
+// versionGo returns the Go runtime version. The returned string
+// has no whitespace, suitable for reporting in header.
+func versionGo() string {
+ const develPrefix = "devel +"
+
+ s := runtime.Version()
+ if strings.HasPrefix(s, develPrefix) {
+ s = s[len(develPrefix):]
+ if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 {
+ s = s[:p]
+ }
+ return s
+ }
+
+ notSemverRune := func(r rune) bool {
+ return !strings.ContainsRune("0123456789.", r)
+ }
+
+ if strings.HasPrefix(s, "go1") {
+ s = s[2:]
+ var prerelease string
+ if p := strings.IndexFunc(s, notSemverRune); p >= 0 {
+ s, prerelease = s[:p], s[p:]
+ }
+ if strings.HasSuffix(s, ".") {
+ s += "0"
+ } else if strings.Count(s, ".") < 2 {
+ s += ".0"
+ }
+ if prerelease != "" {
+ s += "-" + prerelease
+ }
+ return s
+ }
+ return "UNKNOWN"
+}
diff --git a/recommendationengine/apiv1beta1/prediction_api_key_registry_client.go b/recommendationengine/apiv1beta1/prediction_api_key_registry_client.go
new file mode 100644
index 0000000..fcffa0c
--- /dev/null
+++ b/recommendationengine/apiv1beta1/prediction_api_key_registry_client.go
@@ -0,0 +1,307 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine
+
+import (
+ "context"
+ "fmt"
+ "math"
+ "net/url"
+ "time"
+
+ "github.com/golang/protobuf/proto"
+ gax "github.com/googleapis/gax-go/v2"
+ "google.golang.org/api/iterator"
+ "google.golang.org/api/option"
+ "google.golang.org/api/option/internaloption"
+ gtransport "google.golang.org/api/transport/grpc"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/metadata"
+)
+
+var newPredictionApiKeyRegistryClientHook clientHook
+
+// PredictionApiKeyRegistryCallOptions contains the retry settings for each method of PredictionApiKeyRegistryClient.
+type PredictionApiKeyRegistryCallOptions struct {
+ CreatePredictionApiKeyRegistration []gax.CallOption
+ ListPredictionApiKeyRegistrations []gax.CallOption
+ DeletePredictionApiKeyRegistration []gax.CallOption
+}
+
+func defaultPredictionApiKeyRegistryClientOptions() []option.ClientOption {
+ return []option.ClientOption{
+ internaloption.WithDefaultEndpoint("recommendationengine.googleapis.com:443"),
+ internaloption.WithDefaultMTLSEndpoint("recommendationengine.mtls.googleapis.com:443"),
+ internaloption.WithDefaultAudience("https://recommendationengine.googleapis.com/"),
+ internaloption.WithDefaultScopes(DefaultAuthScopes()...),
+ option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
+ option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
+ grpc.MaxCallRecvMsgSize(math.MaxInt32))),
+ }
+}
+
+func defaultPredictionApiKeyRegistryCallOptions() *PredictionApiKeyRegistryCallOptions {
+ return &PredictionApiKeyRegistryCallOptions{
+ CreatePredictionApiKeyRegistration: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ ListPredictionApiKeyRegistrations: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ DeletePredictionApiKeyRegistration: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ }
+}
+
+// PredictionApiKeyRegistryClient is a client for interacting with Recommendations AI.
+//
+// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
+type PredictionApiKeyRegistryClient struct {
+ // Connection pool of gRPC connections to the service.
+ connPool gtransport.ConnPool
+
+ // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
+ disableDeadlines bool
+
+ // The gRPC API client.
+ predictionApiKeyRegistryClient recommendationenginepb.PredictionApiKeyRegistryClient
+
+ // The call options for this service.
+ CallOptions *PredictionApiKeyRegistryCallOptions
+
+ // The x-goog-* metadata to be sent with each request.
+ xGoogMetadata metadata.MD
+}
+
+// NewPredictionApiKeyRegistryClient creates a new prediction api key registry client.
+//
+// Service for registering API keys for use with the predict method. If you
+// use an API key to request predictions, you must first register the API key.
+// Otherwise, your prediction request is rejected. If you use OAuth to
+// authenticate your predict method call, you do not need to register an API
+// key. You can register up to 20 API keys per project.
+func NewPredictionApiKeyRegistryClient(ctx context.Context, opts ...option.ClientOption) (*PredictionApiKeyRegistryClient, error) {
+ clientOpts := defaultPredictionApiKeyRegistryClientOptions()
+
+ if newPredictionApiKeyRegistryClientHook != nil {
+ hookOpts, err := newPredictionApiKeyRegistryClientHook(ctx, clientHookParams{})
+ if err != nil {
+ return nil, err
+ }
+ clientOpts = append(clientOpts, hookOpts...)
+ }
+
+ disableDeadlines, err := checkDisableDeadlines()
+ if err != nil {
+ return nil, err
+ }
+
+ connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
+ if err != nil {
+ return nil, err
+ }
+ c := &PredictionApiKeyRegistryClient{
+ connPool: connPool,
+ disableDeadlines: disableDeadlines,
+ CallOptions: defaultPredictionApiKeyRegistryCallOptions(),
+
+ predictionApiKeyRegistryClient: recommendationenginepb.NewPredictionApiKeyRegistryClient(connPool),
+ }
+ c.setGoogleClientInfo()
+
+ return c, nil
+}
+
+// Connection returns a connection to the API service.
+//
+// Deprecated.
+func (c *PredictionApiKeyRegistryClient) Connection() *grpc.ClientConn {
+ return c.connPool.Conn()
+}
+
+// Close closes the connection to the API service. The user should invoke this when
+// the client is no longer required.
+func (c *PredictionApiKeyRegistryClient) Close() error {
+ return c.connPool.Close()
+}
+
+// setGoogleClientInfo sets the name and version of the application in
+// the `x-goog-api-client` header passed on each request. Intended for
+// use by Google-written clients.
+func (c *PredictionApiKeyRegistryClient) setGoogleClientInfo(keyval ...string) {
+ kv := append([]string{"gl-go", versionGo()}, keyval...)
+ kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
+ c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
+}
+
+// CreatePredictionApiKeyRegistration register an API key for use with predict method.
+func (c *PredictionApiKeyRegistryClient) CreatePredictionApiKeyRegistration(ctx context.Context, req *recommendationenginepb.CreatePredictionApiKeyRegistrationRequest, opts ...gax.CallOption) (*recommendationenginepb.PredictionApiKeyRegistration, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.CreatePredictionApiKeyRegistration[0:len(c.CallOptions.CreatePredictionApiKeyRegistration):len(c.CallOptions.CreatePredictionApiKeyRegistration)], opts...)
+ var resp *recommendationenginepb.PredictionApiKeyRegistration
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.predictionApiKeyRegistryClient.CreatePredictionApiKeyRegistration(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+// ListPredictionApiKeyRegistrations list the registered apiKeys for use with predict method.
+func (c *PredictionApiKeyRegistryClient) ListPredictionApiKeyRegistrations(ctx context.Context, req *recommendationenginepb.ListPredictionApiKeyRegistrationsRequest, opts ...gax.CallOption) *PredictionApiKeyRegistrationIterator {
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.ListPredictionApiKeyRegistrations[0:len(c.CallOptions.ListPredictionApiKeyRegistrations):len(c.CallOptions.ListPredictionApiKeyRegistrations)], opts...)
+ it := &PredictionApiKeyRegistrationIterator{}
+ req = proto.Clone(req).(*recommendationenginepb.ListPredictionApiKeyRegistrationsRequest)
+ it.InternalFetch = func(pageSize int, pageToken string) ([]*recommendationenginepb.PredictionApiKeyRegistration, string, error) {
+ var resp *recommendationenginepb.ListPredictionApiKeyRegistrationsResponse
+ req.PageToken = pageToken
+ if pageSize > math.MaxInt32 {
+ req.PageSize = math.MaxInt32
+ } else {
+ req.PageSize = int32(pageSize)
+ }
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.predictionApiKeyRegistryClient.ListPredictionApiKeyRegistrations(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, "", err
+ }
+
+ it.Response = resp
+ return resp.GetPredictionApiKeyRegistrations(), resp.GetNextPageToken(), nil
+ }
+ fetch := func(pageSize int, pageToken string) (string, error) {
+ items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
+ if err != nil {
+ return "", err
+ }
+ it.items = append(it.items, items...)
+ return nextPageToken, nil
+ }
+ it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
+ it.pageInfo.MaxSize = int(req.GetPageSize())
+ it.pageInfo.Token = req.GetPageToken()
+ return it
+}
+
+// DeletePredictionApiKeyRegistration unregister an apiKey from using for predict method.
+func (c *PredictionApiKeyRegistryClient) DeletePredictionApiKeyRegistration(ctx context.Context, req *recommendationenginepb.DeletePredictionApiKeyRegistrationRequest, opts ...gax.CallOption) error {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.DeletePredictionApiKeyRegistration[0:len(c.CallOptions.DeletePredictionApiKeyRegistration):len(c.CallOptions.DeletePredictionApiKeyRegistration)], opts...)
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ _, err = c.predictionApiKeyRegistryClient.DeletePredictionApiKeyRegistration(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ return err
+}
+
+// PredictionApiKeyRegistrationIterator manages a stream of *recommendationenginepb.PredictionApiKeyRegistration.
+type PredictionApiKeyRegistrationIterator struct {
+ items []*recommendationenginepb.PredictionApiKeyRegistration
+ pageInfo *iterator.PageInfo
+ nextFunc func() error
+
+ // Response is the raw response for the current page.
+ // It must be cast to the RPC response type.
+ // Calling Next() or InternalFetch() updates this value.
+ Response interface{}
+
+ // InternalFetch is for use by the Google Cloud Libraries only.
+ // It is not part of the stable interface of this package.
+ //
+ // InternalFetch returns results from a single call to the underlying RPC.
+ // The number of results is no greater than pageSize.
+ // If there are no more results, nextPageToken is empty and err is nil.
+ InternalFetch func(pageSize int, pageToken string) (results []*recommendationenginepb.PredictionApiKeyRegistration, nextPageToken string, err error)
+}
+
+// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
+func (it *PredictionApiKeyRegistrationIterator) PageInfo() *iterator.PageInfo {
+ return it.pageInfo
+}
+
+// Next returns the next result. Its second return value is iterator.Done if there are no more
+// results. Once Next returns Done, all subsequent calls will return Done.
+func (it *PredictionApiKeyRegistrationIterator) Next() (*recommendationenginepb.PredictionApiKeyRegistration, error) {
+ var item *recommendationenginepb.PredictionApiKeyRegistration
+ if err := it.nextFunc(); err != nil {
+ return item, err
+ }
+ item = it.items[0]
+ it.items = it.items[1:]
+ return item, nil
+}
+
+func (it *PredictionApiKeyRegistrationIterator) bufLen() int {
+ return len(it.items)
+}
+
+func (it *PredictionApiKeyRegistrationIterator) takeBuf() interface{} {
+ b := it.items
+ it.items = nil
+ return b
+}
diff --git a/recommendationengine/apiv1beta1/prediction_api_key_registry_client_example_test.go b/recommendationengine/apiv1beta1/prediction_api_key_registry_client_example_test.go
new file mode 100644
index 0000000..747f74a
--- /dev/null
+++ b/recommendationengine/apiv1beta1/prediction_api_key_registry_client_example_test.go
@@ -0,0 +1,98 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine_test
+
+import (
+ "context"
+
+ recommendationengine "cloud.google.com/go/recommendationengine/apiv1beta1"
+ "google.golang.org/api/iterator"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+)
+
+func ExampleNewPredictionApiKeyRegistryClient() {
+ ctx := context.Background()
+ c, err := recommendationengine.NewPredictionApiKeyRegistryClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use client.
+ _ = c
+}
+
+func ExamplePredictionApiKeyRegistryClient_CreatePredictionApiKeyRegistration() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewPredictionApiKeyRegistryClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.CreatePredictionApiKeyRegistrationRequest{
+ // TODO: Fill request struct fields.
+ }
+ resp, err := c.CreatePredictionApiKeyRegistration(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
+
+func ExamplePredictionApiKeyRegistryClient_ListPredictionApiKeyRegistrations() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ // import "google.golang.org/api/iterator"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewPredictionApiKeyRegistryClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.ListPredictionApiKeyRegistrationsRequest{
+ // TODO: Fill request struct fields.
+ }
+ it := c.ListPredictionApiKeyRegistrations(ctx, req)
+ for {
+ resp, err := it.Next()
+ if err == iterator.Done {
+ break
+ }
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+ }
+}
+
+func ExamplePredictionApiKeyRegistryClient_DeletePredictionApiKeyRegistration() {
+ ctx := context.Background()
+ c, err := recommendationengine.NewPredictionApiKeyRegistryClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.DeletePredictionApiKeyRegistrationRequest{
+ // TODO: Fill request struct fields.
+ }
+ err = c.DeletePredictionApiKeyRegistration(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+}
diff --git a/recommendationengine/apiv1beta1/prediction_client.go b/recommendationengine/apiv1beta1/prediction_client.go
new file mode 100644
index 0000000..e1c436f
--- /dev/null
+++ b/recommendationengine/apiv1beta1/prediction_client.go
@@ -0,0 +1,240 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine
+
+import (
+ "context"
+ "fmt"
+ "math"
+ "net/url"
+ "time"
+
+ "github.com/golang/protobuf/proto"
+ gax "github.com/googleapis/gax-go/v2"
+ "google.golang.org/api/iterator"
+ "google.golang.org/api/option"
+ "google.golang.org/api/option/internaloption"
+ gtransport "google.golang.org/api/transport/grpc"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/metadata"
+)
+
+var newPredictionClientHook clientHook
+
+// PredictionCallOptions contains the retry settings for each method of PredictionClient.
+type PredictionCallOptions struct {
+ Predict []gax.CallOption
+}
+
+func defaultPredictionClientOptions() []option.ClientOption {
+ return []option.ClientOption{
+ internaloption.WithDefaultEndpoint("recommendationengine.googleapis.com:443"),
+ internaloption.WithDefaultMTLSEndpoint("recommendationengine.mtls.googleapis.com:443"),
+ internaloption.WithDefaultAudience("https://recommendationengine.googleapis.com/"),
+ internaloption.WithDefaultScopes(DefaultAuthScopes()...),
+ option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
+ option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
+ grpc.MaxCallRecvMsgSize(math.MaxInt32))),
+ }
+}
+
+func defaultPredictionCallOptions() *PredictionCallOptions {
+ return &PredictionCallOptions{
+ Predict: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ }
+}
+
+// PredictionClient is a client for interacting with Recommendations AI.
+//
+// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
+type PredictionClient struct {
+ // Connection pool of gRPC connections to the service.
+ connPool gtransport.ConnPool
+
+ // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
+ disableDeadlines bool
+
+ // The gRPC API client.
+ predictionClient recommendationenginepb.PredictionServiceClient
+
+ // The call options for this service.
+ CallOptions *PredictionCallOptions
+
+ // The x-goog-* metadata to be sent with each request.
+ xGoogMetadata metadata.MD
+}
+
+// NewPredictionClient creates a new prediction service client.
+//
+// Service for making recommendation prediction.
+func NewPredictionClient(ctx context.Context, opts ...option.ClientOption) (*PredictionClient, error) {
+ clientOpts := defaultPredictionClientOptions()
+
+ if newPredictionClientHook != nil {
+ hookOpts, err := newPredictionClientHook(ctx, clientHookParams{})
+ if err != nil {
+ return nil, err
+ }
+ clientOpts = append(clientOpts, hookOpts...)
+ }
+
+ disableDeadlines, err := checkDisableDeadlines()
+ if err != nil {
+ return nil, err
+ }
+
+ connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
+ if err != nil {
+ return nil, err
+ }
+ c := &PredictionClient{
+ connPool: connPool,
+ disableDeadlines: disableDeadlines,
+ CallOptions: defaultPredictionCallOptions(),
+
+ predictionClient: recommendationenginepb.NewPredictionServiceClient(connPool),
+ }
+ c.setGoogleClientInfo()
+
+ return c, nil
+}
+
+// Connection returns a connection to the API service.
+//
+// Deprecated.
+func (c *PredictionClient) Connection() *grpc.ClientConn {
+ return c.connPool.Conn()
+}
+
+// Close closes the connection to the API service. The user should invoke this when
+// the client is no longer required.
+func (c *PredictionClient) Close() error {
+ return c.connPool.Close()
+}
+
+// setGoogleClientInfo sets the name and version of the application in
+// the `x-goog-api-client` header passed on each request. Intended for
+// use by Google-written clients.
+func (c *PredictionClient) setGoogleClientInfo(keyval ...string) {
+ kv := append([]string{"gl-go", versionGo()}, keyval...)
+ kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
+ c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
+}
+
+// Predict makes a recommendation prediction. If using API Key based authentication,
+// the API Key must be registered using the
+// PredictionApiKeyRegistry
+// service. Learn more (at /recommendations-ai/docs/setting-up#register-key).
+func (c *PredictionClient) Predict(ctx context.Context, req *recommendationenginepb.PredictRequest, opts ...gax.CallOption) *PredictResponse_PredictionResultIterator {
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.Predict[0:len(c.CallOptions.Predict):len(c.CallOptions.Predict)], opts...)
+ it := &PredictResponse_PredictionResultIterator{}
+ req = proto.Clone(req).(*recommendationenginepb.PredictRequest)
+ it.InternalFetch = func(pageSize int, pageToken string) ([]*recommendationenginepb.PredictResponse_PredictionResult, string, error) {
+ var resp *recommendationenginepb.PredictResponse
+ req.PageToken = pageToken
+ if pageSize > math.MaxInt32 {
+ req.PageSize = math.MaxInt32
+ } else {
+ req.PageSize = int32(pageSize)
+ }
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.predictionClient.Predict(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, "", err
+ }
+
+ it.Response = resp
+ return resp.GetResults(), resp.GetNextPageToken(), nil
+ }
+ fetch := func(pageSize int, pageToken string) (string, error) {
+ items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
+ if err != nil {
+ return "", err
+ }
+ it.items = append(it.items, items...)
+ return nextPageToken, nil
+ }
+ it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
+ it.pageInfo.MaxSize = int(req.GetPageSize())
+ it.pageInfo.Token = req.GetPageToken()
+ return it
+}
+
+// PredictResponse_PredictionResultIterator manages a stream of *recommendationenginepb.PredictResponse_PredictionResult.
+type PredictResponse_PredictionResultIterator struct {
+ items []*recommendationenginepb.PredictResponse_PredictionResult
+ pageInfo *iterator.PageInfo
+ nextFunc func() error
+
+ // Response is the raw response for the current page.
+ // It must be cast to the RPC response type.
+ // Calling Next() or InternalFetch() updates this value.
+ Response interface{}
+
+ // InternalFetch is for use by the Google Cloud Libraries only.
+ // It is not part of the stable interface of this package.
+ //
+ // InternalFetch returns results from a single call to the underlying RPC.
+ // The number of results is no greater than pageSize.
+ // If there are no more results, nextPageToken is empty and err is nil.
+ InternalFetch func(pageSize int, pageToken string) (results []*recommendationenginepb.PredictResponse_PredictionResult, nextPageToken string, err error)
+}
+
+// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
+func (it *PredictResponse_PredictionResultIterator) PageInfo() *iterator.PageInfo {
+ return it.pageInfo
+}
+
+// Next returns the next result. Its second return value is iterator.Done if there are no more
+// results. Once Next returns Done, all subsequent calls will return Done.
+func (it *PredictResponse_PredictionResultIterator) Next() (*recommendationenginepb.PredictResponse_PredictionResult, error) {
+ var item *recommendationenginepb.PredictResponse_PredictionResult
+ if err := it.nextFunc(); err != nil {
+ return item, err
+ }
+ item = it.items[0]
+ it.items = it.items[1:]
+ return item, nil
+}
+
+func (it *PredictResponse_PredictionResultIterator) bufLen() int {
+ return len(it.items)
+}
+
+func (it *PredictResponse_PredictionResultIterator) takeBuf() interface{} {
+ b := it.items
+ it.items = nil
+ return b
+}
diff --git a/recommendationengine/apiv1beta1/prediction_client_example_test.go b/recommendationengine/apiv1beta1/prediction_client_example_test.go
new file mode 100644
index 0000000..7c98db8
--- /dev/null
+++ b/recommendationengine/apiv1beta1/prediction_client_example_test.go
@@ -0,0 +1,62 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine_test
+
+import (
+ "context"
+
+ recommendationengine "cloud.google.com/go/recommendationengine/apiv1beta1"
+ "google.golang.org/api/iterator"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+)
+
+func ExampleNewPredictionClient() {
+ ctx := context.Background()
+ c, err := recommendationengine.NewPredictionClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use client.
+ _ = c
+}
+
+func ExamplePredictionClient_Predict() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ // import "google.golang.org/api/iterator"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewPredictionClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.PredictRequest{
+ // TODO: Fill request struct fields.
+ }
+ it := c.Predict(ctx, req)
+ for {
+ resp, err := it.Next()
+ if err == iterator.Done {
+ break
+ }
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+ }
+}
diff --git a/recommendationengine/apiv1beta1/user_event_client.go b/recommendationengine/apiv1beta1/user_event_client.go
new file mode 100644
index 0000000..d6d5f67
--- /dev/null
+++ b/recommendationengine/apiv1beta1/user_event_client.go
@@ -0,0 +1,551 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine
+
+import (
+ "context"
+ "fmt"
+ "math"
+ "net/url"
+ "time"
+
+ "cloud.google.com/go/longrunning"
+ lroauto "cloud.google.com/go/longrunning/autogen"
+ "github.com/golang/protobuf/proto"
+ gax "github.com/googleapis/gax-go/v2"
+ "google.golang.org/api/iterator"
+ "google.golang.org/api/option"
+ "google.golang.org/api/option/internaloption"
+ gtransport "google.golang.org/api/transport/grpc"
+ httpbodypb "google.golang.org/genproto/googleapis/api/httpbody"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ longrunningpb "google.golang.org/genproto/googleapis/longrunning"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/metadata"
+)
+
+var newUserEventClientHook clientHook
+
+// UserEventCallOptions contains the retry settings for each method of UserEventClient.
+type UserEventCallOptions struct {
+ WriteUserEvent []gax.CallOption
+ CollectUserEvent []gax.CallOption
+ ListUserEvents []gax.CallOption
+ PurgeUserEvents []gax.CallOption
+ ImportUserEvents []gax.CallOption
+}
+
+func defaultUserEventClientOptions() []option.ClientOption {
+ return []option.ClientOption{
+ internaloption.WithDefaultEndpoint("recommendationengine.googleapis.com:443"),
+ internaloption.WithDefaultMTLSEndpoint("recommendationengine.mtls.googleapis.com:443"),
+ internaloption.WithDefaultAudience("https://recommendationengine.googleapis.com/"),
+ internaloption.WithDefaultScopes(DefaultAuthScopes()...),
+ option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
+ option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
+ grpc.MaxCallRecvMsgSize(math.MaxInt32))),
+ }
+}
+
+func defaultUserEventCallOptions() *UserEventCallOptions {
+ return &UserEventCallOptions{
+ WriteUserEvent: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ CollectUserEvent: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ ListUserEvents: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ PurgeUserEvents: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ ImportUserEvents: []gax.CallOption{
+ gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.Unavailable,
+ codes.DeadlineExceeded,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60000 * time.Millisecond,
+ Multiplier: 1.30,
+ })
+ }),
+ },
+ }
+}
+
+// UserEventClient is a client for interacting with Recommendations AI.
+//
+// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
+type UserEventClient struct {
+ // Connection pool of gRPC connections to the service.
+ connPool gtransport.ConnPool
+
+ // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
+ disableDeadlines bool
+
+ // The gRPC API client.
+ userEventClient recommendationenginepb.UserEventServiceClient
+
+ // LROClient is used internally to handle longrunning operations.
+ // It is exposed so that its CallOptions can be modified if required.
+ // Users should not Close this client.
+ LROClient *lroauto.OperationsClient
+
+ // The call options for this service.
+ CallOptions *UserEventCallOptions
+
+ // The x-goog-* metadata to be sent with each request.
+ xGoogMetadata metadata.MD
+}
+
+// NewUserEventClient creates a new user event service client.
+//
+// Service for ingesting end user actions on the customer website.
+func NewUserEventClient(ctx context.Context, opts ...option.ClientOption) (*UserEventClient, error) {
+ clientOpts := defaultUserEventClientOptions()
+
+ if newUserEventClientHook != nil {
+ hookOpts, err := newUserEventClientHook(ctx, clientHookParams{})
+ if err != nil {
+ return nil, err
+ }
+ clientOpts = append(clientOpts, hookOpts...)
+ }
+
+ disableDeadlines, err := checkDisableDeadlines()
+ if err != nil {
+ return nil, err
+ }
+
+ connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
+ if err != nil {
+ return nil, err
+ }
+ c := &UserEventClient{
+ connPool: connPool,
+ disableDeadlines: disableDeadlines,
+ CallOptions: defaultUserEventCallOptions(),
+
+ userEventClient: recommendationenginepb.NewUserEventServiceClient(connPool),
+ }
+ c.setGoogleClientInfo()
+
+ c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
+ if err != nil {
+ // This error "should not happen", since we are just reusing old connection pool
+ // and never actually need to dial.
+ // If this does happen, we could leak connp. However, we cannot close conn:
+ // If the user invoked the constructor with option.WithGRPCConn,
+ // we would close a connection that's still in use.
+ // TODO: investigate error conditions.
+ return nil, err
+ }
+ return c, nil
+}
+
+// Connection returns a connection to the API service.
+//
+// Deprecated.
+func (c *UserEventClient) Connection() *grpc.ClientConn {
+ return c.connPool.Conn()
+}
+
+// Close closes the connection to the API service. The user should invoke this when
+// the client is no longer required.
+func (c *UserEventClient) Close() error {
+ return c.connPool.Close()
+}
+
+// setGoogleClientInfo sets the name and version of the application in
+// the `x-goog-api-client` header passed on each request. Intended for
+// use by Google-written clients.
+func (c *UserEventClient) setGoogleClientInfo(keyval ...string) {
+ kv := append([]string{"gl-go", versionGo()}, keyval...)
+ kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
+ c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
+}
+
+// WriteUserEvent writes a single user event.
+func (c *UserEventClient) WriteUserEvent(ctx context.Context, req *recommendationenginepb.WriteUserEventRequest, opts ...gax.CallOption) (*recommendationenginepb.UserEvent, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.WriteUserEvent[0:len(c.CallOptions.WriteUserEvent):len(c.CallOptions.WriteUserEvent)], opts...)
+ var resp *recommendationenginepb.UserEvent
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.userEventClient.WriteUserEvent(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+// CollectUserEvent writes a single user event from the browser. This uses a GET request to
+// due to browser restriction of POST-ing to a 3rd party domain.
+//
+// This method is used only by the Recommendations AI JavaScript pixel.
+// Users should not call this method directly.
+func (c *UserEventClient) CollectUserEvent(ctx context.Context, req *recommendationenginepb.CollectUserEventRequest, opts ...gax.CallOption) (*httpbodypb.HttpBody, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.CollectUserEvent[0:len(c.CallOptions.CollectUserEvent):len(c.CallOptions.CollectUserEvent)], opts...)
+ var resp *httpbodypb.HttpBody
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.userEventClient.CollectUserEvent(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
+
+// ListUserEvents gets a list of user events within a time range, with potential filtering.
+func (c *UserEventClient) ListUserEvents(ctx context.Context, req *recommendationenginepb.ListUserEventsRequest, opts ...gax.CallOption) *UserEventIterator {
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.ListUserEvents[0:len(c.CallOptions.ListUserEvents):len(c.CallOptions.ListUserEvents)], opts...)
+ it := &UserEventIterator{}
+ req = proto.Clone(req).(*recommendationenginepb.ListUserEventsRequest)
+ it.InternalFetch = func(pageSize int, pageToken string) ([]*recommendationenginepb.UserEvent, string, error) {
+ var resp *recommendationenginepb.ListUserEventsResponse
+ req.PageToken = pageToken
+ if pageSize > math.MaxInt32 {
+ req.PageSize = math.MaxInt32
+ } else {
+ req.PageSize = int32(pageSize)
+ }
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.userEventClient.ListUserEvents(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, "", err
+ }
+
+ it.Response = resp
+ return resp.GetUserEvents(), resp.GetNextPageToken(), nil
+ }
+ fetch := func(pageSize int, pageToken string) (string, error) {
+ items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
+ if err != nil {
+ return "", err
+ }
+ it.items = append(it.items, items...)
+ return nextPageToken, nil
+ }
+ it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
+ it.pageInfo.MaxSize = int(req.GetPageSize())
+ it.pageInfo.Token = req.GetPageToken()
+ return it
+}
+
+// PurgeUserEvents deletes permanently all user events specified by the filter provided.
+// Depending on the number of events specified by the filter, this operation
+// could take hours or days to complete. To test a filter, use the list
+// command first.
+func (c *UserEventClient) PurgeUserEvents(ctx context.Context, req *recommendationenginepb.PurgeUserEventsRequest, opts ...gax.CallOption) (*PurgeUserEventsOperation, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.PurgeUserEvents[0:len(c.CallOptions.PurgeUserEvents):len(c.CallOptions.PurgeUserEvents)], opts...)
+ var resp *longrunningpb.Operation
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.userEventClient.PurgeUserEvents(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return &PurgeUserEventsOperation{
+ lro: longrunning.InternalNewOperation(c.LROClient, resp),
+ }, nil
+}
+
+// ImportUserEvents bulk import of User events. Request processing might be
+// synchronous. Events that already exist are skipped.
+// Use this method for backfilling historical user events.
+//
+// Operation.response is of type ImportResponse. Note that it is
+// possible for a subset of the items to be successfully inserted.
+// Operation.metadata is of type ImportMetadata.
+func (c *UserEventClient) ImportUserEvents(ctx context.Context, req *recommendationenginepb.ImportUserEventsRequest, opts ...gax.CallOption) (*ImportUserEventsOperation, error) {
+ if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
+ cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
+ defer cancel()
+ ctx = cctx
+ }
+ md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
+ ctx = insertMetadata(ctx, c.xGoogMetadata, md)
+ opts = append(c.CallOptions.ImportUserEvents[0:len(c.CallOptions.ImportUserEvents):len(c.CallOptions.ImportUserEvents)], opts...)
+ var resp *longrunningpb.Operation
+ err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
+ var err error
+ resp, err = c.userEventClient.ImportUserEvents(ctx, req, settings.GRPC...)
+ return err
+ }, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return &ImportUserEventsOperation{
+ lro: longrunning.InternalNewOperation(c.LROClient, resp),
+ }, nil
+}
+
+// ImportUserEventsOperation manages a long-running operation from ImportUserEvents.
+type ImportUserEventsOperation struct {
+ lro *longrunning.Operation
+}
+
+// ImportUserEventsOperation returns a new ImportUserEventsOperation from a given name.
+// The name must be that of a previously created ImportUserEventsOperation, possibly from a different process.
+func (c *UserEventClient) ImportUserEventsOperation(name string) *ImportUserEventsOperation {
+ return &ImportUserEventsOperation{
+ lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
+ }
+}
+
+// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
+//
+// See documentation of Poll for error-handling information.
+func (op *ImportUserEventsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*recommendationenginepb.ImportUserEventsResponse, error) {
+ var resp recommendationenginepb.ImportUserEventsResponse
+ if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
+ return nil, err
+ }
+ return &resp, nil
+}
+
+// Poll fetches the latest state of the long-running operation.
+//
+// Poll also fetches the latest metadata, which can be retrieved by Metadata.
+//
+// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
+// the operation has completed with failure, the error is returned and op.Done will return true.
+// If Poll succeeds and the operation has completed successfully,
+// op.Done will return true, and the response of the operation is returned.
+// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
+func (op *ImportUserEventsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*recommendationenginepb.ImportUserEventsResponse, error) {
+ var resp recommendationenginepb.ImportUserEventsResponse
+ if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
+ return nil, err
+ }
+ if !op.Done() {
+ return nil, nil
+ }
+ return &resp, nil
+}
+
+// Metadata returns metadata associated with the long-running operation.
+// Metadata itself does not contact the server, but Poll does.
+// To get the latest metadata, call this method after a successful call to Poll.
+// If the metadata is not available, the returned metadata and error are both nil.
+func (op *ImportUserEventsOperation) Metadata() (*recommendationenginepb.ImportMetadata, error) {
+ var meta recommendationenginepb.ImportMetadata
+ if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
+ return nil, nil
+ } else if err != nil {
+ return nil, err
+ }
+ return &meta, nil
+}
+
+// Done reports whether the long-running operation has completed.
+func (op *ImportUserEventsOperation) Done() bool {
+ return op.lro.Done()
+}
+
+// Name returns the name of the long-running operation.
+// The name is assigned by the server and is unique within the service from which the operation is created.
+func (op *ImportUserEventsOperation) Name() string {
+ return op.lro.Name()
+}
+
+// PurgeUserEventsOperation manages a long-running operation from PurgeUserEvents.
+type PurgeUserEventsOperation struct {
+ lro *longrunning.Operation
+}
+
+// PurgeUserEventsOperation returns a new PurgeUserEventsOperation from a given name.
+// The name must be that of a previously created PurgeUserEventsOperation, possibly from a different process.
+func (c *UserEventClient) PurgeUserEventsOperation(name string) *PurgeUserEventsOperation {
+ return &PurgeUserEventsOperation{
+ lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
+ }
+}
+
+// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
+//
+// See documentation of Poll for error-handling information.
+func (op *PurgeUserEventsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*recommendationenginepb.PurgeUserEventsResponse, error) {
+ var resp recommendationenginepb.PurgeUserEventsResponse
+ if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
+ return nil, err
+ }
+ return &resp, nil
+}
+
+// Poll fetches the latest state of the long-running operation.
+//
+// Poll also fetches the latest metadata, which can be retrieved by Metadata.
+//
+// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
+// the operation has completed with failure, the error is returned and op.Done will return true.
+// If Poll succeeds and the operation has completed successfully,
+// op.Done will return true, and the response of the operation is returned.
+// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
+func (op *PurgeUserEventsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*recommendationenginepb.PurgeUserEventsResponse, error) {
+ var resp recommendationenginepb.PurgeUserEventsResponse
+ if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
+ return nil, err
+ }
+ if !op.Done() {
+ return nil, nil
+ }
+ return &resp, nil
+}
+
+// Metadata returns metadata associated with the long-running operation.
+// Metadata itself does not contact the server, but Poll does.
+// To get the latest metadata, call this method after a successful call to Poll.
+// If the metadata is not available, the returned metadata and error are both nil.
+func (op *PurgeUserEventsOperation) Metadata() (*recommendationenginepb.PurgeUserEventsMetadata, error) {
+ var meta recommendationenginepb.PurgeUserEventsMetadata
+ if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
+ return nil, nil
+ } else if err != nil {
+ return nil, err
+ }
+ return &meta, nil
+}
+
+// Done reports whether the long-running operation has completed.
+func (op *PurgeUserEventsOperation) Done() bool {
+ return op.lro.Done()
+}
+
+// Name returns the name of the long-running operation.
+// The name is assigned by the server and is unique within the service from which the operation is created.
+func (op *PurgeUserEventsOperation) Name() string {
+ return op.lro.Name()
+}
+
+// UserEventIterator manages a stream of *recommendationenginepb.UserEvent.
+type UserEventIterator struct {
+ items []*recommendationenginepb.UserEvent
+ pageInfo *iterator.PageInfo
+ nextFunc func() error
+
+ // Response is the raw response for the current page.
+ // It must be cast to the RPC response type.
+ // Calling Next() or InternalFetch() updates this value.
+ Response interface{}
+
+ // InternalFetch is for use by the Google Cloud Libraries only.
+ // It is not part of the stable interface of this package.
+ //
+ // InternalFetch returns results from a single call to the underlying RPC.
+ // The number of results is no greater than pageSize.
+ // If there are no more results, nextPageToken is empty and err is nil.
+ InternalFetch func(pageSize int, pageToken string) (results []*recommendationenginepb.UserEvent, nextPageToken string, err error)
+}
+
+// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
+func (it *UserEventIterator) PageInfo() *iterator.PageInfo {
+ return it.pageInfo
+}
+
+// Next returns the next result. Its second return value is iterator.Done if there are no more
+// results. Once Next returns Done, all subsequent calls will return Done.
+func (it *UserEventIterator) Next() (*recommendationenginepb.UserEvent, error) {
+ var item *recommendationenginepb.UserEvent
+ if err := it.nextFunc(); err != nil {
+ return item, err
+ }
+ item = it.items[0]
+ it.items = it.items[1:]
+ return item, nil
+}
+
+func (it *UserEventIterator) bufLen() int {
+ return len(it.items)
+}
+
+func (it *UserEventIterator) takeBuf() interface{} {
+ b := it.items
+ it.items = nil
+ return b
+}
diff --git a/recommendationengine/apiv1beta1/user_event_client_example_test.go b/recommendationengine/apiv1beta1/user_event_client_example_test.go
new file mode 100644
index 0000000..aac99c8
--- /dev/null
+++ b/recommendationengine/apiv1beta1/user_event_client_example_test.go
@@ -0,0 +1,152 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
+
+package recommendationengine_test
+
+import (
+ "context"
+
+ recommendationengine "cloud.google.com/go/recommendationengine/apiv1beta1"
+ "google.golang.org/api/iterator"
+ recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+)
+
+func ExampleNewUserEventClient() {
+ ctx := context.Background()
+ c, err := recommendationengine.NewUserEventClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use client.
+ _ = c
+}
+
+func ExampleUserEventClient_WriteUserEvent() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewUserEventClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.WriteUserEventRequest{
+ // TODO: Fill request struct fields.
+ }
+ resp, err := c.WriteUserEvent(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
+
+func ExampleUserEventClient_CollectUserEvent() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewUserEventClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.CollectUserEventRequest{
+ // TODO: Fill request struct fields.
+ }
+ resp, err := c.CollectUserEvent(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
+
+func ExampleUserEventClient_ListUserEvents() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+ // import "google.golang.org/api/iterator"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewUserEventClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.ListUserEventsRequest{
+ // TODO: Fill request struct fields.
+ }
+ it := c.ListUserEvents(ctx, req)
+ for {
+ resp, err := it.Next()
+ if err == iterator.Done {
+ break
+ }
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+ }
+}
+
+func ExampleUserEventClient_PurgeUserEvents() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewUserEventClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.PurgeUserEventsRequest{
+ // TODO: Fill request struct fields.
+ }
+ op, err := c.PurgeUserEvents(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ resp, err := op.Wait(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}
+
+func ExampleUserEventClient_ImportUserEvents() {
+ // import recommendationenginepb "google.golang.org/genproto/googleapis/cloud/recommendationengine/v1beta1"
+
+ ctx := context.Background()
+ c, err := recommendationengine.NewUserEventClient(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ req := &recommendationenginepb.ImportUserEventsRequest{
+ // TODO: Fill request struct fields.
+ }
+ op, err := c.ImportUserEvents(ctx, req)
+ if err != nil {
+ // TODO: Handle error.
+ }
+
+ resp, err := op.Wait(ctx)
+ if err != nil {
+ // TODO: Handle error.
+ }
+ // TODO: Use resp.
+ _ = resp
+}