Spaces:
No application file
No application file
File size: 1,659 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
<?php
namespace Mautic\CoreBundle\IpLookup;
use GuzzleHttp\Exception\GuzzleException;
abstract class AbstractRemoteDataLookup extends AbstractLookup
{
/**
* Method to use when communicating with the service.
*
* @var string
*/
protected $method = 'get';
/**
* Get the URL to fetch data from.
*
* @return mixed
*/
abstract protected function getUrl();
/**
* @return mixed
*/
abstract protected function parseResponse($response);
/**
* @return array
*/
protected function getHeaders()
{
return [];
}
/**
* @return array
*/
protected function getParameters()
{
return [];
}
/**
* Fetch data from lookup service.
*/
protected function lookup()
{
$url = $this->getUrl();
try {
$response = ('post' == $this->method) ?
$this->client->post($url, [
\GuzzleHttp\RequestOptions::BODY => $this->getParameters(),
\GuzzleHttp\RequestOptions::HEADERS => $this->getHeaders(),
\GuzzleHttp\RequestOptions::TIMEOUT => 10,
]) :
$this->client->get($url, [
\GuzzleHttp\RequestOptions::HEADERS => $this->getHeaders(),
\GuzzleHttp\RequestOptions::TIMEOUT => 10,
]);
$this->parseResponse($response->getBody());
} catch (GuzzleException $exception) {
if ($this->logger) {
$this->logger->warning('IP LOOKUP: '.$exception->getMessage());
}
}
}
}
|