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: [AppsChat] add GetSpaceEvent and ListSpaceEvents APIs #7523

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] committed Jul 12, 2024
commit 93b4b05e038d4436972963e072251e590b21acdf
Binary file modified AppsChat/metadata/Chat/V1/ChatService.php
Binary file not shown.
File renamed without changes.
101 changes: 101 additions & 0 deletions AppsChat/src/Chat/V1/Client/ChatServiceClient.php
Original file line number Diff line number Diff line change
@@ -47,18 +47,21 @@
use Google\Apps\Chat\V1\GetAttachmentRequest;
use Google\Apps\Chat\V1\GetMembershipRequest;
use Google\Apps\Chat\V1\GetMessageRequest;
use Google\Apps\Chat\V1\GetSpaceEventRequest;
use Google\Apps\Chat\V1\GetSpaceReadStateRequest;
use Google\Apps\Chat\V1\GetSpaceRequest;
use Google\Apps\Chat\V1\GetThreadReadStateRequest;
use Google\Apps\Chat\V1\ListMembershipsRequest;
use Google\Apps\Chat\V1\ListMessagesRequest;
use Google\Apps\Chat\V1\ListReactionsRequest;
use Google\Apps\Chat\V1\ListSpaceEventsRequest;
use Google\Apps\Chat\V1\ListSpacesRequest;
use Google\Apps\Chat\V1\Membership;
use Google\Apps\Chat\V1\Message;
use Google\Apps\Chat\V1\Reaction;
use Google\Apps\Chat\V1\SetUpSpaceRequest;
use Google\Apps\Chat\V1\Space;
use Google\Apps\Chat\V1\SpaceEvent;
use Google\Apps\Chat\V1\SpaceReadState;
use Google\Apps\Chat\V1\ThreadReadState;
use Google\Apps\Chat\V1\UpdateMembershipRequest;
@@ -96,11 +99,13 @@
* @method PromiseInterface getMembershipAsync(GetMembershipRequest $request, array $optionalArgs = [])
* @method PromiseInterface getMessageAsync(GetMessageRequest $request, array $optionalArgs = [])
* @method PromiseInterface getSpaceAsync(GetSpaceRequest $request, array $optionalArgs = [])
* @method PromiseInterface getSpaceEventAsync(GetSpaceEventRequest $request, array $optionalArgs = [])
* @method PromiseInterface getSpaceReadStateAsync(GetSpaceReadStateRequest $request, array $optionalArgs = [])
* @method PromiseInterface getThreadReadStateAsync(GetThreadReadStateRequest $request, array $optionalArgs = [])
* @method PromiseInterface listMembershipsAsync(ListMembershipsRequest $request, array $optionalArgs = [])
* @method PromiseInterface listMessagesAsync(ListMessagesRequest $request, array $optionalArgs = [])
* @method PromiseInterface listReactionsAsync(ListReactionsRequest $request, array $optionalArgs = [])
* @method PromiseInterface listSpaceEventsAsync(ListSpaceEventsRequest $request, array $optionalArgs = [])
* @method PromiseInterface listSpacesAsync(ListSpacesRequest $request, array $optionalArgs = [])
* @method PromiseInterface setUpSpaceAsync(SetUpSpaceRequest $request, array $optionalArgs = [])
* @method PromiseInterface updateMembershipAsync(UpdateMembershipRequest $request, array $optionalArgs = [])
@@ -287,6 +292,23 @@ public static function spaceName(string $space): string
]);
}

/**
* Formats a string containing the fully-qualified path to represent a space_event
* resource.
*
* @param string $space
* @param string $spaceEvent
*
* @return string The formatted space_event resource.
*/
public static function spaceEventName(string $space, string $spaceEvent): string
{
return self::getPathTemplate('spaceEvent')->render([
'space' => $space,
'space_event' => $spaceEvent,
]);
}

