Initialised composer, started prototyping.

master
conky 2022-10-12 23:37:30 +03:00
commit 4bfc4ccdaf
5 changed files with 113 additions and 0 deletions

3
.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
.idea
vendor/
composer.lock

27
composer.json 100644
View File

@ -0,0 +1,27 @@
{
"name": "toloka/php-api",
"description": "PHP library to integrate with Hurtom Toloka using web scrapping.",
"type": "library",
"homepage": "http://git.devbones.com/Toloka/php-api",
"require": {
"php": ">=7.4",
"psr/simple-cache": "^3.0",
"psr/log": "^3.0",
"psr/http-client": "^1.0"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Toloka\\PhpApi\\": "src/"
}
},
"authors": [
{
"name": "conky",
"email": "bogdan@devbones.com"
}
],
"require-dev": {
"guzzlehttp/guzzle": "^7.5"
}
}

54
src/Client.php 100644
View File

@ -0,0 +1,54 @@
<?php
namespace Toloka\PhpApi;
use Psr\Http\Client\ClientInterface as HttpClientInterface;
use Psr\Log\LoggerInterface;
use Psr\SimpleCache\CacheInterface;
class Client {
/**
* Hurtom Toloka base url.
*
* @var string
*/
protected string $base_url;
protected HttpClientInterface $httpClient;
/**
* Cache bin.
*
* @var CacheInterface
*/
protected CacheInterface $cache;
/**
* Events logger.
*
* @var LoggerInterface
*/
protected LoggerInterface $logger;
/**
* Toloka client constructor.
*
* @param string $base_url
* @param CacheInterface|NULL $cache
* @param LoggerInterface|NULL $logger
*/
public function __construct(
string $base_url = 'https://toloka.to',
HttpClientInterface $httpClient,
CacheInterface $cache,
LoggerInterface $logger
) {
$this->httpClient = $httpClient;
$this->cache = $cache;
$this->logger = $logger;
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Toloka\PhpApi;
interface ClientInterface {
/**
* Login using credentials.
*
* @param string $login
*
* @param string $password
*
* @throws InvalidAuthCredentials
*
* @return void
*/
public function login(string $login, string $password): void;
}

View File

@ -0,0 +1,9 @@
<?php
namespace Toloka\PhpApi;
class InvalidAuthCredentials extends \Exception {
protected $message = 'Failed to login using given credentials.';
}