From f3d397404fb10248a53e59b93aa6b220cbc58e5d Mon Sep 17 00:00:00 2001 From: conky Date: Thu, 13 Oct 2022 20:18:48 +0300 Subject: [PATCH] Prototyped several interfaces, added basic topics stuff and exception. --- README.md | 3 ++ src/Client.php | 34 ++++++++++++++++++- src/ClientInterface.php | 34 ++++++++++++++++--- src/Exception/Auth/InvalidAuthCredentials.php | 11 ++++++ src/Exception/Auth/TooManyLoginAttempts.php | 11 ++++++ src/Exception/AuthException.php | 5 +++ src/Exceptions/InvalidAuthCredentials.php | 9 ----- src/Topic/Movie.php | 9 +++++ src/Topic/TopicBase.php | 9 +++++ src/TopicInterface.php | 11 ++++++ 10 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 README.md create mode 100644 src/Exception/Auth/InvalidAuthCredentials.php create mode 100644 src/Exception/Auth/TooManyLoginAttempts.php create mode 100644 src/Exception/AuthException.php delete mode 100644 src/Exceptions/InvalidAuthCredentials.php create mode 100644 src/Topic/Movie.php create mode 100644 src/Topic/TopicBase.php create mode 100644 src/TopicInterface.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ca048b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Hurtom Toloka PHP-API library + +This library uses web-scrapping method to work with web resource. \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index ee9197a..32d940d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -6,7 +6,7 @@ use Psr\Http\Client\ClientInterface as HttpClientInterface; use Psr\Log\LoggerInterface; use Psr\SimpleCache\CacheInterface; -class Client { +class Client implements ClientInterface { /** * Hurtom Toloka base url. @@ -15,6 +15,11 @@ class Client { */ protected string $base_url; + /** + * Http client. + * + * @var HttpClientInterface + */ protected HttpClientInterface $httpClient; /** @@ -49,6 +54,33 @@ class Client { $this->logger = $logger; } + /** + * {@inheritDoc} + */ + public function login(string $login, string $password): void { + // TODO: Implement login() method. + } + + /** + * {@inheritDoc} + */ + public function isLoggedIn(): bool { + // TODO: Implement isLoggedIn() method. + } + + /** + * {@inheritDoc} + */ + public function logout(): void { + // TODO: Implement logout() method. + } + + /** + * {@inheritDoc} + */ + public function getTopic(int $id): TopicInterface { + // TODO: Implement getTopic() method. + } } diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 9e6bbc2..7b383f8 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -8,13 +8,39 @@ interface ClientInterface { * Login using credentials. * * @param string $login - * + * User login. * @param string $password + * User password. * - * @throws InvalidAuthCredentials - * - * @return void + * @throws \Toloka\PhpApi\Exception\Auth\InvalidAuthCredentials + * @throws \Toloka\PhpApi\Exception\Auth\TooManyLoginAttempts + * @throws \Psr\Http\Client\ClientExceptionInterface */ public function login(string $login, string $password): void; + /** + * Check if user logged in. + * + * @return bool + */ + public function isLoggedIn(): bool; + + /** + * Perform user's logout. + * + * @throws \Psr\Http\Client\ClientExceptionInterface + */ + public function logout(): void; + + /** + * Get topic by ID. + * + * @param int $id + * Integer serial number of topic. + * + * @return TopicInterface + * Object with populated topic data. + */ + public function getTopic(int $id): TopicInterface; + } diff --git a/src/Exception/Auth/InvalidAuthCredentials.php b/src/Exception/Auth/InvalidAuthCredentials.php new file mode 100644 index 0000000..43242e1 --- /dev/null +++ b/src/Exception/Auth/InvalidAuthCredentials.php @@ -0,0 +1,11 @@ +