/**
* Formats a string containing the fully-qualified path to represent a
* space_read_state resource.
@@ -350,6 +372,7 @@ public static function threadReadStateName(string $user, string $space, string $
* - quotedMessageMetadata: spaces/{space}/messages/{message}/quotedMessageMetadata/{quoted_message_metadata}
* - reaction: spaces/{space}/messages/{message}/reactions/{reaction}
* - space: spaces/{space}
* - spaceEvent: spaces/{space}/spaceEvents/{space_event}
* - spaceReadState: users/{user}/spaces/{space}/spaceReadState
* - thread: spaces/{space}/threads/{thread}
* - threadReadState: users/{user}/spaces/{space}/threads/{thread}/threadReadState
@@ -952,6 +975,45 @@ public function getSpace(GetSpaceRequest $request, array $callOptions = []): Spa
return $this->startApiCall('GetSpace', $request, $callOptions)->wait();
}

/**
* Returns an event from a Google Chat space. The [event
* payload](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.spaceEvents#SpaceEvent.FIELDS.oneof_payload)
* contains the most recent version of the resource that changed. For example,
* if you request an event about a new message but the message was later
* updated, the server returns the updated `Message` resource in the event
* payload.
*
* Requires [user
* authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user).
* To get an event, the authenticated user must be a member of the space.
*
* For an example, see [Get details about an
* event from a Google Chat
* space](https://developers.google.com/workspace/chat/get-space-event).
*
* The async variant is {@see ChatServiceClient::getSpaceEventAsync()} .
*
* @example samples/V1/ChatServiceClient/get_space_event.php
*
* @param GetSpaceEventRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return SpaceEvent
*
* @throws ApiException Thrown if the API call fails.
*/
public function getSpaceEvent(GetSpaceEventRequest $request, array $callOptions = []): SpaceEvent
{
return $this->startApiCall('GetSpaceEvent', $request, $callOptions)->wait();
}

/**
* Returns details about a user's read state within a space, used to identify
* read and unread messages. For an example, see [Get details about a user's
@@ -1120,6 +1182,45 @@ public function listReactions(ListReactionsRequest $request, array $callOptions
return $this->startApiCall('ListReactions', $request, $callOptions);
}

/**
* Lists events from a Google Chat space. For each event, the
* [payload](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.spaceEvents#SpaceEvent.FIELDS.oneof_payload)
* contains the most recent version of the Chat resource. For example, if you
* list events about new space members, the server returns `Membership`
* resources that contain the latest membership details. If new members were
* removed during the requested period, the event payload contains an empty
* `Membership` resource.
*
* Requires [user
* authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user).
* To list events, the authenticated user must be a member of the space.
*
* For an example, see [List events from a Google Chat
* space](https://developers.google.com/workspace/chat/list-space-events).
*
* The async variant is {@see ChatServiceClient::listSpaceEventsAsync()} .
*
* @example samples/V1/ChatServiceClient/list_space_events.php
*
* @param ListSpaceEventsRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return PagedListResponse
*
* @throws ApiException Thrown if the API call fails.
*/
public function listSpaceEvents(ListSpaceEventsRequest $request, array $callOptions = []): PagedListResponse
{
return $this->startApiCall('ListSpaceEvents', $request, $callOptions);
}

