-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33076d6
commit d055645
Showing
19 changed files
with
791 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,19 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.github export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/art export-ignore | ||
/docs export-ignore | ||
/tests export-ignore | ||
/.editorconfig export-ignore | ||
/.php_cs.dist.php export-ignore | ||
/psalm.xml export-ignore | ||
/psalm.xml.dist export-ignore | ||
/testbench.yaml export-ignore | ||
/UPGRADING.md export-ignore | ||
/phpstan.neon.dist export-ignore | ||
/phpstan-baseline.neon export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.idea | ||
.phpunit.cache | ||
build | ||
composer.lock | ||
coverage | ||
docs | ||
phpunit.xml | ||
phpstan.neon | ||
testbench.yaml | ||
vendor | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changelog | ||
|
||
All notable changes to `geo-content` will be documented in this file. | ||
|
||
## 0.1.0 - 2023-08-11 | ||
### Added | ||
- Initial release | ||
- freeipapi integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Nawras Bukhari <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Laravel Geo-Content Package | ||
|
||
--- | ||
The Laravel Geo-Content package provides a convenient way to fetch geolocation information using the FreeIPAPI service. This package is designed to retrieve geolocation data for IP addresses, including details such as country name, country code, continent, and more. | ||
|
||
## Installation | ||
```bash | ||
composer require nawrasbukhari/geo-content | ||
``` | ||
|
||
You can publish the config file with: | ||
|
||
```bash | ||
php artisan vendor:publish --tag="geo-content-config" | ||
``` | ||
|
||
This is the contents of the published config file: | ||
|
||
```php | ||
return [ | ||
'freeipapi_base_url' => env('FREEIPAPI_BASE_URL', 'https://freeipapi.com/api/json/'), | ||
'freeipapi_key' => env('FREEIPAPI_KEY'), | ||
'freeipapi_ssl' => env('FREEIPAPI_SSL', false), | ||
'timeout' => env('FREEIPAPI_TIMEOUT', 30), | ||
'testing_ip_address' => env('FREEIPAPI_TESTING_IP_ADDRESS', '208.67.222.222'), | ||
'usual_localhost_ip' => [ | ||
'127.0.0.1', | ||
'::1', | ||
'localhost', | ||
], | ||
]; | ||
``` | ||
|
||
## Usage | ||
|
||
Show content only to users from the United States | ||
```php | ||
use NawrasBukhari\GeoContent\GeoContent; | ||
|
||
$geoContent = new GeoContent(); | ||
|
||
if ($geoContent->country('United States of America')) { | ||
// Display restricted content here | ||
} | ||
``` | ||
Allowing Content for Specific Continents | ||
Similarly, you can use the continent method to display content exclusively to users from particular continents: | ||
|
||
```php | ||
use NawrasBukhari\GeoContent\GeoContent; | ||
|
||
$geoContent = new GeoContent(); | ||
|
||
if ($geoContent->continent('AM')) { | ||
// Display restricted content here | ||
} | ||
``` | ||
|
||
Disallowing Content for Specific Countries | ||
You can use the `onlyShowInCountry()` or `onlyShowInCountryCode()` method to display content to users from specific country | ||
|
||
```php | ||
use NawrasBukhari\GeoContent\GeoContent; | ||
|
||
// Create an instance of the GeoContent class | ||
$geoContent = new GeoContent(); | ||
|
||
// Hide content from users in Russia | ||
if ($geoContent->onlyShowInCountry('Russia')) { | ||
// Display non-restricted content here for users from Russia | ||
} | ||
``` | ||
|
||
## Testing | ||
|
||
```bash | ||
composer test | ||
``` | ||
|
||
## Changelog | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
|
||
|
||
## Credits | ||
|
||
- [Free IP API](https://freeipapi.com) | ||
- [Spatie skeleton](https://github.com/spatie/package-skeleton-laravel) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"name": "nawrasbukhari/geo-content", | ||
"description": "GeoContent is a Laravel package that provides a simple way to manage your content based on the user's location.", | ||
"keywords": [ | ||
"laravel", | ||
"laravel-package", | ||
"GeoContent", | ||
"freeipapi" | ||
], | ||
"homepage": "https://github.com/NawrasBukhari/GeoContent", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nawras Bukhari", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.1", | ||
"illuminate/contracts": "^10.0", | ||
"spatie/laravel-package-tools": "^1.14.0" | ||
}, | ||
"require-dev": { | ||
"laravel/pint": "^1.0", | ||
"nunomaduro/collision": "^7.8", | ||
"nunomaduro/larastan": "^2.0.1", | ||
"orchestra/testbench": "^8.0", | ||
"pestphp/pest": "^2.0", | ||
"pestphp/pest-plugin-arch": "^2.0", | ||
"pestphp/pest-plugin-laravel": "^2.0", | ||
"phpstan/extension-installer": "^1.1", | ||
"phpstan/phpstan-deprecation-rules": "^1.0", | ||
"phpstan/phpstan-phpunit": "^1.0", | ||
"spatie/laravel-ray": "^1.26" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"NawrasBukhari\\GeoContent\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"NawrasBukhari\\GeoContent\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", | ||
"analyse": "vendor/bin/phpstan analyse", | ||
"test": "vendor/bin/pest", | ||
"test-coverage": "vendor/bin/pest --coverage", | ||
"format": "vendor/bin/pint" | ||
}, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"pestphp/pest-plugin": true, | ||
"phpstan/extension-installer": true | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"NawrasBukhari\\GeoContent\\GeoContentServiceProvider" | ||
], | ||
"aliases": { | ||
"GeoContent": "NawrasBukhari\\GeoContent\\Facades\\GeoContent" | ||
} | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
return [ | ||
'freeipapi_base_url' => env('FREEIPAPI_BASE_URL', 'https://freeipapi.com/api/json/'), | ||
'freeipapi_key' => env('FREEIPAPI_KEY'), | ||
'freeipapi_ssl' => env('FREEIPAPI_SSL', false), | ||
'timeout' => env('FREEIPAPI_TIMEOUT', 30), | ||
'testing_ip_address' => env('FREEIPAPI_TESTING_IP_ADDRESS', '208.67.222.222'), | ||
'usual_localhost_ip' => [ | ||
'127.0.0.1', | ||
'::1', | ||
'localhost', | ||
], | ||
]; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
includes: | ||
- phpstan-baseline.neon | ||
|
||
parameters: | ||
level: 4 | ||
paths: | ||
- src | ||
- config | ||
- database | ||
tmpDir: build/phpstan | ||
checkOctaneCompatibility: true | ||
checkModelProperties: true | ||
checkMissingIterableValueType: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" | ||
backupGlobals="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
executionOrder="random" | ||
failOnWarning="true" | ||
failOnRisky="true" | ||
failOnEmptyTestSuite="true" | ||
beStrictAboutOutputDuringTests="true" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false" | ||
> | ||
<testsuites> | ||
<testsuite name="VendorName Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<report> | ||
<html outputDirectory="build/coverage"/> | ||
<text outputFile="build/coverage.txt"/> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
</report> | ||
</coverage> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace NawrasBukhari\GeoContent\Exceptions; | ||
|
||
use Exception; | ||
|
||
class MissingSSLException extends Exception | ||
{ | ||
} |
Oops, something went wrong.