Skip to content

Commit

Permalink
Patch Extensions to Event (#20)
Browse files Browse the repository at this point in the history
* add ability to patch extensions to an event

* ignore phpstan for request conf
  • Loading branch information
frets1700 authored Mar 14, 2024
1 parent 360d65f commit 81f118b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
use Microsoft\Graph\Generated\Models\EventType;
use Microsoft\Graph\Generated\Models\ODataErrors\MainError;
use Microsoft\Graph\Generated\Models\ODataErrors\ODataError;
use Microsoft\Graph\Generated\Models\OpenTypeExtension;
use Microsoft\Graph\Generated\Users\Item\CalendarView\Delta\DeltaGetResponse;
use Microsoft\Graph\Generated\Users\Item\Events\EventsRequestBuilderPostRequestConfiguration;
use Microsoft\Graph\Generated\Users\Item\Events\Item\EventItemRequestBuilderDeleteRequestConfiguration;
use Microsoft\Graph\Generated\Users\Item\Events\Item\EventItemRequestBuilderGetQueryParameters;
use Microsoft\Graph\Generated\Users\Item\Events\Item\EventItemRequestBuilderPatchRequestConfiguration;
use Microsoft\Graph\Generated\Users\Item\Events\Item\Extensions\ExtensionsRequestBuilderPostRequestConfiguration;
use Microsoft\Graph\Generated\Users\Item\Events\Item\Instances\InstancesRequestBuilderGetQueryParameters;
use Microsoft\Kiota\Abstractions\RequestAdapter;
use Microsoft\Kiota\Serialization\Json\JsonParseNode;
Expand Down Expand Up @@ -336,6 +338,36 @@ public function delete(string $id, array $args = []): void
->wait();
}

/**
* @param OpenTypeExtension $extension
* @param string $id
* @param array<string, mixed> $args
* @return bool
* @throws \Exception
*/
public function patchExtensionForEvent(string $id, OpenTypeExtension $extension, array $args = []): bool
{
$headers = $args['headers'] ?? [];
$options = $args['options'] ?? [];
$requestConfiguration = new ExtensionsRequestBuilderPostRequestConfiguration($headers, $options);
$requestConfiguration = $this->generateRequestConfiguration(
$requestConfiguration,
$headers,
$options
);

$extension = $this->graphService
->client($args)
->me()
->events()
->byEventId($id)
->extensions()
->post($extension, $requestConfiguration) // @phpstan-ignore-line
->wait();

return $extension instanceof OpenTypeExtension;
}

/**
* @param array<string, ?string> $correlationIds
*/
Expand Down
3 changes: 2 additions & 1 deletion src/RequestConfigurationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Microsoft\Graph\Generated\Users\Item\Events\Item\EventItemRequestBuilderGetQueryParameters;
use Microsoft\Graph\Generated\Users\Item\Events\Item\EventItemRequestBuilderGetRequestConfiguration;
use Microsoft\Graph\Generated\Users\Item\Events\Item\EventItemRequestBuilderPatchRequestConfiguration;
use Microsoft\Graph\Generated\Users\Item\Events\Item\Extensions\ExtensionsRequestBuilderPostRequestConfiguration;
use Microsoft\Graph\Generated\Users\Item\Events\Item\Instances\InstancesRequestBuilderGetQueryParameters;
use Microsoft\Graph\Generated\Users\Item\Events\Item\Instances\InstancesRequestBuilderGetRequestConfiguration;
use Symplicity\Outlook\Interfaces\Utilities\CalendarView\CalendarViewParamsInterface;
Expand Down Expand Up @@ -130,7 +131,7 @@ protected function getCalendarViewRequestConfiguration(CalendarViewParamsInterfa
* @param array<string, string> $headers
* @param RequestOptions[] | null $options
*/
private function generateRequestConfiguration(InstancesRequestBuilderGetRequestConfiguration | EventsRequestBuilderPostRequestConfiguration | EventItemRequestBuilderPatchRequestConfiguration | BatchRequestBuilderPostRequestConfiguration | EventItemRequestBuilderDeleteRequestConfiguration $configuration, array $headers = [], array $options = []): InstancesRequestBuilderGetRequestConfiguration | EventsRequestBuilderPostRequestConfiguration | EventItemRequestBuilderPatchRequestConfiguration | BatchRequestBuilderPostRequestConfiguration | EventItemRequestBuilderDeleteRequestConfiguration
private function generateRequestConfiguration(InstancesRequestBuilderGetRequestConfiguration | EventsRequestBuilderPostRequestConfiguration | EventItemRequestBuilderPatchRequestConfiguration | BatchRequestBuilderPostRequestConfiguration | EventItemRequestBuilderDeleteRequestConfiguration | ExtensionsRequestBuilderPostRequestConfiguration $configuration, array $headers = [], array $options = []): InstancesRequestBuilderGetRequestConfiguration | EventsRequestBuilderPostRequestConfiguration | EventItemRequestBuilderPatchRequestConfiguration | BatchRequestBuilderPostRequestConfiguration | EventItemRequestBuilderDeleteRequestConfiguration | ExtensionsRequestBuilderPostRequestConfiguration
{
$configuration->headers = array_merge(
$headers,
Expand Down
24 changes: 24 additions & 0 deletions tests/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use GuzzleHttp\Psr7\Utils;
use Microsoft\Graph\Generated\Models\DateTimeTimeZone;
use Microsoft\Graph\Generated\Models\Event as MsEvent;
use Microsoft\Graph\Generated\Models\OpenTypeExtension;
use Microsoft\Graph\Generated\Users\Item\Events\Item\EventItemRequestBuilderGetQueryParameters;
use Monolog\Handler\NullHandler;
use Monolog\Logger;
Expand Down Expand Up @@ -243,6 +244,29 @@ public function testPushEvents()
$this->stub->push(args: ['client' => $client]);
}

public function testPatchExtension()
{
$jsonBody = '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users(\'foo\')/events(\'abc==\')/extensions/$entity","@odata.type":"#microsoft.graph.openTypeExtension","id":"Microsoft.OutlookServices.OpenTypeExtension.foo.bar","extensionName":"foo.bar","internalId":"123"}';

$stream = Utils::streamFor($jsonBody);

$mock = new MockHandler([
new Response(201, ['Content-Type' => 'application/json'], $stream),
]);

$container = [];
$client = self::getClientWithTransactionHandler($container, $mock);

$extension = new OpenTypeExtension();
$extension->setExtensionName('foo.bar');
$extension->setAdditionalData([
'id' => 'foo'
]);

$actual = $this->stub->patchExtensionForEvent('abc==', $extension, ['client' => $client]);
$this->assertTrue($actual);
}

protected function getEvents(): array
{
return [
Expand Down

0 comments on commit 81f118b

Please sign in to comment.