**Fixed**
- clear method is broken in 0.9.5.
This commit is contained in:
kristuff 2021-01-08 19:12:48 +01:00
commit cd48341f1b

View file

@ -164,14 +164,14 @@ class ApiHandler extends ApiDefintion
$cats = $this->validateReportCategories($categories); $cats = $this->validateReportCategories($categories);
$msg = $this->cleanMessage($message); $msg = $this->cleanMessage($message);
// report AbuseIPDB request // AbuseIPDB request
$response = $this->apiRequest( $response = $this->apiRequest(
'report', [ 'report', [
'ip' => $ip, 'ip' => $ip,
'categories' => $cats, 'categories' => $cats,
'comment' => $msg 'comment' => $msg
], ],
'POST', $returnArray 'POST'
); );
return json_decode($response, $returnArray); return json_decode($response, $returnArray);
@ -238,43 +238,7 @@ class ApiHandler extends ApiDefintion
'maxAgeInDays' => $maxAge, 'maxAgeInDays' => $maxAge,
]; ];
$response = $this->apiRequest('check-block', $data, 'GET', $returnArray) ; $response = $this->apiRequest('check-block', $data, 'GET') ;
return json_decode($response, $returnArray);
}
/**
* Perform a 'clear-address' api request
*
* Sample response:
*
* {
* "data": {
* "numReportsDeleted": 0
* }
* }
*
*
* @access public
* @param string $ip The ip to check
* @param bool $returnArray True to return an indexed array instead of object. Default is false.
*
* @return object|array
* @throws \InvalidArgumentException When ip value was not set.
*/
public function clear(string $ip = null, bool $returnArray = false)
{
// ip must be set
if (empty($ip)){
throw new \InvalidArgumentException('ip argument must be set (null given)');
}
// minimal data
$data = [
'ipAddress' => $ip,
];
$response = $this->apiRequest('clear-address', $data, 'DELETE', $returnArray) ;
return json_decode($response, $returnArray); return json_decode($response, $returnArray);
} }
@ -314,11 +278,46 @@ class ApiHandler extends ApiDefintion
$data['verbose'] = true; $data['verbose'] = true;
} }
$response = $this->apiRequest('check', $data, 'GET', $returnArray) ; $response = $this->apiRequest('check', $data, 'GET') ;
return json_decode($response, $returnArray); return json_decode($response, $returnArray);
} }
/**
* Perform a 'clear-address' api request
*
* Sample response:
*
* {
* "data": {
* "numReportsDeleted": 0
* }
* }
*
*
* @access public
* @param string $ip The ip to check
* @param bool $returnArray True to return an indexed array instead of object. Default is false.
*
* @return object|array
* @throws \InvalidArgumentException When ip value was not set.
*/
public function clear(string $ip = null, bool $returnArray = false)
{
// ip must be set
if (empty($ip)){
throw new \InvalidArgumentException('ip argument must be set (null given)');
}
// minimal data
$data = [
'ipAddress' => $ip,
];
$response = $this->apiRequest('clear-address', $data, "DELETE") ;
return json_decode($response, $returnArray);
}
/** /**
* Perform a 'blacklist' api request * Perform a 'blacklist' api request
* *
@ -430,7 +429,7 @@ class ApiHandler extends ApiDefintion
* *
* @return mixed * @return mixed
*/ */
protected function apiRequest(string $path, array $data, string $method = 'GET', bool $returnArray = false) protected function apiRequest(string $path, array $data, string $method = 'GET')
{ {
// set api url // set api url
$url = $this->aipdbApiEndpoint . $path; $url = $this->aipdbApiEndpoint . $path;
@ -439,6 +438,7 @@ class ApiHandler extends ApiDefintion
$ch = curl_init(); $ch = curl_init();
// set the method and data to send // set the method and data to send
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if ($method == 'POST') { if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
@ -463,7 +463,7 @@ class ApiHandler extends ApiDefintion
// close connection // close connection
curl_close($ch); curl_close($ch);
// return response as JSON data // return response as is (JSON or plain text)
return $result; return $result;
} }