Skip to content

Commit e7e597e

Browse files
committed
v0.1.0
0 parents  commit e7e597e

28 files changed

+1452
-0
lines changed

.env.example.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IP_GEO_API_KEY="YOUR_API_KEY"

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/tests export-ignore
2+
/.gitattributes export-ignore
3+
/.gitignore export-ignore

.github/workflows/unittest.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Unit test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
unit_test:
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
matrix:
10+
operating-system: [ ubuntu-18.04, windows-2019 ]
11+
php: [ '7.1', '7.2', '7.3', '7.4', '7.3.3' ]
12+
13+
env:
14+
IP_GEO_API_KEY: ${{ secrets.API_KEY }}
15+
16+
steps:
17+
- uses: actions/checkout@master
18+
19+
- name: Setup PHP
20+
uses: nanasess/setup-php@master
21+
with:
22+
php-version: ${{ matrix.php }}
23+
24+
- name: Run test
25+
run: |
26+
composer self-update
27+
composer install --prefer-source --no-interaction --ignore-platform-reqs
28+
php vendor/bin/phpunit

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
.env.test
3+
/vendor
4+
composer.lock

.scrutinizer.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# .scrutinizer.yml
2+
checks:
3+
php: true
4+
5+
filter:
6+
excluded_paths:
7+
- tests/*
8+
- vendor/*
9+
paths:
10+
- src/*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Abstract
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# AbstractAPI php-ip-geolocation library
2+
3+
Integrate the powerful [IP Geolocation API from Abstract](https://www.abstractapi.com/ip-geolocation-api) in your PHP project in a few lines of code.
4+
5+
Abstract's IP Geolocation API is a fast, lightweight, modern, and RESTful JSON API allowing you to look up the location, timezone, country details, and more of an IPv4 or IPv6 address.
6+
7+
It's very simple to use: you only need to submit your API key and an IP address, and the API will respond with an assessment of its geographical location, as well as additional details like the timezone, if it's a VPN address, and more.
8+
9+
Validating and verifying IP addresses is a critical step to reducing the chances of low-quality data and fraudulent or risky users in your website or application.
10+
11+
# Documentation
12+
13+
## Supported PHP Versions
14+
15+
This library supports the **PHP version 5.6** and higher.
16+
17+
## Installation
18+
19+
You can install **php-ip-geolocation** via composer or by downloading the source.
20+
21+
### Via Composer:
22+
23+
**php-ip-geolocation** is available on Packagist as the
24+
[`abstractapi/php-ip-geolocation`](https://packagist.org/packages/abstractapi/php-ip-geolocation) package:
25+
26+
```bash
27+
composer require abstractapi/php-ip-geolocation
28+
```
29+
30+
## API key
31+
32+
Get your API key for free and without hassle from the [Abstact website](https://app.abstractapi.com/users/signup?target=/api/ip-geolocation/pricing/select).
33+
34+
## Quickstart
35+
36+
### Geolocation from an IP Address
37+
38+
```php
39+
// Get a Geolocation from an IP Address Abstract's IP Geolocation API and PHP
40+
<?php
41+
$api_key = "YYYYYY"; // Your API Key from https://app.abstractapi.com/api/ip-geolocation/documentation
42+
43+
Abstractapi\IpGeolocation\AbstractIpGeolocation::configure($api_key);
44+
45+
$info = Abstractapi\IpGeolocation\AbstractIpGeolocation::look_up('8.8.8.8');
46+
47+
print $info->city;
48+
49+
```
50+
51+
## API response
52+
53+
The API response is returned in a `IpGeolocationData` object.
54+
55+
| PARAMETER | TYPE | DETAILS |
56+
| - | - | - |
57+
| Parameter | Type | Details |
58+
| ip_address | String | The requested IP address |
59+
| city | String | City's name. |
60+
| city_geoname_id | String | City's geoname ID. |
61+
| region | String | State or province in which the the city is located. |
62+
| region_iso_code | Char[2] | State or province's ISO 3166-2 code. |
63+
| region_geoname_id | String | State or province's geoname ID. |
64+
| postal_code | String | ZIP or postal code. |
65+
| country | String | Country's name. |
66+
| country_code | Char[2] | Country's ISO 3166-1 alpha-2 code. |
67+
| country_geoname_id | String | Country's geoname ID. |
68+
| country_is_eu | Boolean | True if the country is in the EU, false if it is not. |
69+
| continent | String | Continent's name. |
70+
| continent_code | Char[2] | 2 letter continent code: AF, AS, EU, NA, OC, SA, AN |
71+
| continent_geoname_id | String | Continent's geoname ID. |
72+
| longitude | Float | Decimal of the longitude. |
73+
| latitude | Float | Decimal of the latitude. |
74+
| security > is_vpn | Boolean | Whether the IP address is using from a VPN or using a proxy |
75+
| timezone > name | String | Timezone's name from the IANA Time Zone Database. |
76+
| timezone > abbreviation | String | Timezone's abbreviation, also from the IANA Time Zone Database. |
77+
| timezone > gmt_offset | String | Timezone's offset from Greenwich Mean Time (GMT). |
78+
| timezone > current_time | String | Current time in the local time zone. |
79+
| timezone > is_dst | Boolean | True if the location is currently in Daylight Savings Time (DST). |
80+
| flag > svg | String | Link to a hosted version of the country's flag in SVG format. |
81+
| flag > png | String | Link to a hosted version of the country's flag in PNG format. |
82+
| flag > emoji | String | Country's flag as an emoji. |
83+
| flag > unicode | String | Country's flag in unicode. |
84+
| currency > currency_name | String | The currency's name. |
85+
| currency > currency_code | String | The currency's code in ISO 4217 format. |
86+
| connection > connection_type | String | Type of network connection: Dialup, Cable/DSL, Cellular, Corporate |
87+
| connection > autonomous_system_number | Uint32 | Autonomous System number |
88+
| connection > autonomous_system_organization | String | Autonomous System Organization name. |
89+
| connection > isp_name | String | Internet Service Provider (ISP) name. |
90+
| connection > organization_name | String | Organization name. |
91+
92+
## Detailed documentation
93+
94+
You will find additional information and request examples in the [Abstract help page](https://app.abstractapi.com/api/ip-geolocation/documentation).
95+
96+
## Getting help
97+
98+
If you need help installing or using the library, please contact [Abstract's Support](https://app.abstractapi.com/api/ip-geolocation/support).
99+
100+
For bug report and feature suggestion, please use [this repository issues page](https://github.com/abstractapi/php-ip-geolocation/issues).
101+
102+
# Contribution
103+
104+
Contributions are always welcome, as they improve the quality of the libraries we provide to the community.
105+
106+
Please provide your changes covered by the appropriate unit tests, and post them in the [pull requests page](https://github.com/abstractapi/php-ip-geolocation/pulls).
107+
108+
## Composer
109+
110+
To work on the source code, you need to install composer on your local computer. At the time of writing, the latest version of composer is v2.0.12. The installation instructions can be found here: https://getcomposer.org/download/.
111+
112+
## Setup
113+
114+
To install the requirements, run:
115+
116+
```bash
117+
composer install --prefer-source --no-interaction --ignore-platform-reqs
118+
```
119+
120+
Once you implementer all your changes and the unit tests, run the following command to run the tests:
121+
122+
```bash
123+
php vendor/bin/phpunit
124+
```

composer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "abstractapi/php-ip-geolocation",
3+
"description": "AbstractIpGeolocation - Wrapper to quickly start using the powerful AbstractAPI's IP geolocation service in your projects.",
4+
"version": "0.1.0",
5+
"type": "library",
6+
"keywords": ["abstract", "abstractapi", "api", "api", "geolocation", "geolocation", "geolocation-api", "geolocation-application", "geolocation-data", "geolocation-database", "geolocation-plugin", "ip", "ip geolocation", "ip-geo", "ip-geolocation", "ip-geolocation-api", "ip-geolocation-ip2location", "library", "php", "php", "php-library", "wrapper"]
7+
,
8+
"homepage": "https://github.com/abstractapi/php-ip-geolocation",
9+
"readme": "README.md",
10+
"time": "2021-04-09",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Benjamin Bouchet",
15+
"email": "libraries@abstractapi.com",
16+
"homepage": "https://www.abstractapi.com"
17+
}
18+
],
19+
"support": {
20+
"source": "https://github.com/abstractapi/php-ip-geolocation",
21+
"docs": "https://app.abstractapi.com/api/ip-geolocation/documentation"
22+
},
23+
"scripts": {
24+
"check": [
25+
],
26+
"fix": [
27+
],
28+
"versions": [
29+
]
30+
},
31+
"require": {
32+
"php": ">=5.6",
33+
"ext-curl": "*",
34+
"ext-json": "*"
35+
},
36+
"require-dev": {
37+
"phpunit/phpunit": "7.0.*",
38+
"vlucas/phpdotenv": "^2.0"
39+
},
40+
"suggest": {
41+
},
42+
"autoload": {
43+
"psr-4": {
44+
"Abstractapi\\IpGeolocation\\": "src/AbstractIpGeolocation"
45+
}
46+
},
47+
"autoload-dev": {
48+
"psr-4": {
49+
"Abstractapi\\IpGeolocation\\Tests\\": "tests/"
50+
}
51+
}
52+
}

examples/error_handling.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require_once("../src/AbstractIpGeolocation/autoload.php");
4+
5+
use Abstractapi\IpGeolocation\AbstractIpGeolocation;
6+
use Abstractapi\IpGeolocation\Common\Exception\AbstractHttpErrorException;
7+
8+
AbstractIpGeolocation::configure($api_key = "YOUR_API_KEY");
9+
10+
try
11+
{
12+
$info = AbstractIpGeolocation::look_up();
13+
}
14+
catch (AbstractHttpErrorException $e)
15+
{
16+
echo "Message: ". $e->getMessage(). "; <br>";
17+
echo "Code: ". $e->code. "; <br>";
18+
echo "HttpStatusCode: ". $e->http_code. "; <br>";
19+
echo "Details: ";
20+
print_r($e->details);
21+
22+
echo "<pre>";
23+
print_r(AbstractIpGeolocation::getLastResponse());
24+
echo "</pre>";
25+
26+
}
27+
catch (InvalidArgumentException $e)
28+
{
29+
// Handle somehow
30+
}

examples/lookup_ip_adress.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once("../src/AbstractIpGeolocation/autoload.php");
4+
5+
use Abstractapi\IpGeolocation\AbstractIpGeolocation;
6+
7+
AbstractIpGeolocation::configure($api_key = "YOUR_API_KEY");
8+
9+
$info = AbstractIpGeolocation::look_up();
10+
11+
echo "<pre>";
12+
print_r($info);
13+
echo "</pre>";
14+
15+
echo "city: " ; echo $info->city;
16+
echo "</br>";
17+
echo "security.is_vpn: "; echo var_export($info->security->is_vpn);

0 commit comments

Comments
 (0)