Move to Amp/HttpClient from Amp/Artax
This commit is contained in:
parent
eb12f57e7d
commit
37c3d6ecf0
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@ -12,7 +12,7 @@ pipeline {
|
||||
sh 'apk add --no-cache php7-phpdbg php7-xsl php7-gd php7-json php7-pdo'
|
||||
sh 'curl -sS https://getcomposer.org/installer | php'
|
||||
sh 'rm -f composer.lock'
|
||||
sh 'php composer.phar install'
|
||||
sh 'php composer.phar install --ignore-platform-reqs'
|
||||
sh 'php vendor/bin/robo lint'
|
||||
sh 'php ./vendor/bin/phpunit --colors=never'
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"amphp/artax": "^3.0",
|
||||
"amphp/http-client": "^4.2",
|
||||
"aura/html": "^2.0",
|
||||
"aura/router": "^3.0",
|
||||
"aura/session": "^2.0",
|
||||
@ -28,13 +28,13 @@
|
||||
"ext-json": "*",
|
||||
"ext-gd":"*",
|
||||
"ext-pdo": "*",
|
||||
"laminas/laminas-diactoros": "^2.0.0",
|
||||
"maximebf/consolekit": "^1.0",
|
||||
"monolog/monolog": "^2.0.1",
|
||||
"php": "^7.3",
|
||||
"psr/http-message": "~1.0",
|
||||
"psr/log": "~1.0",
|
||||
"yosymfony/toml": "^1.0",
|
||||
"zendframework/zend-diactoros": "^2.0.0"
|
||||
"yosymfony/toml": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"consolidation/robo": "^2.0.0",
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -22,13 +22,14 @@ use function Amp\Promise\wait;
|
||||
use function Aviat\AnimeClient\getResponse;
|
||||
|
||||
use Amp;
|
||||
use Amp\Artax\{FormBody, Request};
|
||||
use Amp\Http\Client\Request;
|
||||
use Amp\Http\Client\Body\FormBody;
|
||||
use Aviat\Ion\Json;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Log\LoggerAwareTrait;
|
||||
|
||||
/**
|
||||
* Wrapper around Artax to make it easier to build API requests
|
||||
* Wrapper around Http\Client to make it easier to build API requests
|
||||
*/
|
||||
abstract class APIRequestBuilder {
|
||||
use LoggerAwareTrait;
|
||||
@ -78,7 +79,7 @@ abstract class APIRequestBuilder {
|
||||
public static function simpleRequest(string $uri): Request
|
||||
{
|
||||
return (new Request($uri))
|
||||
->withHeader('User-Agent', USER_AGENT);
|
||||
->setHeader('User-Agent', USER_AGENT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +119,7 @@ abstract class APIRequestBuilder {
|
||||
*/
|
||||
public function setBody($body): self
|
||||
{
|
||||
$this->request = $this->request->withBody($body);
|
||||
$this->request->setBody($body);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -145,7 +146,7 @@ abstract class APIRequestBuilder {
|
||||
*/
|
||||
public function unsetHeader(string $name): self
|
||||
{
|
||||
$this->request = $this->request->withoutHeader($name);
|
||||
$this->request->removeHeader($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -164,7 +165,7 @@ abstract class APIRequestBuilder {
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->request = $this->request->withHeader($name, $value);
|
||||
$this->request->setHeader($name, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -254,7 +255,7 @@ abstract class APIRequestBuilder {
|
||||
public function getResponseData(Request $request)
|
||||
{
|
||||
$response = getResponse($request);
|
||||
return wait($response->getBody());
|
||||
return wait($response->getBody()->buffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,7 +307,7 @@ abstract class APIRequestBuilder {
|
||||
$url .= '?' . $this->query;
|
||||
}
|
||||
|
||||
$this->request = $this->request->withUri($url);
|
||||
$this->request->setUri($url);
|
||||
|
||||
return $this->request;
|
||||
}
|
||||
@ -324,7 +325,8 @@ abstract class APIRequestBuilder {
|
||||
|
||||
$this->path = '';
|
||||
$this->query = '';
|
||||
$this->request = (new Request($requestUrl))
|
||||
->withMethod($type);
|
||||
$this->request = new Request($requestUrl, $type);
|
||||
$this->request->setTcpConnectTimeout(300000);
|
||||
$this->request->setTransferTimeout(300000);
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Http\Client\Request;
|
||||
use Aviat\AnimeClient\Types\FormItemData;
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -21,8 +21,8 @@ use const Aviat\AnimeClient\USER_AGENT;
|
||||
use function Amp\Promise\wait;
|
||||
use function Aviat\AnimeClient\getResponse;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Artax\Response;
|
||||
use Amp\Http\Client\Request;
|
||||
use Amp\Http\Client\Response;
|
||||
|
||||
use Aviat\AnimeClient\API\Anilist;
|
||||
use Aviat\Ion\Json;
|
||||
@ -194,7 +194,7 @@ trait AnilistTrait {
|
||||
$request = $this->mutateRequest($name, $variables);
|
||||
$response = $this->getResponseFromRequest($request);
|
||||
|
||||
return Json::decode(wait($response->getBody()));
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,8 +286,8 @@ trait AnilistTrait {
|
||||
}
|
||||
}
|
||||
|
||||
// dump(wait($response->getBody()));
|
||||
// dump(wait($response->getBody()->buffer()));
|
||||
|
||||
return Json::decode(wait($response->getBody()));
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API\Anilist;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Http\Client\Request;
|
||||
|
||||
use Aviat\AnimeClient\API\AbstractListItem;
|
||||
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Anilist as AnilistStatus;
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -20,7 +20,7 @@ use function Amp\Promise\wait;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Http\Client\Request;
|
||||
use Aviat\AnimeClient\API\Anilist;
|
||||
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
|
||||
use Aviat\AnimeClient\Types\FormItem;
|
||||
@ -79,7 +79,7 @@ final class Model
|
||||
|
||||
$response = $this->getResponseFromRequest($request);
|
||||
|
||||
return Json::decode(wait($response->getBody()));
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,7 +276,7 @@ final class Model
|
||||
* this way is more accurate than getting the list item id
|
||||
* directly from the MAL id
|
||||
*/
|
||||
private function getListIdFromMediaId(string $mediaId): ?string
|
||||
private function getListIdFromMediaId(string $mediaId): string
|
||||
{
|
||||
$config = $this->container->get('config');
|
||||
$anilistUser = $config->get(['anilist', 'username']);
|
||||
@ -286,9 +286,7 @@ final class Model
|
||||
'userName' => $anilistUser,
|
||||
]);
|
||||
|
||||
$data = $info['data']['MediaList'];
|
||||
|
||||
return ($data !== NULL) ? (string)$data['id'] : NULL;
|
||||
return (string)$info['data']['MediaList']['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -21,8 +21,8 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
|
||||
use function Amp\Promise\wait;
|
||||
use function Aviat\AnimeClient\getResponse;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Artax\Response;
|
||||
use Amp\Http\Client\Request;
|
||||
use Amp\Http\Client\Response;
|
||||
use Aviat\AnimeClient\API\{
|
||||
FailedResponseException,
|
||||
Kitsu as K
|
||||
@ -181,7 +181,7 @@ trait KitsuTrait {
|
||||
|
||||
try
|
||||
{
|
||||
return Json::decode(wait($response->getBody()));
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
}
|
||||
catch (JsonException $e)
|
||||
{
|
||||
@ -241,7 +241,7 @@ trait KitsuTrait {
|
||||
}
|
||||
}
|
||||
|
||||
return JSON::decode(wait($response->getBody()), TRUE);
|
||||
return JSON::decode(wait($response->getBody()->buffer()), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -23,7 +23,7 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
|
||||
use function Amp\Promise\wait;
|
||||
use function Aviat\AnimeClient\getResponse;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Http\Client\Request;
|
||||
use Aviat\AnimeClient\API\AbstractListItem;
|
||||
use Aviat\AnimeClient\Types\FormItemData;
|
||||
use Aviat\Ion\Di\ContainerAware;
|
||||
@ -126,7 +126,7 @@ final class ListItem extends AbstractListItem {
|
||||
|
||||
$request = $request->getFullRequest();
|
||||
$response = getResponse($request);
|
||||
return Json::decode(wait($response->getBody()));
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
}
|
||||
|
||||
public function increment(string $id, FormItemData $data): Request
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -18,7 +18,7 @@ namespace Aviat\AnimeClient\API\Kitsu;
|
||||
|
||||
use function Amp\Promise\wait;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Http\Client\Request;
|
||||
use Aviat\AnimeClient\API\{
|
||||
CacheTrait,
|
||||
JsonAPI,
|
||||
@ -126,7 +126,7 @@ final class Model {
|
||||
'password' => $password
|
||||
]
|
||||
]);
|
||||
$data = Json::decode(wait($response->getBody()));
|
||||
$data = Json::decode(wait($response->getBody()->buffer()));
|
||||
|
||||
if (array_key_exists('error', $data))
|
||||
{
|
||||
@ -163,7 +163,7 @@ final class Model {
|
||||
]
|
||||
]);
|
||||
|
||||
$data = Json::decode(wait($response->getBody()));
|
||||
$data = Json::decode(wait($response->getBody()->buffer()));
|
||||
|
||||
if (array_key_exists('access_token', $data))
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API;
|
||||
|
||||
use Amp\Artax\Request;
|
||||
use Amp\Http\Client\Request;
|
||||
use function Amp\call;
|
||||
use function Amp\Promise\{all, wait};
|
||||
use function Aviat\AnimeClient\getApiClient;
|
||||
@ -82,7 +82,7 @@ final class ParallelAPIRequest {
|
||||
{
|
||||
$promises[$key] = call(static function () use ($client, $url) {
|
||||
$response = yield $client->request($url);
|
||||
return yield $response->getBody();
|
||||
return yield $response->getBody()->buffer();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -18,7 +18,9 @@ namespace Aviat\AnimeClient;
|
||||
|
||||
use function Amp\Promise\wait;
|
||||
|
||||
use Amp\Artax\{Client, DefaultClient, Response};
|
||||
use Amp\Http\Client\Response;
|
||||
use Amp\Http\Client\HttpClient;
|
||||
use Amp\Http\Client\HttpClientBuilder;
|
||||
|
||||
use Aviat\Ion\ConfigInterface;
|
||||
use Yosymfony\Toml\{Toml, TomlBuilder};
|
||||
@ -218,15 +220,14 @@ function getApiClient ()
|
||||
|
||||
if ($client === NULL)
|
||||
{
|
||||
$client = new DefaultClient;
|
||||
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
|
||||
$client = HttpClientBuilder::buildDefault();
|
||||
}
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplify making a request with Artax
|
||||
* Simplify making a request with Http\Client
|
||||
*
|
||||
* @param $request
|
||||
* @return Response
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7.3
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
@ -130,7 +130,7 @@ final class Images extends BaseController {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = wait($response->getBody());
|
||||
$data = wait($response->getBody()->buffer());
|
||||
|
||||
[$origWidth] = getimagesizefromstring($data);
|
||||
$gdImg = imagecreatefromstring($data);
|
||||
|
Loading…
Reference in New Issue
Block a user