Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhtimmins committed Sep 27, 2018
0 parents commit 623fc9a
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 0 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: laravel
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

All notable changes to `ipinfolaravel` will be documented in this file.

## Version 1.0

### Added
- Everything
44 changes: 44 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "ipinfo/ipinfolaravel",
"description": ":description",
"license": "Apache",
"authors": [
{
"name": "James Timmins",
"email": "[email protected]",
"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"
}
}
}
}
5 changes: 5 additions & 0 deletions config/ipinfolaravel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
//
];
27 changes: 27 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Contributing

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on [Github](https://github.com/ipinfo/ipinfolaravel).

# Things you could do
If you want to contribute but do not know where to start, this list provides some starting points.
- Add license text
- Remove rewriteRules.php
- Set up TravisCI, StyleCI, ScrutinizerCI
- Write a comprehensive ReadMe

## Pull Requests

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.


**Happy coding**!
5 changes: 5 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The license

Copyright (c) James Timmins <[email protected]>

...Add your license text here...
22 changes: 22 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Package">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src/</directory>
</whitelist>
</filter>
</phpunit>
57 changes: 57 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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 [email protected] 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]
9 changes: 9 additions & 0 deletions rewriteRules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// Available placeholders: ipinfo, ipinfolaravel, ipinfo, ipinfolaravel
return [
'src/MyPackage.php' => 'src/ipinfolaravel.php',
'config/mypackage.php' => 'config/ipinfolaravel.php',
'src/Facades/MyPackage.php' => 'src/Facades/ipinfolaravel.php',
'src/MyPackageServiceProvider.php' => 'src/ipinfolaravelServiceProvider.php',
];
9 changes: 9 additions & 0 deletions rules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// Available placeholders: ipinfo, ipinfolaravel, ipinfo, ipinfolaravel
return [
'src/MyPackage.php' => 'src/ipinfolaravel.php',
'config/mypackage.php' => 'config/ipinfolaravel.php',
'src/Facades/MyPackage.php' => 'src/Facades/ipinfolaravel.php',
'src/MyPackageServiceProvider.php' => 'src/ipinfolaravelServiceProvider.php',
];
18 changes: 18 additions & 0 deletions src/Facades/ipinfolaravel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace ipinfo\ipinfolaravel\Facades;

use Illuminate\Support\Facades\Facade;

class ipinfolaravel extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'ipinfolaravel';
}
}
62 changes: 62 additions & 0 deletions src/ipinfolaravel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace ipinfo\ipinfolaravel;

use Closure;
use ipinfo\ipinfo\IPinfo as IPinfoClient;

class ipinfolaravel
{
/**
* IPinfo API access token.
* @var string
*/
protected $access_token = null;

/**
* IPinfo client object settings.
* @var array
*/
protected $settings = [];

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->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;
}
}
82 changes: 82 additions & 0 deletions src/ipinfolaravelServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace ipinfo\ipinfolaravel;

use Illuminate\Support\ServiceProvider;

class ipinfolaravelServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
// $this->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([]);
}
}

0 comments on commit 623fc9a

Please sign in to comment.