diff options
Diffstat (limited to 'matrix-specification/Requests')
11 files changed, 167 insertions, 21 deletions
diff --git a/matrix-specification/Requests/ClientAccountWhoamiGetRequest.php b/matrix-specification/Requests/ClientAccountWhoamiGetRequest.php new file mode 100644 index 0000000..50313bb --- /dev/null +++ b/matrix-specification/Requests/ClientAccountWhoamiGetRequest.php @@ -0,0 +1,27 @@ +<?php + +namespace Matrix\Requests; + +use Matrix\Enums\ApiPathVersion; +use Matrix\Request; + +class ClientAccountWhoamiGetRequest extends Request implements RateLimited, RequiresAuthentication +{ + public function __construct() + {} + + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/account/whoami"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array + { + return []; + } +} diff --git a/matrix-specification/Requests/ClientDirectoryRoomAliasGetRequest.php b/matrix-specification/Requests/ClientDirectoryRoomAliasGetRequest.php index 174a5c2..ea104a2 100644 --- a/matrix-specification/Requests/ClientDirectoryRoomAliasGetRequest.php +++ b/matrix-specification/Requests/ClientDirectoryRoomAliasGetRequest.php @@ -12,9 +12,9 @@ class ClientDirectoryRoomAliasGetRequest extends Request ) {} - public function getUri(string $serverName, ApiPathVersion $version): string + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string { - return "https://$serverName/_matrix/client/{$version}/directory/room/{$this->roomAlias}"; + return "{$scheme}://{$serverName}/_matrix/client/{$version}/directory/room/{$this->roomAlias}"; } public function getQueryParameters(): array diff --git a/matrix-specification/Requests/ClientKeysUploadPostRequest.php b/matrix-specification/Requests/ClientKeysUploadPostRequest.php index 40d9eae..05b2fde 100644 --- a/matrix-specification/Requests/ClientKeysUploadPostRequest.php +++ b/matrix-specification/Requests/ClientKeysUploadPostRequest.php @@ -4,8 +4,10 @@ namespace Matrix\Requests; use Matrix\Data\DeviceKeys; use Matrix\Data\KeyObject; +use Matrix\Enums\ApiPathVersion; +use Matrix\Request; -class ClientKeysUploadPostRequest implements RateLimited, RequiresAuthentication, \JsonSerializable +class ClientKeysUploadPostRequest extends Request implements RateLimited, RequiresAuthentication { /** * @param array<string, string|KeyObject> $fallbackKeys @@ -18,12 +20,22 @@ class ClientKeysUploadPostRequest implements RateLimited, RequiresAuthentication ) {} - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/keys/upload"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { return array_filter([ "device_keys" => $this->deviceKeys, "fallback_keys" => $this->fallbackKeys, "one_time_keys" => $this->oneTimeKeys, - ], "is_null"); + ], fn ($value) => ! is_null($value)); } } diff --git a/matrix-specification/Requests/ClientLoginPostRequest.php b/matrix-specification/Requests/ClientLoginPostRequest.php index 44497e7..161c6de 100644 --- a/matrix-specification/Requests/ClientLoginPostRequest.php +++ b/matrix-specification/Requests/ClientLoginPostRequest.php @@ -3,9 +3,11 @@ namespace Matrix\Requests; use Matrix\Data\UserIdentifier; +use Matrix\Enums\ApiPathVersion; use Matrix\Enums\LoginType; +use Matrix\Request; -class ClientLoginPostRequest implements RateLimited, \JsonSerializable +class ClientLoginPostRequest extends Request implements RateLimited { public function __construct( private LoginType $type, @@ -26,7 +28,17 @@ class ClientLoginPostRequest implements RateLimited, \JsonSerializable } } - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/login"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { $request = [ "device_id" => $this->deviceId, @@ -48,6 +60,6 @@ class ClientLoginPostRequest implements RateLimited, \JsonSerializable default => [], }; - return array_filter($request, "is_null"); + return array_filter($request, fn ($value) => ! is_null($value)); } } diff --git a/matrix-specification/Requests/ClientRefreshPostRequest.php b/matrix-specification/Requests/ClientRefreshPostRequest.php index 733ca75..3733945 100644 --- a/matrix-specification/Requests/ClientRefreshPostRequest.php +++ b/matrix-specification/Requests/ClientRefreshPostRequest.php @@ -2,14 +2,27 @@ namespace Matrix\Requests; -class ClientRefreshPostRequest implements RateLimited, \JsonSerializable +use Matrix\Enums\ApiPathVersion; +use Matrix\Request; + +class ClientRefreshPostRequest extends Request implements RateLimited { public function __construct( private string $refreshToken, ) {} - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/refresh"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { return [ "refresh_token" => $this->refreshToken, diff --git a/matrix-specification/Requests/ClientRegisterPostRequest.php b/matrix-specification/Requests/ClientRegisterPostRequest.php new file mode 100644 index 0000000..74c0c1d --- /dev/null +++ b/matrix-specification/Requests/ClientRegisterPostRequest.php @@ -0,0 +1,57 @@ +<?php + +namespace Matrix\Requests; + +use Matrix\Data\AuthenticationData; +use Matrix\Enums\ApiPathVersion; +use Matrix\Enums\UserRegistrationKind; +use Matrix\Request; + +/** + * @see https://spec.matrix.org/v1.16/client-server-api/#post_matrixclientv3register + */ +class ClientRegisterPostRequest extends Request implements RateLimited +{ + public function __construct( + private AuthenticationData $authenticationData, + private string $password, + private ?UserRegistrationKind $kind = null, + private ?string $deviceId = null, + private ?bool $inhibitLogin = null, + private ?string $initialDeviceDisplayName = null, + private ?string $username = null, + private ?bool $refreshToken = null, + ) + {} + + public function setDefaults(): void + { + $this->kind ??= UserRegistrationKind::USER; + $this->inhibitLogin ??= false; + } + + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/register"; + } + + public function getQueryParameters(): array + { + return array_filter([ + "kind" => $this->kind, + ], fn ($value) => ! is_null($value)); + } + + public function getBody(): array + { + return array_filter([ + "auth" => $this->authenticationData, + "device_id" => $this->deviceId, + "inhibit_login" => $this->inhibitLogin, + "initial_device_display_name" => $this->initialDeviceDisplayName, + "password" => $this->password, + "refresh_token" => $this->refreshToken, + "username" => $this->username, + ], fn ($value) => ! is_null($value)); + } +} diff --git a/matrix-specification/Requests/ClientSyncGetRequest.php b/matrix-specification/Requests/ClientSyncGetRequest.php index 2ab7d9e..f19e820 100644 --- a/matrix-specification/Requests/ClientSyncGetRequest.php +++ b/matrix-specification/Requests/ClientSyncGetRequest.php @@ -2,9 +2,11 @@ namespace Matrix\Requests; +use Matrix\Enums\ApiPathVersion; use Matrix\Enums\PresenceState; +use Matrix\Request; -class ClientSyncGetRequest implements RequiresAuthentication +class ClientSyncGetRequest extends Request implements RequiresAuthentication { public function __construct( private ?string $filter = null, @@ -24,6 +26,11 @@ class ClientSyncGetRequest implements RequiresAuthentication $this->useStateAfter ??= false; } + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/sync"; + } + public function getQueryParameters(): array { return array_filter([ @@ -33,6 +40,11 @@ class ClientSyncGetRequest implements RequiresAuthentication "since" => $this->since, "timeout" => $this->timeout, "use_state_after" => $this->useStateAfter, - ], "is_null"); + ], fn ($value) => ! is_null($value)); + } + + public function getBody(): array + { + return []; } } diff --git a/matrix-specification/Requests/ClientUserIdFilterPostRequest.php b/matrix-specification/Requests/ClientUserIdFilterPostRequest.php index 2edc4c5..cd01532 100644 --- a/matrix-specification/Requests/ClientUserIdFilterPostRequest.php +++ b/matrix-specification/Requests/ClientUserIdFilterPostRequest.php @@ -4,9 +4,10 @@ namespace Matrix\Requests; use Matrix\Data\Filters\EventFilter; use Matrix\Data\Filters\RoomFilter; +use Matrix\Enums\ApiPathVersion; +use Matrix\Request; - # ClientUserUserIdFilterPostRequest? -class ClientUserIdFilterPostRequest implements RequiresAuthentication, \JsonSerializable +class ClientUserIdFilterPostRequest extends Request implements RequiresAuthentication { /** * @param string[] $eventFields @@ -21,7 +22,17 @@ class ClientUserIdFilterPostRequest implements RequiresAuthentication, \JsonSeri ) {} - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/user/{$this->userId}/filter"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { return [ "account_data" => $this->accountData, diff --git a/matrix-specification/Requests/RateLimited.php b/matrix-specification/Requests/RateLimited.php index 9f917a4..a75054f 100644 --- a/matrix-specification/Requests/RateLimited.php +++ b/matrix-specification/Requests/RateLimited.php @@ -3,6 +3,4 @@ namespace Matrix\Requests; interface RateLimited -{ - # TODO -} +{} diff --git a/matrix-specification/Requests/RequiresAuthentication.php b/matrix-specification/Requests/RequiresAuthentication.php index a762405..cc4b3e6 100644 --- a/matrix-specification/Requests/RequiresAuthentication.php +++ b/matrix-specification/Requests/RequiresAuthentication.php @@ -3,6 +3,4 @@ namespace Matrix\Requests; interface RequiresAuthentication -{ - //public function authenticateUser(): bool; -} +{} diff --git a/matrix-specification/Requests/RequiresAuthenticationOptional.php b/matrix-specification/Requests/RequiresAuthenticationOptional.php new file mode 100644 index 0000000..2ff7980 --- /dev/null +++ b/matrix-specification/Requests/RequiresAuthenticationOptional.php @@ -0,0 +1,6 @@ +<?php + +namespace Matrix\Requests; + +interface RequiresAuthenticationOptional +{} |
