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 @@ +<?php + +namespace Toloka\PhpApi\Exception\Auth; + +use Toloka\PhpApi\Exception\AuthException; + +class InvalidAuthCredentials extends AuthException { + + protected $message = 'Failed to login using given credentials.'; + +} diff --git a/src/Exception/Auth/TooManyLoginAttempts.php b/src/Exception/Auth/TooManyLoginAttempts.php new file mode 100644 index 0000000..3a0a748 --- /dev/null +++ b/src/Exception/Auth/TooManyLoginAttempts.php @@ -0,0 +1,11 @@ +<?php + +namespace Toloka\PhpApi\Exception\Auth; + +use Toloka\PhpApi\Exception\AuthException; + +class TooManyLoginAttempts extends AuthException { + + protected $message = 'Too many login attempts performed. Try again later.'; + +} diff --git a/src/Exception/AuthException.php b/src/Exception/AuthException.php new file mode 100644 index 0000000..b34e69a --- /dev/null +++ b/src/Exception/AuthException.php @@ -0,0 +1,5 @@ +<?php + +namespace Toloka\PhpApi\Exception; + +abstract class AuthException extends \Exception {} diff --git a/src/Exceptions/InvalidAuthCredentials.php b/src/Exceptions/InvalidAuthCredentials.php deleted file mode 100644 index 5fda184..0000000 --- a/src/Exceptions/InvalidAuthCredentials.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -namespace Toloka\PhpApi; - -class InvalidAuthCredentials extends \Exception { - - protected $message = 'Failed to login using given credentials.'; - -} diff --git a/src/Topic/Movie.php b/src/Topic/Movie.php new file mode 100644 index 0000000..33ce712 --- /dev/null +++ b/src/Topic/Movie.php @@ -0,0 +1,9 @@ +<?php + +namespace Toloka\PhpApi\Topic; + +use Toloka\PhpApi\TopicBase; + +class Movie extends TopicBase { + +} diff --git a/src/Topic/TopicBase.php b/src/Topic/TopicBase.php new file mode 100644 index 0000000..1424607 --- /dev/null +++ b/src/Topic/TopicBase.php @@ -0,0 +1,9 @@ +<?php + +namespace Toloka\PhpApi; + +abstract class TopicBase implements TopicInterface { + + + +} diff --git a/src/TopicInterface.php b/src/TopicInterface.php new file mode 100644 index 0000000..c121cb5 --- /dev/null +++ b/src/TopicInterface.php @@ -0,0 +1,11 @@ +<?php + +namespace Toloka\PhpApi; + +interface TopicInterface { + + public function id(): int; + + public function url(bool $absolute = TRUE): string; + +}