diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..c3bb259 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: laravel \ No newline at end of file diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..e0a7550 --- /dev/null +++ b/changelog.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to `ipinfolaravel` will be documented in this file. + +## Version 1.0 + +### Added +- Everything diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..4e50ae1 --- /dev/null +++ b/composer.json @@ -0,0 +1,44 @@ +{ + "name": "ipinfo/ipinfolaravel", + "description": ":description", + "license": "Apache", + "authors": [ + { + "name": "James Timmins", + "email": "jameshtimmins@gmail.com", + "homepage": "ipinfo.io" + } + ], + "homepage": "https://github.com/ipinfo/ipinfolaravel", + "keywords": ["Laravel", "ipinfolaravel"], + "require": { + "illuminate/support": "~5", + "ipinfo/ipinfo": "^1.0@dev" + }, + "require-dev": { + "phpunit/phpunit": "~7.0", + "mockery/mockery": "^1.1", + "orchestra/testbench": "~3.0", + "sempro/phpunit-pretty-print": "^1.0" + }, + "autoload": { + "psr-4": { + "ipinfo\\ipinfolaravel\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "ipinfo\\ipinfolaravel\\Tests\\": "tests" + } + }, + "extra": { + "laravel": { + "providers": [ + "ipinfo\\ipinfolaravel\\ipinfolaravelServiceProvider" + ], + "aliases": { + "ipinfolaravel": "ipinfo\\ipinfolaravel\\Facades\\ipinfolaravel" + } + } + } +} diff --git a/config/ipinfolaravel.php b/config/ipinfolaravel.php new file mode 100644 index 0000000..035fcd5 --- /dev/null +++ b/config/ipinfolaravel.php @@ -0,0 +1,5 @@ + + +...Add your license text here... \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..ce34605 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,22 @@ + + + + + ./tests/ + + + + + src/ + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..2f52c63 --- /dev/null +++ b/readme.md @@ -0,0 +1,57 @@ +# ipinfolaravel + +[![Latest Version on Packagist][ico-version]][link-packagist] +[![Total Downloads][ico-downloads]][link-downloads] +[![Build Status][ico-travis]][link-travis] +[![StyleCI][ico-styleci]][link-styleci] + +This is where your description should go. Take a look at [contributing.md](contributing.md) to see a to do list. + +## Installation + +Via Composer + +``` bash +$ composer require ipinfo/ipinfolaravel +``` + +## Usage + +## Change log + +Please see the [changelog](changelog.md) for more information on what has changed recently. + +## Testing + +``` bash +$ composer test +``` + +## Contributing + +Please see [contributing.md](contributing.md) for details and a todolist. + +## Security + +If you discover any security related issues, please email jameshtimmins@gmail.com instead of using the issue tracker. + +## Credits + +- [James Timmins][link-author] +- [All Contributors][link-contributors] + +## License + +Apache. Please see the [license file](license.md) for more information. + +[ico-version]: https://img.shields.io/packagist/v/ipinfo/ipinfolaravel.svg?style=flat-square +[ico-downloads]: https://img.shields.io/packagist/dt/ipinfo/ipinfolaravel.svg?style=flat-square +[ico-travis]: https://img.shields.io/travis/ipinfo/ipinfolaravel/master.svg?style=flat-square +[ico-styleci]: https://styleci.io/repos/12345678/shield + +[link-packagist]: https://packagist.org/packages/ipinfo/ipinfolaravel +[link-downloads]: https://packagist.org/packages/ipinfo/ipinfolaravel +[link-travis]: https://travis-ci.org/ipinfo/ipinfolaravel +[link-styleci]: https://styleci.io/repos/12345678 +[link-author]: https://github.com/ipinfo +[link-contributors]: ../../contributors] \ No newline at end of file diff --git a/rewriteRules.php b/rewriteRules.php new file mode 100644 index 0000000..6abf62c --- /dev/null +++ b/rewriteRules.php @@ -0,0 +1,9 @@ + 'src/ipinfolaravel.php', + 'config/mypackage.php' => 'config/ipinfolaravel.php', + 'src/Facades/MyPackage.php' => 'src/Facades/ipinfolaravel.php', + 'src/MyPackageServiceProvider.php' => 'src/ipinfolaravelServiceProvider.php', +]; \ No newline at end of file diff --git a/rules.php b/rules.php new file mode 100644 index 0000000..6abf62c --- /dev/null +++ b/rules.php @@ -0,0 +1,9 @@ + 'src/ipinfolaravel.php', + 'config/mypackage.php' => 'config/ipinfolaravel.php', + 'src/Facades/MyPackage.php' => 'src/Facades/ipinfolaravel.php', + 'src/MyPackageServiceProvider.php' => 'src/ipinfolaravelServiceProvider.php', +]; \ No newline at end of file diff --git a/src/Facades/ipinfolaravel.php b/src/Facades/ipinfolaravel.php new file mode 100644 index 0000000..e0cda6f --- /dev/null +++ b/src/Facades/ipinfolaravel.php @@ -0,0 +1,18 @@ +filter($request)) { + $details = null; + } else { + $ipinfo = new IPinfoClient($this->access_token, $this->settings); + $details = $ipinfo->getDetails(); + } + + $request->merge(['ipinfo' => $details]); + + return $next($request); + } + + /** + * Should IP lookup be skipped. + * @param Request $request Request object. + * @return bool Whether or not to filter out. + */ + protected function filter($request) + { + $user_agent = $request->header('user-agent'); + if ($user_agent) { + $lower_user_agent = strtolower($user_agent); + + $is_spider = strpos($lower_user_agent, 'spider') !== false; + $is_bot = strpos($lower_user_agent, 'bot') !== false; + + return $is_spider || $is_bot; + } + + return false; + } +} diff --git a/src/ipinfolaravelServiceProvider.php b/src/ipinfolaravelServiceProvider.php new file mode 100644 index 0000000..70c0dc9 --- /dev/null +++ b/src/ipinfolaravelServiceProvider.php @@ -0,0 +1,82 @@ +loadTranslationsFrom(__DIR__.'/../resources/lang', 'ipinfo'); + // $this->loadViewsFrom(__DIR__.'/../resources/views', 'ipinfo'); + // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + // $this->loadRoutesFrom(__DIR__.'/routes.php'); + + // Publishing is only necessary when using the CLI. + if ($this->app->runningInConsole()) { + $this->bootForConsole(); + } + } + + /** + * Register any package services. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom(__DIR__.'/../config/ipinfolaravel.php', 'ipinfolaravel'); + + // Register the service the package provides. + $this->app->singleton('ipinfolaravel', function ($app) { + return new ipinfolaravel; + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return ['ipinfolaravel']; + } + + /** + * Console-specific booting. + * + * @return void + */ + protected function bootForConsole() + { + // Publishing the configuration file. + $this->publishes([ + __DIR__.'/../config/ipinfolaravel.php' => config_path('ipinfolaravel.php'), + ], 'ipinfolaravel.config'); + + // Publishing the views. + /*$this->publishes([ + __DIR__.'/../resources/views' => base_path('resources/views/vendor/ipinfo'), + ], 'ipinfolaravel.views');*/ + + // Publishing assets. + /*$this->publishes([ + __DIR__.'/../resources/assets' => public_path('vendor/ipinfo'), + ], 'ipinfolaravel.views');*/ + + // Publishing the translation files. + /*$this->publishes([ + __DIR__.'/../resources/lang' => resource_path('lang/vendor/ipinfo'), + ], 'ipinfolaravel.views');*/ + + // Registering package commands. + // $this->commands([]); + } +}