diff --git a/analytics/data/apiv1alpha/alpha_analytics_data_client.go b/analytics/data/apiv1alpha/alpha_analytics_data_client.go new file mode 100644 index 00000000000..fbb7bed6a7f --- /dev/null +++ b/analytics/data/apiv1alpha/alpha_analytics_data_client.go @@ -0,0 +1,202 @@ +// Copyright 2020 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 data + +import ( + "context" + "math" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + gtransport "google.golang.org/api/transport/grpc" + datapb "google.golang.org/genproto/googleapis/analytics/data/v1alpha" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newAlphaAnalyticsDataClientHook clientHook + +// AlphaAnalyticsDataCallOptions contains the retry settings for each method of AlphaAnalyticsDataClient. +type AlphaAnalyticsDataCallOptions struct { + RunReport []gax.CallOption + RunPivotReport []gax.CallOption + BatchRunReports []gax.CallOption + BatchRunPivotReports []gax.CallOption +} + +func defaultAlphaAnalyticsDataClientOptions() []option.ClientOption { + return []option.ClientOption{ + option.WithEndpoint("analyticsdata.googleapis.com:443"), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultAlphaAnalyticsDataCallOptions() *AlphaAnalyticsDataCallOptions { + return &AlphaAnalyticsDataCallOptions{ + RunReport: []gax.CallOption{}, + RunPivotReport: []gax.CallOption{}, + BatchRunReports: []gax.CallOption{}, + BatchRunPivotReports: []gax.CallOption{}, + } +} + +// AlphaAnalyticsDataClient is a client for interacting with . +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type AlphaAnalyticsDataClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // The gRPC API client. + alphaAnalyticsDataClient datapb.AlphaAnalyticsDataClient + + // The call options for this service. + CallOptions *AlphaAnalyticsDataCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewAlphaAnalyticsDataClient creates a new alpha analytics data client. +// +// Google Analytics reporting data service. +func NewAlphaAnalyticsDataClient(ctx context.Context, opts ...option.ClientOption) (*AlphaAnalyticsDataClient, error) { + clientOpts := defaultAlphaAnalyticsDataClientOptions() + + if newAlphaAnalyticsDataClientHook != nil { + hookOpts, err := newAlphaAnalyticsDataClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &AlphaAnalyticsDataClient{ + connPool: connPool, + CallOptions: defaultAlphaAnalyticsDataCallOptions(), + + alphaAnalyticsDataClient: datapb.NewAlphaAnalyticsDataClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *AlphaAnalyticsDataClient) 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 *AlphaAnalyticsDataClient) 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 *AlphaAnalyticsDataClient) 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...)) +} + +// RunReport returns a customized report of your Google Analytics event data. Reports +// contain statistics derived from data collected by the Google Analytics +// tracking code. The data returned from the API is as a table with columns +// for the requested dimensions and metrics. Metrics are individual +// measurements of user activity on your property, such as active users or +// event count. Dimensions break down metrics across some common criteria, +// such as country or event name. +func (c *AlphaAnalyticsDataClient) RunReport(ctx context.Context, req *datapb.RunReportRequest, opts ...gax.CallOption) (*datapb.RunReportResponse, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.RunReport[0:len(c.CallOptions.RunReport):len(c.CallOptions.RunReport)], opts...) + var resp *datapb.RunReportResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.alphaAnalyticsDataClient.RunReport(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// RunPivotReport returns a customized pivot report of your Google Analytics event data. +// Pivot reports are more advanced and expressive formats than regular +// reports. In a pivot report, dimensions are only visible if they are +// included in a pivot. Multiple pivots can be specified to further dissect +// your data. +func (c *AlphaAnalyticsDataClient) RunPivotReport(ctx context.Context, req *datapb.RunPivotReportRequest, opts ...gax.CallOption) (*datapb.RunPivotReportResponse, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.RunPivotReport[0:len(c.CallOptions.RunPivotReport):len(c.CallOptions.RunPivotReport)], opts...) + var resp *datapb.RunPivotReportResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.alphaAnalyticsDataClient.RunPivotReport(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// BatchRunReports returns multiple reports in a batch. All reports must be for the same +// Entity. +func (c *AlphaAnalyticsDataClient) BatchRunReports(ctx context.Context, req *datapb.BatchRunReportsRequest, opts ...gax.CallOption) (*datapb.BatchRunReportsResponse, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.BatchRunReports[0:len(c.CallOptions.BatchRunReports):len(c.CallOptions.BatchRunReports)], opts...) + var resp *datapb.BatchRunReportsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.alphaAnalyticsDataClient.BatchRunReports(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// BatchRunPivotReports returns multiple pivot reports in a batch. All reports must be for the same +// Entity. +func (c *AlphaAnalyticsDataClient) BatchRunPivotReports(ctx context.Context, req *datapb.BatchRunPivotReportsRequest, opts ...gax.CallOption) (*datapb.BatchRunPivotReportsResponse, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.BatchRunPivotReports[0:len(c.CallOptions.BatchRunPivotReports):len(c.CallOptions.BatchRunPivotReports)], opts...) + var resp *datapb.BatchRunPivotReportsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.alphaAnalyticsDataClient.BatchRunPivotReports(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/analytics/data/apiv1alpha/alpha_analytics_data_client_example_test.go b/analytics/data/apiv1alpha/alpha_analytics_data_client_example_test.go new file mode 100644 index 00000000000..8345004a2f7 --- /dev/null +++ b/analytics/data/apiv1alpha/alpha_analytics_data_client_example_test.go @@ -0,0 +1,114 @@ +// Copyright 2020 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 data_test + +import ( + "context" + + data "cloud.google.com/go/analytics/data/apiv1alpha" + datapb "google.golang.org/genproto/googleapis/analytics/data/v1alpha" +) + +func ExampleNewAlphaAnalyticsDataClient() { + ctx := context.Background() + c, err := data.NewAlphaAnalyticsDataClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleAlphaAnalyticsDataClient_RunReport() { + // import datapb "google.golang.org/genproto/googleapis/analytics/data/v1alpha" + + ctx := context.Background() + c, err := data.NewAlphaAnalyticsDataClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &datapb.RunReportRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RunReport(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAlphaAnalyticsDataClient_RunPivotReport() { + // import datapb "google.golang.org/genproto/googleapis/analytics/data/v1alpha" + + ctx := context.Background() + c, err := data.NewAlphaAnalyticsDataClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &datapb.RunPivotReportRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RunPivotReport(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAlphaAnalyticsDataClient_BatchRunReports() { + // import datapb "google.golang.org/genproto/googleapis/analytics/data/v1alpha" + + ctx := context.Background() + c, err := data.NewAlphaAnalyticsDataClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &datapb.BatchRunReportsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.BatchRunReports(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAlphaAnalyticsDataClient_BatchRunPivotReports() { + // import datapb "google.golang.org/genproto/googleapis/analytics/data/v1alpha" + + ctx := context.Background() + c, err := data.NewAlphaAnalyticsDataClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &datapb.BatchRunPivotReportsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.BatchRunPivotReports(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/analytics/data/apiv1alpha/doc.go b/analytics/data/apiv1alpha/doc.go new file mode 100644 index 00000000000..febd9c8d800 --- /dev/null +++ b/analytics/data/apiv1alpha/doc.go @@ -0,0 +1,103 @@ +// Copyright 2020 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. + +// +// NOTE: This package is in alpha. It is not stable, and is likely to change. +// +// 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 godoc.org/cloud.google.com/go. +package data // import "cloud.google.com/go/analytics/data/apiv1alpha" + +import ( + "context" + "runtime" + "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 = "20200831" + +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) +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/analytics", + "https://www.googleapis.com/auth/analytics.readonly", + } +} + +// 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/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 536f89cb36e..789eaee0ee7 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -7,6 +7,14 @@ "docs_url": "https://pkg.go.dev/cloud.google.com/go/analytics/admin/apiv1alpha", "release_level": "alpha" }, + "cloud.google.com/go/analytics/data/apiv1alpha": { + "distribution_name": "cloud.google.com/go/analytics/data/apiv1alpha", + "description": "", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://pkg.go.dev/cloud.google.com/go/analytics/data/apiv1alpha", + "release_level": "alpha" + }, "cloud.google.com/go/asset/apiv1": { "distribution_name": "cloud.google.com/go/asset/apiv1", "description": "Cloud Asset API", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 8538fdcfc61..8ae8552ccd2 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -778,4 +778,12 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/analytics/admin/v1alpha/analyticsadmin_gapic.yaml", releaseLevel: "alpha", }, + { + inputDirectoryPath: "google/analytics/data/v1alpha", + pkg: "data", + importPath: "cloud.google.com/go/analytics/data/apiv1alpha", + gRPCServiceConfigPath: "google/analytics/data/v1alpha/analytics_data_grpc_service_config.json", + apiServiceConfigPath: "google/analytics/data/v1alpha/analyticsdata_gapic.yaml", + releaseLevel: "alpha", + }, }