/**
* Lists spaces the caller is a member of. Group chats and DMs aren't listed
* until the first message is sent. For an example, see
File renamed without changes.
10 changes: 10 additions & 0 deletions AppsChat/src/Chat/V1/gapic_metadata.json
Original file line number Diff line number Diff line change
@@ -80,6 +80,11 @@
"getSpace"
]
},
"GetSpaceEvent": {
"methods": [
"getSpaceEvent"
]
},
"GetSpaceReadState": {
"methods": [
"getSpaceReadState"
@@ -105,6 +110,11 @@
"listReactions"
]
},
"ListSpaceEvents": {
"methods": [
"listSpaceEvents"
]
},
"ListSpaces": {
"methods": [
"listSpaces"
10 changes: 10 additions & 0 deletions AppsChat/src/Chat/V1/resources/chat_service_client_config.json
Original file line number Diff line number Diff line change
@@ -98,6 +98,11 @@
"retry_codes_name": "retry_policy_1_codes",
"retry_params_name": "retry_policy_1_params"
},
"GetSpaceEvent": {
"timeout_millis": 30000,
"retry_codes_name": "retry_policy_1_codes",
"retry_params_name": "retry_policy_1_params"
},
"GetSpaceReadState": {
"timeout_millis": 30000,
"retry_codes_name": "retry_policy_1_codes",
@@ -123,6 +128,11 @@
"retry_codes_name": "retry_policy_1_codes",
"retry_params_name": "retry_policy_1_params"
},
"ListSpaceEvents": {
"timeout_millis": 30000,
"retry_codes_name": "retry_policy_1_codes",
"retry_params_name": "retry_policy_1_params"
},
"ListSpaces": {
"timeout_millis": 30000,
"retry_codes_name": "retry_policy_1_codes",
Original file line number Diff line number Diff line change
@@ -175,6 +175,18 @@
],
],
],
'GetSpaceEvent' => [
'callType' => \Google\ApiCore\Call::UNARY_CALL,
'responseType' => 'Google\Apps\Chat\V1\SpaceEvent',
'headerParams' => [
[
'keyName' => 'name',
'fieldAccessors' => [
'getName',
],
],
],
],
'GetSpaceReadState' => [
'callType' => \Google\ApiCore\Call::UNARY_CALL,
'responseType' => 'Google\Apps\Chat\V1\SpaceReadState',
@@ -259,6 +271,26 @@
],
],
],
'ListSpaceEvents' => [
'pageStreaming' => [
'requestPageTokenGetMethod' => 'getPageToken',
'requestPageTokenSetMethod' => 'setPageToken',
'requestPageSizeGetMethod' => 'getPageSize',
'requestPageSizeSetMethod' => 'setPageSize',
'responsePageTokenGetMethod' => 'getNextPageToken',
'resourcesGetMethod' => 'getSpaceEvents',
],
'callType' => \Google\ApiCore\Call::PAGINATED_CALL,
'responseType' => 'Google\Apps\Chat\V1\ListSpaceEventsResponse',
'headerParams' => [
[
'keyName' => 'parent',
'fieldAccessors' => [
'getParent',
],
],
],
],
'ListSpaces' => [
'pageStreaming' => [
'requestPageTokenGetMethod' => 'getPageToken',
@@ -346,6 +378,7 @@
'quotedMessageMetadata' => 'spaces/{space}/messages/{message}/quotedMessageMetadata/{quoted_message_metadata}',
'reaction' => 'spaces/{space}/messages/{message}/reactions/{reaction}',
'space' => 'spaces/{space}',
'spaceEvent' => 'spaces/{space}/spaceEvents/{space_event}',
'spaceReadState' => 'users/{user}/spaces/{space}/spaceReadState',
'thread' => 'spaces/{space}/threads/{thread}',
'threadReadState' => 'users/{user}/spaces/{space}/threads/{thread}/threadReadState',
Original file line number Diff line number Diff line change
@@ -168,6 +168,17 @@
],
],
],
'GetSpaceEvent' => [
'method' => 'get',
'uriTemplate' => '/v1/{name=spaces/*/spaceEvents/*}',
'placeholders' => [
'name' => [
'getters' => [
'getName',
],
],
],
],
'GetSpaceReadState' => [
'method' => 'get',
'uriTemplate' => '/v1/{name=users/*/spaces/*/spaceReadState}',
@@ -223,6 +234,20 @@
],
],
],
'ListSpaceEvents' => [
'method' => 'get',
'uriTemplate' => '/v1/{parent=spaces/*}/spaceEvents',
'placeholders' => [
'parent' => [
'getters' => [
'getParent',
],
],
],
'queryParams' => [
'filter',
],
],
'ListSpaces' => [
'method' => 'get',
'uriTemplate' => '/v1/spaces',
146 changes: 146 additions & 0 deletions AppsChat/tests/Unit/V1/Client/ChatServiceClientTest.php
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
use Google\Apps\Chat\V1\GetAttachmentRequest;
use Google\Apps\Chat\V1\GetMembershipRequest;
use Google\Apps\Chat\V1\GetMessageRequest;
use Google\Apps\Chat\V1\GetSpaceEventRequest;
use Google\Apps\Chat\V1\GetSpaceReadStateRequest;
use Google\Apps\Chat\V1\GetSpaceRequest;
use Google\Apps\Chat\V1\GetThreadReadStateRequest;
@@ -51,13 +52,16 @@
use Google\Apps\Chat\V1\ListMessagesResponse;
use Google\Apps\Chat\V1\ListReactionsRequest;
use Google\Apps\Chat\V1\ListReactionsResponse;
use Google\Apps\Chat\V1\ListSpaceEventsRequest;
use Google\Apps\Chat\V1\ListSpaceEventsResponse;
use Google\Apps\Chat\V1\ListSpacesRequest;
use Google\Apps\Chat\V1\ListSpacesResponse;
use Google\Apps\Chat\V1\Membership;
use Google\Apps\Chat\V1\Message;
use Google\Apps\Chat\V1\Reaction;
use Google\Apps\Chat\V1\SetUpSpaceRequest;
use Google\Apps\Chat\V1\Space;
use Google\Apps\Chat\V1\SpaceEvent;
use Google\Apps\Chat\V1\SpaceReadState;
use Google\Apps\Chat\V1\ThreadReadState;
use Google\Apps\Chat\V1\UpdateMembershipRequest;
@@ -1086,6 +1090,73 @@ public function getSpaceExceptionTest()
$this->assertTrue($transport->isExhausted());
}

/** @test */
public function getSpaceEventTest()
{
$transport = $this->createTransport();
$gapicClient = $this->createClient([
'transport' => $transport,
]);
$this->assertTrue($transport->isExhausted());
// Mock response
$name2 = 'name2-1052831874';
$eventType = 'eventType984376767';
$expectedResponse = new SpaceEvent();
$expectedResponse->setName($name2);
$expectedResponse->setEventType($eventType);
$transport->addResponse($expectedResponse);
// Mock request
$formattedName = $gapicClient->spaceEventName('[SPACE]', '[SPACE_EVENT]');
$request = (new GetSpaceEventRequest())->setName($formattedName);
$response = $gapicClient->getSpaceEvent($request);
$this->assertEquals($expectedResponse, $response);
$actualRequests = $transport->popReceivedCalls();
$this->assertSame(1, count($actualRequests));
$actualFuncCall = $actualRequests[0]->getFuncCall();
$actualRequestObject = $actualRequests[0]->getRequestObject();
$this->assertSame('/google.chat.v1.ChatService/GetSpaceEvent', $actualFuncCall);
$actualValue = $actualRequestObject->getName();
$this->assertProtobufEquals($formattedName, $actualValue);
$this->assertTrue($transport->isExhausted());
}

