Skip to content

Commit

Permalink
Rename package from UnlimitedGeolocation to Geolocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Niek Pijp committed Apr 13, 2022
1 parent 3bb59f4 commit 835e571
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 207 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/brainstud/unlimited-geolocation/discussions/new?category=q-a
url: https://github.com/brainstud/geolocation/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/brainstud/unlimited-geolocation/discussions/new?category=ideas
url: https://github.com/brainstud/geolocation/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/brainstud/unlimited-geolocation/security/policy
url: https://github.com/brainstud/geolocation/security/policy
about: Learn how to notify us for sensitive bugs
- name: Report a bug
url: https://github.com/brainstud/unlimited-geolocation/issues/new
url: https://github.com/brainstud/geolocation/issues/new
about: Report a reproducable bug
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

All notable changes to `unlimited-geolocation` will be documented in this file.
All notable changes to `geolocation` will be documented in this file.

## 1.0.0 - 202X-XX-XX

Expand Down
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# Unlimited Geolocation
# Laravel Location

[![Latest Version on Packagist](https://img.shields.io/packagist/v/brainstud/unlimited-geolocation.svg?style=flat-square)](https://packagist.org/packages/brainstud/unlimited-geolocation)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/brainstud/unlimited-geolocation/run-tests?label=tests)](https://github.com/brainstud/unlimited-geolocation/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/brainstud/unlimited-geolocation/Check%20&%20fix%20styling?label=code%20style)](https://github.com/brainstud/unlimited-geolocation/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/brainstud/unlimited-geolocation.svg?style=flat-square)](https://packagist.org/packages/brainstud/unlimited-geolocation)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/brainstud/geolocation.svg?style=flat-square)](https://packagist.org/packages/brainstud/geolocation)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/brainstud/geolocation/run-tests?label=tests)](https://github.com/brainstud/geolocation/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/brainstud/geolocation/Check%20&%20fix%20styling?label=code%20style)](https://github.com/brainstud/geolocation/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/brainstud/geolocation.svg?style=flat-square)](https://packagist.org/packages/brainstud/geolocation)

Get the geolocation of the request to base the locale or timestamp on. This package will try to get the location from the cloudflare (or other configuable) header, or use a paid geo-locator API.
Get the country & timezone of the request with the cloudflare country header or fallback to a paid geo-locator API.

```php
UnlimitedGeolocation::getGeolocation($request)?->countryCode
$location = Geolocation::getLocation($request);
// { countryCode: "NL", timeZone: "Europe/Amsterdam" }
````

The aim of this package prioritize the cloudflare header to keep costs down. Only if that fails an API-call will be done.
By this philosophy only minimal info will be available. (country code and timezone)

## Installation

You can install the package via composer:

```bash
composer require brainstud/unlimited-geolocation
composer require brainstud/geolocation
```
You can publish the config file with:

```bash
php artisan vendor:publish --tag="unlimited-geolocation-config"
php artisan vendor:publish --tag="geolocation-config"
```

This is the contents of the published config file:
Expand All @@ -42,15 +46,6 @@ return [
];
```

## Usage
Configure the package with the config file. After that the package can be used like this.

```php
$location = UnlimitedGeolocation::getGeolocation($request);

// { countryCode: "NL", timeZone: "Europe/Amsterdam" }
````

## Supported services
- [Cloudflare IP geolocation](https://support.cloudflare.com/hc/en-us/articles/200168236-Configuring-Cloudflare-IP-Geolocation)
- [ipregistry](https://ipregistry.co/)
Expand Down
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "brainstud/unlimited-geolocation",
"description": "Get the geolocation of the request",
"name": "brainstud/geolocation",
"description": "A laravel package to get the country and timezone (geolocation) of the request",
"keywords": [
"brainstud",
"laravel",
"unlimited-geolocation"
"geolocation",
"timezone",
"ip",
"ipgeo"
],
"homepage": "https://github.com/brainstud/unlimited-geolocation",
"homepage": "https://github.com/brainstud/geolocation",
"license": "MIT",
"authors": [
{
Expand Down Expand Up @@ -35,13 +38,13 @@
},
"autoload": {
"psr-4": {
"Brainstud\\UnlimitedGeolocation\\": "src",
"Brainstud\\UnlimitedGeolocation\\Database\\Factories\\": "database/factories"
"Brainstud\\Geolocation\\": "src",
"Brainstud\\Geolocation\\Database\\Factories\\": "database/factories"
}
},
"autoload-dev": {
"psr-4": {
"Brainstud\\UnlimitedGeolocation\\Tests\\": "tests"
"Brainstud\\Geolocation\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -59,10 +62,10 @@
"extra": {
"laravel": {
"providers": [
"Brainstud\\UnlimitedGeolocation\\UnlimitedGeolocationServiceProvider"
"Brainstud\\Geolocation\\GeolocationServiceProvider"
],
"aliases": {
"UnlimitedGeolocation": "Brainstud\\UnlimitedGeolocation\\Facades\\UnlimitedGeolocation"
"Geolocation": "Brainstud\\Geolocation\\Facades\\Geolocation"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Brainstud\UnlimitedGeolocation\GeoLocators\GeoLocator;
use Brainstud\Geolocation\GeoLocators\GeoLocator;

return [
'header' => 'CF-IPCountry',
Expand Down
18 changes: 18 additions & 0 deletions src/Facades/Geolocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Brainstud\Geolocation\Facades;

use Brainstud\Geolocation\Location;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Facade;

/**
* @method static Location getLocation(Request $request)
*/
class Geolocation extends Facade
{
protected static function getFacadeAccessor()
{
return 'geolocation';
}
}
16 changes: 0 additions & 16 deletions src/Facades/UnlimitedGeolocation.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/GeoLocators/GeoLocator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Brainstud\UnlimitedGeolocation\GeoLocators;
namespace Brainstud\Geolocation\GeoLocators;

/**
* All available geo-locators.
Expand Down
8 changes: 4 additions & 4 deletions src/GeoLocators/GeoLocatorContract.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Brainstud\UnlimitedGeolocation\GeoLocators;
namespace Brainstud\Geolocation\GeoLocators;

use Brainstud\UnlimitedGeolocation\Geolocation;
use Brainstud\Geolocation\Location;
use Exception;

/**
Expand All @@ -13,8 +13,8 @@ interface GeoLocatorContract
/**
* Get the country code in ISO 3166-1 alpha-2 format.
* @param string $ip
* @return Geolocation|null
* @return Location|null
* @throws Exception
*/
public function getGeolocation(string $ip): ?Geolocation;
public function getLocation(string $ip): ?Location;
}
2 changes: 1 addition & 1 deletion src/GeoLocators/GeoLocatorFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Brainstud\UnlimitedGeolocation\GeoLocators;
namespace Brainstud\Geolocation\GeoLocators;

use Exception;
use Illuminate\Support\Facades\Log;
Expand Down
12 changes: 6 additions & 6 deletions src/GeoLocators/IpRegistry.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Brainstud\UnlimitedGeolocation\GeoLocators;
namespace Brainstud\Geolocation\GeoLocators;

use Brainstud\UnlimitedGeolocation\Geolocation;
use Brainstud\Geolocation\Location;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

Expand All @@ -18,10 +18,10 @@ public function __construct()
$this->client = new Client();
}

public function getGeolocation(string $ip): ?Geolocation
public function getLocation(string $ip): ?Location
{
if (! ($baseUrl = config('unlimited-geolocation.ip-registry.base_url'))
|| ! ($apiKey = config('unlimited-geolocation.ip-registry.key'))
if (! ($baseUrl = config('geolocation.ip-registry.base_url'))
|| ! ($apiKey = config('geolocation.ip-registry.key'))
) {
return null;
}
Expand All @@ -30,7 +30,7 @@ public function getGeolocation(string $ip): ?Geolocation
$res = $this->client->request('GET', "$baseUrl/$ip?key=$apiKey");
$data = json_decode($res->getBody()->getContents());

return Geolocation::fromIpRegistry($data);
return Location::fromIpRegistry($data);
} catch (RequestException $e) {
if ($e->hasResponse() && $e->getResponse()->getStatusCode() === 400) {
return null;
Expand Down
12 changes: 6 additions & 6 deletions src/GeoLocators/IpStack.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Brainstud\UnlimitedGeolocation\GeoLocators;
namespace Brainstud\Geolocation\GeoLocators;

use Brainstud\UnlimitedGeolocation\Geolocation;
use Brainstud\Geolocation\Location;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

Expand All @@ -18,10 +18,10 @@ public function __construct()
$this->client = new Client();
}

public function getGeolocation(string $ip): ?Geolocation
public function getLocation(string $ip): ?Location
{
if (! ($baseUrl = config('unlimited-geolocation.ip-stack.base_url'))
|| ! ($apiKey = config('unlimited-geolocation.ip-stack.key'))
if (! ($baseUrl = config('geolocation.ip-stack.base_url'))
|| ! ($apiKey = config('geolocation.ip-stack.key'))
) {
return null;
}
Expand All @@ -30,7 +30,7 @@ public function getGeolocation(string $ip): ?Geolocation
$res = $this->client->request('GET', "$baseUrl/$ip?access_key=$apiKey");
$data = json_decode($res->getBody()->getContents());

return Geolocation::fromIpStack($data);
return Location::fromIpStack($data);
} catch (RequestException $e) {
if ($e->hasResponse() && $e->getResponse()->getStatusCode() === 400) {
return null;
Expand Down
Loading

0 comments on commit 835e571

Please sign in to comment.