diff --git a/README.md b/README.md index ea5fd78..4d79cd1 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ Features - IP block check request **✓** - Blacklist request **✓** - Single report request **✓** +- Clear address request (remove own reports) **✓** - Auto cleaning report comment from sensitive data **✓** -TODO -- *\[TODO\] clear address request* -- *\[TODO\] Bulk report request* +**Not implemented:** +- *\[TODO\] Bulk report Api request* Requirements ------------ @@ -34,7 +34,7 @@ Deploy with composer: ```json ... "require": { - "kristuff/abuseipdb": ">=0.9.4-stable" + "kristuff/abuseipdb": ">=0.9.5-stable" }, ``` diff --git a/lib/ApiDefintion.php b/lib/ApiDefintion.php index d692c38..620d8dc 100644 --- a/lib/ApiDefintion.php +++ b/lib/ApiDefintion.php @@ -14,7 +14,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * - * @version 0.9.4 + * @version 0.9.5 * @copyright 2020-2021 Kristuff */ @@ -120,7 +120,18 @@ abstract class ApiDefintion // Abuse was targeted at an "Internet of Things" type device. Include // information about what type of device was targeted in the comments. ['oit' , '23', 'IoT Targeted', true], - ]; + ]; + + /** + * Get the list of report categories + * + * @access public + * @return array + */ + public function getCategories() + { + return $this->aipdbApiCategories; + } /** * Get the category id corresponding to given name diff --git a/lib/ApiHandler.php b/lib/ApiHandler.php index 25e5bd8..71465ff 100644 --- a/lib/ApiHandler.php +++ b/lib/ApiHandler.php @@ -14,7 +14,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * - * @version 0.9.4 + * @version 0.9.5 * @copyright 2020-2021 Kristuff */ @@ -86,13 +86,13 @@ class ApiHandler extends ApiDefintion } /** - * Get a new instance of ApiManager with config stored in a Json file + * Get a new instance of ApiHandler with config stored in a Json file * * @access public * @static * @param string $configPath The configuration file path * - * @return \Kristuff\AbuseIPDB\ApiManager + * @return \Kristuff\AbuseIPDB\ApiHandler * @throws \InvalidArgumentException If the given file does not exist * @throws \Kristuff\AbuseIPDB\InvalidPermissionException If the given file is not readable */ @@ -123,17 +123,6 @@ class ApiHandler extends ApiDefintion return $app; } - /** - * Get the list of report categories - * - * @access public - * @return array - */ - public function getCategories() - { - return $this->aipdbApiCategories; - } - /** * Performs a 'report' api request * @@ -149,7 +138,7 @@ class ApiHandler extends ApiDefintion * @param string $ip The ip to report * @param string $categories The report categories * @param string $message The report message - * @param bool $returnArray True to return an indexed array instead of an object. Default is false. + * @param bool $returnArray True to return an indexed array instead of object. Default is false. * * @return object|array * @throws \InvalidArgumentException @@ -226,7 +215,7 @@ class ApiHandler extends ApiDefintion * @access public * @param string $network The network to check * @param int $maxAge Max age in days - * @param bool $returnArray True to return an indexed array instead of an object. Default is false. + * @param bool $returnArray True to return an indexed array instead of object. Default is false. * * @return object|array * @throws \InvalidArgumentException when maxAge is less than 1 or greater than 365, or when network value was not set. @@ -254,6 +243,42 @@ class ApiHandler extends ApiDefintion 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('check', $data, 'DELETE', $returnArray) ; + + return json_decode($response, $returnArray); + } + /** * Perform a 'check' api request * @@ -261,7 +286,7 @@ class ApiHandler extends ApiDefintion * @param string $ip The ip to check * @param int $maxAge Max age in days * @param bool $verbose True to get the full response. Default is false - * @param bool $returnArray True to return an indexed array instead of an object. Default is false. + * @param bool $returnArray True to return an indexed array instead of object. Default is false. * * @return object|array * @throws \InvalidArgumentException when maxAge is less than 1 or greater than 365, or when ip value was not set. @@ -289,7 +314,6 @@ class ApiHandler extends ApiDefintion $data['verbose'] = true; } - // check AbuseIPDB request $response = $this->apiRequest('check', $data, 'GET', $returnArray) ; return json_decode($response, $returnArray); @@ -301,7 +325,7 @@ class ApiHandler extends ApiDefintion * @access public * @param int $limit The blacklist limit. Default is TODO (the api default limit) * @param bool $plainText True to get the response in plain text list. Default is false - * @param bool $returnArray True to return an indexed array instead of an object (when $plainText is set to false). Default is false. + * @param bool $returnArray True to return an indexed array instead of object (when $plainText is set to false). Default is false. * * @return object|array * @throws \InvalidArgumentException When maxAge is not a numeric value, when maxAge is less than 1 or diff --git a/lib/InvalidPermissionException.php b/lib/InvalidPermissionException.php index cb38e93..821731f 100644 --- a/lib/InvalidPermissionException.php +++ b/lib/InvalidPermissionException.php @@ -14,7 +14,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * - * @version 0.9.4 + * @version 0.9.5 * @copyright 2020-2021 Kristuff */