/** @test */
public function getSpaceEventExceptionTest()
{
$transport = $this->createTransport();
$gapicClient = $this->createClient([
'transport' => $transport,
]);
$this->assertTrue($transport->isExhausted());
$status = new stdClass();
$status->code = Code::DATA_LOSS;
$status->details = 'internal error';
$expectedExceptionMessage = json_encode(
[
'message' => 'internal error',
'code' => Code::DATA_LOSS,
'status' => 'DATA_LOSS',
'details' => [],
],
JSON_PRETTY_PRINT
);
$transport->addResponse(null, $status);
// Mock request
$formattedName = $gapicClient->spaceEventName('[SPACE]', '[SPACE_EVENT]');
$request = (new GetSpaceEventRequest())->setName($formattedName);
try {
$gapicClient->getSpaceEvent($request);
// If the $gapicClient method call did not throw, fail the test
$this->fail('Expected an ApiException, but no exception was thrown.');
} catch (ApiException $ex) {
$this->assertEquals($status->code, $ex->getCode());
$this->assertEquals($expectedExceptionMessage, $ex->getMessage());
}
// Call popReceivedCalls to ensure the stub is exhausted
$transport->popReceivedCalls();
$this->assertTrue($transport->isExhausted());
}

/** @test */
public function getSpaceReadStateTest()
{
@@ -1429,6 +1500,81 @@ public function listReactionsExceptionTest()
$this->assertTrue($transport->isExhausted());
}

