peaky-blind3rs / ip-address-interface
IP Address Interface
Requires
- php: >=8.2
- guzzlehttp/guzzle: ^7.7
- psr/http-message: 1.1
Requires (Dev)
- phpunit/phpunit: ^10.2
- rector/rector: ^0.17.5
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.13
This package is not auto-updated.
Last update: 2025-05-18 19:41:14 UTC
README
This library offers a standard interface to implement IP Geolocation and Threat Intelligence API in your PHP projects. It offers developers a way to craft various IP data adapter classes for their unique project requirements.
Requirements
- PHP 8.2 or higher
- psr/http-message 1.1 or higher
Installation
The package can be installed via Composer. Run the following command:
composer require peaky-blind3rs/ip-address-interface
Usage
Using IPInfo Adapter
use PeakyBlind3rs\IpAddressInterface\Interface\Model\IpAddressInterface; use PeakyBlind3rs\IpAddressInterface\IPServiceFactory; $instance = IPServiceFactory::getInstance('ipinfo://nobody:your-api-token@ipinfo.io/?timeout=30'); $result = $instance->lookup('27.126.160.0'); if ($result instanceof IpAddressInterface) { // Request was successful, use getter methods to get data } else { // Requested Ended in Error and $result hold instance of \Psr\Http\Message\ResponseInterface }
Or if you want to use IPData Adapter
use PeakyBlind3rs\IpAddressInterface\Interface\Model\IpAddressInterface; use PeakyBlind3rs\IpAddressInterface\IPServiceFactory; $instance = IPServiceFactory::getInstance('ipdata://nobody:your-api-key@ipdata.co/?timeout=30'); $result = $instance->lookup('27.126.160.0'); if ($result instanceof IpAddressInterface) { // Request was successful, use getter methods to get data } else { // Requested Ended in Error and $result hold instance of \Psr\Http\Message\ResponseInterface }
If you want to use your own adapter, your adapter needs to implement \PeakyBlind3rs\IpAddressInterface\Interface\IpLookupInterface
namespace MyNamespace; class MyAdapter implements \PeakyBlind3rs\IpAddressInterface\Interface\IpLookupInterface { }
And then add your adapter to class map and use it
use MyNamespace\MyAdapter; use PeakyBlind3rs\IpAddressInterface\IPServiceFactory; use PeakyBlind3rs\IpAddressInterface\Interface\Model\IpAddressInterface; IPServiceFactory::classMaps([ 'myadapter' => MyAdapter::class ]); $instance = IPServiceFactory::getInstance('myadapter://nobody:your-api-key@myadapter-api.tld/?timeout=30'); $result = $instance->lookup('27.126.160.0'); if ($result instanceof IpAddressInterface) { // Request was successful, use getter methods to get data } else { // Requested Ended in Error and $result hold instance of \Psr\Http\Message\ResponseInterface }
Testing
To run the tests, execute:
composer test
Coding Standards
Check your code for PSR compliance:
composer cs-check
Static Analysis
Analyze your code statically:
composer static-analysis
License
This project is licensed under the MIT License. Refer to the LICENSE.md file for further details.
Contributing
Please consult the CONTRIBUTING.md file for more information.
Acknowledgements
- Thanks to the PHP community for providing the language we cherish.
- Thanks to Composer for handling the package dependencies effectively.
Contact
- Have any issues? Report them via the project issue tracker.
- Got some enhancements in mind? Feel free to create a pull request or open an issue.
Happy coding!