Prototyped several interfaces, added basic topics stuff and exception.
parent
4bfc4ccdaf
commit
f3d397404f
|
@ -0,0 +1,3 @@
|
|||
# Hurtom Toloka PHP-API library
|
||||
|
||||
This library uses web-scrapping method to work with web resource.
|
|
@ -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.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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.';
|
||||
|
||||
}
|
|
@ -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.';
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Toloka\PhpApi\Exception;
|
||||
|
||||
abstract class AuthException extends \Exception {}
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Toloka\PhpApi;
|
||||
|
||||
class InvalidAuthCredentials extends \Exception {
|
||||
|
||||
protected $message = 'Failed to login using given credentials.';
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Toloka\PhpApi\Topic;
|
||||
|
||||
use Toloka\PhpApi\TopicBase;
|
||||
|
||||
class Movie extends TopicBase {
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Toloka\PhpApi;
|
||||
|
||||
abstract class TopicBase implements TopicInterface {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Toloka\PhpApi;
|
||||
|
||||
interface TopicInterface {
|
||||
|
||||
public function id(): int;
|
||||
|
||||
public function url(bool $absolute = TRUE): string;
|
||||
|
||||
}
|
Loading…
Reference in New Issue