/** @test */
public function listSpaceEventsTest()
{
$transport = $this->createTransport();
$gapicClient = $this->createClient([
'transport' => $transport,
]);
$this->assertTrue($transport->isExhausted());
// Mock response
$nextPageToken = '';
$spaceEventsElement = new SpaceEvent();
$spaceEvents = [$spaceEventsElement];
$expectedResponse = new ListSpaceEventsResponse();
$expectedResponse->setNextPageToken($nextPageToken);
$expectedResponse->setSpaceEvents($spaceEvents);
$transport->addResponse($expectedResponse);
// Mock request
$formattedParent = $gapicClient->spaceName('[SPACE]');
$filter = 'filter-1274492040';
$request = (new ListSpaceEventsRequest())->setParent($formattedParent)->setFilter($filter);
$response = $gapicClient->listSpaceEvents($request);
$this->assertEquals($expectedResponse, $response->getPage()->getResponseObject());
$resources = iterator_to_array($response->iterateAllElements());
$this->assertSame(1, count($resources));
$this->assertEquals($expectedResponse->getSpaceEvents()[0], $resources[0]);
$actualRequests = $transport->popReceivedCalls();
$this->assertSame(1, count($actualRequests));
$actualFuncCall = $actualRequests[0]->getFuncCall();
$actualRequestObject = $actualRequests[0]->getRequestObject();
$this->assertSame('/google.chat.v1.ChatService/ListSpaceEvents', $actualFuncCall);
$actualValue = $actualRequestObject->getParent();
$this->assertProtobufEquals($formattedParent, $actualValue);
$actualValue = $actualRequestObject->getFilter();
$this->assertProtobufEquals($filter, $actualValue);
$this->assertTrue($transport->isExhausted());
}

/** @test */
public function listSpaceEventsExceptionTest()
{
$transport = $this->createTransport();
$gapicClient = $this->createClient([
'transport' => $transport,
]);
$this->assertTrue($transport->isExhausted());
$status = new stdClass();
$status->code = Code::DATA_LOSS;
$status->details = 'internal error';
$expectedExceptionMessage = json_encode(
[
'message' => 'internal error',
'code' => Code::DATA_LOSS,
'status' => 'DATA_LOSS',
'details' => [],
],
JSON_PRETTY_PRINT
);
$transport->addResponse(null, $status);
// Mock request
$formattedParent = $gapicClient->spaceName('[SPACE]');
$filter = 'filter-1274492040';
$request = (new ListSpaceEventsRequest())->setParent($formattedParent)->setFilter($filter);
try {
$gapicClient->listSpaceEvents($request);
// If the $gapicClient method call did not throw, fail the test
$this->fail('Expected an ApiException, but no exception was thrown.');
} catch (ApiException $ex) {
$this->assertEquals($status->code, $ex->getCode());
$this->assertEquals($expectedExceptionMessage, $ex->getMessage());
}
// Call popReceivedCalls to ensure the stub is exhausted
$transport->popReceivedCalls();
$this->assertTrue($transport->isExhausted());
}

/** @test */
public function listSpacesTest()
{
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading