Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [AnalyticsData] add CreateReportTask, QueryReportTask, GetReportTask, ListReportTasks methods to the Data API v1alpha #7295

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified AnalyticsData/metadata/V1Alpha/AnalyticsDataApi.php
Binary file not shown.
Binary file modified AnalyticsData/metadata/V1Alpha/Data.php
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/*
* Copyright 2024 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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateReportTask_sync]
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\CreateReportTaskRequest;
use Google\Analytics\Data\V1alpha\ReportTask;
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Rpc\Status;

/**
* Initiates the creation of a report task. This method quickly
* returns a report task and initiates a long running
* asynchronous request to form a customized report of your Google Analytics
* event data.
*
* @param string $formattedParent The parent resource where this report task will be created.
* Format: `properties/{propertyId}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
*/
function create_report_task_sample(string $formattedParent): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();

// Prepare the request message.
$reportTask = new ReportTask();
$request = (new CreateReportTaskRequest())
->setParent($formattedParent)
->setReportTask($reportTask);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $alphaAnalyticsDataClient->createReportTask($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var ReportTask $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');

create_report_task_sample($formattedParent);
}
// [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateReportTask_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/*
* Copyright 2024 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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetReportTask_sync]
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\GetReportTaskRequest;
use Google\Analytics\Data\V1alpha\ReportTask;
use Google\ApiCore\ApiException;

/**
* Gets report metadata about a specific report task. After creating a report
* task, use this method to check its processing state or inspect its
* report definition.
*
* @param string $formattedName The report task resource name.
* Format: `properties/{property}/reportTasks/{report_task}`
* Please see {@see AlphaAnalyticsDataClient::reportTaskName()} for help formatting this field.
*/
function get_report_task_sample(string $formattedName): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();

// Prepare the request message.
$request = (new GetReportTaskRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var ReportTask $response */
$response = $alphaAnalyticsDataClient->getReportTask($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = AlphaAnalyticsDataClient::reportTaskName('[PROPERTY]', '[REPORT_TASK]');

get_report_task_sample($formattedName);
}
// [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetReportTask_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/*
* Copyright 2024 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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListReportTasks_sync]
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\ListReportTasksRequest;
use Google\Analytics\Data\V1alpha\ReportTask;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
* Lists all report tasks for a property.
*
* @param string $formattedParent All report tasks for this property will be listed in the
* response. Format: `properties/{property}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
*/
function list_report_tasks_sample(string $formattedParent): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();

// Prepare the request message.
$request = (new ListReportTasksRequest())
->setParent($formattedParent);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $alphaAnalyticsDataClient->listReportTasks($request);

/** @var ReportTask $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');

list_report_tasks_sample($formattedParent);
}
// [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListReportTasks_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/*
* Copyright 2024 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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryReportTask_sync]
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\QueryReportTaskRequest;
use Google\Analytics\Data\V1alpha\QueryReportTaskResponse;
use Google\ApiCore\ApiException;

/**
* Retrieves a report task's content. After requesting the `CreateReportTask`,
* you are able to retrieve the report content once the report is
* ACTIVE. This method will return an error if the report task's state is not
* `ACTIVE`. A query response will return the tabular row & column values of
* the report.
*
* @param string $name The report source name.
* Format: `properties/{property}/reportTasks/{report}`
*/
function query_report_task_sample(string $name): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();

// Prepare the request message.
$request = (new QueryReportTaskRequest())
->setName($name);

// Call the API and handle any network failures.
try {
/** @var QueryReportTaskResponse $response */
$response = $alphaAnalyticsDataClient->queryReportTask($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$name = '[NAME]';

query_report_task_sample($name);
}
// [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryReportTask_sync]
Loading
Loading