Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
feat: added RunRealtimeReport method that returns a customized report…
Browse files Browse the repository at this point in the history
… of realtime event data for a GA4 property docs: minor documentation updates (#80)

PiperOrigin-RevId: 340463146

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Nov 3 09:41:08 2020 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 705962b5a317e083fdbb2311d4baa72df5816686
Source-Link: googleapis/googleapis@705962b
  • Loading branch information
yoshi-automation committed Nov 4, 2020
1 parent 6a49d40 commit 815fe2e
Show file tree
Hide file tree
Showing 29 changed files with 9,026 additions and 310 deletions.
Expand Up @@ -491,6 +491,48 @@ public final UnaryCallable<GetMetadataRequest, Metadata> getMetadataCallable() {
return stub.getMetadataCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* The Google Analytics Realtime API returns a customized report of realtime event data for your
* property. These reports show events and usage from the last 30 minutes.
*
* <p>Sample code:
*
* <pre><code>
* try (AlphaAnalyticsDataClient alphaAnalyticsDataClient = AlphaAnalyticsDataClient.create()) {
* RunRealtimeReportRequest request = RunRealtimeReportRequest.newBuilder().build();
* RunRealtimeReportResponse response = alphaAnalyticsDataClient.runRealtimeReport(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final RunRealtimeReportResponse runRealtimeReport(RunRealtimeReportRequest request) {
return runRealtimeReportCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* The Google Analytics Realtime API returns a customized report of realtime event data for your
* property. These reports show events and usage from the last 30 minutes.
*
* <p>Sample code:
*
* <pre><code>
* try (AlphaAnalyticsDataClient alphaAnalyticsDataClient = AlphaAnalyticsDataClient.create()) {
* RunRealtimeReportRequest request = RunRealtimeReportRequest.newBuilder().build();
* ApiFuture&lt;RunRealtimeReportResponse&gt; future = alphaAnalyticsDataClient.runRealtimeReportCallable().futureCall(request);
* // Do something
* RunRealtimeReportResponse response = future.get();
* }
* </code></pre>
*/
public final UnaryCallable<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportCallable() {
return stub.runRealtimeReportCallable();
}

@Override
public final void close() {
stub.close();
Expand Down
Expand Up @@ -97,6 +97,12 @@ public UnaryCallSettings<GetMetadataRequest, Metadata> getMetadataSettings() {
return ((AlphaAnalyticsDataStubSettings) getStubSettings()).getMetadataSettings();
}

/** Returns the object with the settings used for calls to runRealtimeReport. */
public UnaryCallSettings<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportSettings() {
return ((AlphaAnalyticsDataStubSettings) getStubSettings()).runRealtimeReportSettings();
}

public static final AlphaAnalyticsDataSettings create(AlphaAnalyticsDataStubSettings stub)
throws IOException {
return new AlphaAnalyticsDataSettings.Builder(stub.toBuilder()).build();
Expand Down Expand Up @@ -228,6 +234,12 @@ public UnaryCallSettings.Builder<GetMetadataRequest, Metadata> getMetadataSettin
return getStubSettingsBuilder().getMetadataSettings();
}

/** Returns the builder for the settings used for calls to runRealtimeReport. */
public UnaryCallSettings.Builder<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportSettings() {
return getStubSettingsBuilder().runRealtimeReportSettings();
}

@Override
public AlphaAnalyticsDataSettings build() throws IOException {
return new AlphaAnalyticsDataSettings(this);
Expand Down
Expand Up @@ -24,6 +24,8 @@
import com.google.analytics.data.v1alpha.Metadata;
import com.google.analytics.data.v1alpha.RunPivotReportRequest;
import com.google.analytics.data.v1alpha.RunPivotReportResponse;
import com.google.analytics.data.v1alpha.RunRealtimeReportRequest;
import com.google.analytics.data.v1alpha.RunRealtimeReportResponse;
import com.google.analytics.data.v1alpha.RunReportRequest;
import com.google.analytics.data.v1alpha.RunReportResponse;
import com.google.analytics.data.v1alpha.UniversalMetadata;
Expand Down Expand Up @@ -68,6 +70,11 @@ public UnaryCallable<GetMetadataRequest, Metadata> getMetadataCallable() {
throw new UnsupportedOperationException("Not implemented: getMetadataCallable()");
}

public UnaryCallable<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportCallable() {
throw new UnsupportedOperationException("Not implemented: runRealtimeReportCallable()");
}

@Override
public abstract void close();
}
Expand Up @@ -24,6 +24,8 @@
import com.google.analytics.data.v1alpha.Metadata;
import com.google.analytics.data.v1alpha.RunPivotReportRequest;
import com.google.analytics.data.v1alpha.RunPivotReportResponse;
import com.google.analytics.data.v1alpha.RunRealtimeReportRequest;
import com.google.analytics.data.v1alpha.RunRealtimeReportResponse;
import com.google.analytics.data.v1alpha.RunReportRequest;
import com.google.analytics.data.v1alpha.RunReportResponse;
import com.google.analytics.data.v1alpha.UniversalMetadata;
Expand Down Expand Up @@ -102,6 +104,8 @@ public class AlphaAnalyticsDataStubSettings extends StubSettings<AlphaAnalyticsD
private final UnaryCallSettings<GetUniversalMetadataRequest, UniversalMetadata>
getUniversalMetadataSettings;
private final UnaryCallSettings<GetMetadataRequest, Metadata> getMetadataSettings;
private final UnaryCallSettings<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportSettings;

/** Returns the object with the settings used for calls to runReport. */
public UnaryCallSettings<RunReportRequest, RunReportResponse> runReportSettings() {
Expand Down Expand Up @@ -136,6 +140,12 @@ public UnaryCallSettings<GetMetadataRequest, Metadata> getMetadataSettings() {
return getMetadataSettings;
}

/** Returns the object with the settings used for calls to runRealtimeReport. */
public UnaryCallSettings<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportSettings() {
return runRealtimeReportSettings;
}

@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public AlphaAnalyticsDataStub createStub() throws IOException {
if (getTransportChannelProvider()
Expand Down Expand Up @@ -211,6 +221,7 @@ protected AlphaAnalyticsDataStubSettings(Builder settingsBuilder) throws IOExcep
batchRunPivotReportsSettings = settingsBuilder.batchRunPivotReportsSettings().build();
getUniversalMetadataSettings = settingsBuilder.getUniversalMetadataSettings().build();
getMetadataSettings = settingsBuilder.getMetadataSettings().build();
runRealtimeReportSettings = settingsBuilder.runRealtimeReportSettings().build();
}

/** Builder for AlphaAnalyticsDataStubSettings. */
Expand All @@ -229,6 +240,8 @@ public static class Builder
private final UnaryCallSettings.Builder<GetUniversalMetadataRequest, UniversalMetadata>
getUniversalMetadataSettings;
private final UnaryCallSettings.Builder<GetMetadataRequest, Metadata> getMetadataSettings;
private final UnaryCallSettings.Builder<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportSettings;

private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
RETRYABLE_CODE_DEFINITIONS;
Expand Down Expand Up @@ -293,14 +306,17 @@ protected Builder(ClientContext clientContext) {

getMetadataSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();

runRealtimeReportSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
runReportSettings,
runPivotReportSettings,
batchRunReportsSettings,
batchRunPivotReportsSettings,
getUniversalMetadataSettings,
getMetadataSettings);
getMetadataSettings,
runRealtimeReportSettings);

initDefaults(this);
}
Expand Down Expand Up @@ -346,6 +362,11 @@ private static Builder initDefaults(Builder builder) {
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params"));

builder
.runRealtimeReportSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params"));

return builder;
}

Expand All @@ -358,6 +379,7 @@ protected Builder(AlphaAnalyticsDataStubSettings settings) {
batchRunPivotReportsSettings = settings.batchRunPivotReportsSettings.toBuilder();
getUniversalMetadataSettings = settings.getUniversalMetadataSettings.toBuilder();
getMetadataSettings = settings.getMetadataSettings.toBuilder();
runRealtimeReportSettings = settings.runRealtimeReportSettings.toBuilder();

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
Expand All @@ -366,7 +388,8 @@ protected Builder(AlphaAnalyticsDataStubSettings settings) {
batchRunReportsSettings,
batchRunPivotReportsSettings,
getUniversalMetadataSettings,
getMetadataSettings);
getMetadataSettings,
runRealtimeReportSettings);
}

// NEXT_MAJOR_VER: remove 'throws Exception'
Expand Down Expand Up @@ -419,6 +442,12 @@ public UnaryCallSettings.Builder<GetMetadataRequest, Metadata> getMetadataSettin
return getMetadataSettings;
}

/** Returns the builder for the settings used for calls to runRealtimeReport. */
public UnaryCallSettings.Builder<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportSettings() {
return runRealtimeReportSettings;
}

@Override
public AlphaAnalyticsDataStubSettings build() throws IOException {
return new AlphaAnalyticsDataStubSettings(this);
Expand Down
Expand Up @@ -24,6 +24,8 @@
import com.google.analytics.data.v1alpha.Metadata;
import com.google.analytics.data.v1alpha.RunPivotReportRequest;
import com.google.analytics.data.v1alpha.RunPivotReportResponse;
import com.google.analytics.data.v1alpha.RunRealtimeReportRequest;
import com.google.analytics.data.v1alpha.RunRealtimeReportResponse;
import com.google.analytics.data.v1alpha.RunReportRequest;
import com.google.analytics.data.v1alpha.RunReportResponse;
import com.google.analytics.data.v1alpha.UniversalMetadata;
Expand Down Expand Up @@ -109,6 +111,17 @@ public class GrpcAlphaAnalyticsDataStub extends AlphaAnalyticsDataStub {
.setRequestMarshaller(ProtoUtils.marshaller(GetMetadataRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Metadata.getDefaultInstance()))
.build();
private static final MethodDescriptor<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportMethodDescriptor =
MethodDescriptor.<RunRealtimeReportRequest, RunRealtimeReportResponse>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.analytics.data.v1alpha.AlphaAnalyticsData/RunRealtimeReport")
.setRequestMarshaller(
ProtoUtils.marshaller(RunRealtimeReportRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(RunRealtimeReportResponse.getDefaultInstance()))
.build();

private final BackgroundResource backgroundResources;

Expand All @@ -121,6 +134,8 @@ public class GrpcAlphaAnalyticsDataStub extends AlphaAnalyticsDataStub {
private final UnaryCallable<GetUniversalMetadataRequest, UniversalMetadata>
getUniversalMetadataCallable;
private final UnaryCallable<GetMetadataRequest, Metadata> getMetadataCallable;
private final UnaryCallable<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportCallable;

private final GrpcStubCallableFactory callableFactory;

Expand Down Expand Up @@ -200,6 +215,20 @@ public Map<String, String> extract(GetMetadataRequest request) {
}
})
.build();
GrpcCallSettings<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportTransportSettings =
GrpcCallSettings.<RunRealtimeReportRequest, RunRealtimeReportResponse>newBuilder()
.setMethodDescriptor(runRealtimeReportMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<RunRealtimeReportRequest>() {
@Override
public Map<String, String> extract(RunRealtimeReportRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("property", String.valueOf(request.getProperty()));
return params.build();
}
})
.build();

this.runReportCallable =
callableFactory.createUnaryCallable(
Expand All @@ -223,6 +252,11 @@ public Map<String, String> extract(GetMetadataRequest request) {
this.getMetadataCallable =
callableFactory.createUnaryCallable(
getMetadataTransportSettings, settings.getMetadataSettings(), clientContext);
this.runRealtimeReportCallable =
callableFactory.createUnaryCallable(
runRealtimeReportTransportSettings,
settings.runRealtimeReportSettings(),
clientContext);

backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
Expand Down Expand Up @@ -253,6 +287,11 @@ public UnaryCallable<GetMetadataRequest, Metadata> getMetadataCallable() {
return getMetadataCallable;
}

public UnaryCallable<RunRealtimeReportRequest, RunRealtimeReportResponse>
runRealtimeReportCallable() {
return runRealtimeReportCallable;
}

@Override
public final void close() {
shutdown();
Expand Down
Expand Up @@ -300,4 +300,43 @@ public void getMetadataExceptionTest() throws Exception {
// Expected exception
}
}

@Test
@SuppressWarnings("all")
public void runRealtimeReportTest() {
int rowCount = 1340416618;
RunRealtimeReportResponse expectedResponse =
RunRealtimeReportResponse.newBuilder().setRowCount(rowCount).build();
mockAlphaAnalyticsData.addResponse(expectedResponse);

RunRealtimeReportRequest request = RunRealtimeReportRequest.newBuilder().build();

RunRealtimeReportResponse actualResponse = client.runRealtimeReport(request);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAlphaAnalyticsData.getRequests();
Assert.assertEquals(1, actualRequests.size());
RunRealtimeReportRequest actualRequest = (RunRealtimeReportRequest) actualRequests.get(0);

Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
@SuppressWarnings("all")
public void runRealtimeReportExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockAlphaAnalyticsData.addException(exception);

try {
RunRealtimeReportRequest request = RunRealtimeReportRequest.newBuilder().build();

client.runRealtimeReport(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Expand Up @@ -145,4 +145,20 @@ public void getMetadata(GetMetadataRequest request, StreamObserver<Metadata> res
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
}
}

@Override
public void runRealtimeReport(
RunRealtimeReportRequest request,
StreamObserver<RunRealtimeReportResponse> responseObserver) {
Object response = responses.remove();
if (response instanceof RunRealtimeReportResponse) {
requests.add(request);
responseObserver.onNext((RunRealtimeReportResponse) response);
responseObserver.onCompleted();
} else if (response instanceof Exception) {
responseObserver.onError((Exception) response);
} else {
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
}
}
}

0 comments on commit 815fe2e

Please sign in to comment.