Skip to content

ericsizemore/ipquery-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

IPQuery PHP

Build Status Code Coverage Scrutinizer Code Quality Continuous Integration Type Coverage Psalm Level Latest Stable Version Downloads per Month License

Esi\IPQuery - A PHP library for ipquery.io, a free and performant ip address API.

Important

WIP: This library is not yet finished. Not recommended for production.

Requirements

  • PHP >= 8.3
  • Composer
  • And library(ies) that provide(s):
    • PSR-7 HTTP Message implementation
    • PSR-17 HTTP Factory implementation
    • PSR-18 HTTP Client implementation

Installation

This library is decoupled from any HTTP messaging client by using PSR-7, PSR-17, and PSR-18.

You can install the package via composer:

# First, install the base package
composer require esi/ipquery-php

# Then install your preferred PSR implementations.

# Example 1: Using Symfony components
composer require symfony/http-client:^7.0 symfony/psr-http-message-bridge:^7.0 nyholm/psr7:^1.0

# Example 2: Using Guzzle
composer require guzzlehttp/guzzle:^7.0

# There are other libraries and numerous combinations. The important thing is that a PSR-7, PSR-17, and PSR-18 implementation is provided.

This library makes use of php-http/http-discovery. This means that the Builder will default to any discoverable PSR-7, PSR-17, and PSR-18 libraries that are installed.

php-http/http-discovery also supports auto-installation if no libraries implementing the above PSR standards are found. This is accomplished by having the following in composer.json:

    "config": {
        "allow-plugins": {
            "php-http/discovery": true
        }
    }

Usage

Basic usage

use Esi\IPQuery\Client;
use Esi\IPQuery\Api\IP;

$ipApi = new IP(new Client());

var_dump($ipApi->sendRequest(['1.1.1.1', '8.8.8.8']));

HTTP Client Builder

You can customize the HTTP client by providing a Esi\IPQuery\HttpClient\Builder instance to the Esi\IPQuery\Client constructor.

For example, to set a custom user agent:

use Esi\IPQuery\Client;
use Esi\IPQuery\HttpClient\Builder;
use Http\Client\Common\Plugin\HeaderSetPlugin;

$builder = (new Builder())
    ->addPlugin(new HeaderSetPlugin([
        'User-Agent' => 'My super cool user agent',
    ]));

$client = new Client($builder);

Or using a specific library for the PSR implementations, instead of what is found by php-http/http-discovery:

use Esi\IPQuery\Client;
use Esi\IPQuery\HttpClient\Builder;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;

$factory = new HttpFactory();
$ipApi = new IP(new Client(new Builder(new GuzzleClient(), $factory, $factory, $factory)));

var_dump($ipApi->sendRequest(['1.1.1.1', '8.8.8.8']));

About

Credits

Contributing

See CONTRIBUTING.

Bugs and feature requests are tracked on GitHub.

Contributor Covenant Code of Conduct

See CODE_OF_CONDUCT.md

Backward Compatibility Promise

See backward-compatibility.md for more information on Backwards Compatibility.

Changelog

See the CHANGELOG for more information on what has changed recently.

License

See the LICENSE for more information on the license that applies to this project.

Security

See SECURITY for more information on the security disclosure process.

About

PHP library for ipquery.io, a free and performant ip address API.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Contributors 2

  •  
  •  

Languages