composer update

This commit is contained in:
Manish Verma
2018-12-05 10:50:52 +05:30
parent 9eabcacfa7
commit 4addd1e9c6
3328 changed files with 156676 additions and 138988 deletions

View File

@@ -19,6 +19,10 @@ class GeoIPServiceProvider extends ServiceProvider
$this->registerResources();
$this->registerGeoIpCommands();
}
if ($this->isLumen() === false) {
$this->mergeConfigFrom(__DIR__ . '/../config/geoip.php', 'geoip');
}
}
/**
@@ -72,4 +76,4 @@ class GeoIPServiceProvider extends ServiceProvider
{
return str_contains($this->app->version(), 'Lumen') === true;
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace Torann\GeoIP\Services;
use Exception;
use Torann\GeoIP\Support\HttpClient;
/**
* Class GeoIP
* @package Torann\GeoIP\Services
*/
class IPData extends AbstractService
{
/**
* Http client instance.
*
* @var HttpClient
*/
protected $client;
/**
* The "booting" method of the service.
*
* @return void
*/
public function boot()
{
$this->client = new HttpClient([
'base_uri' => 'https://api.ipdata.co/',
'query' => [
'api-key' => $this->config('key'),
],
]);
}
/**
* {@inheritdoc}
* @throws Exception
*/
public function locate($ip)
{
// Get data from client
$data = $this->client->get($ip);
// Verify server response
if ($this->client->getErrors() !== null || empty($data[0])) {
throw new Exception('Request failed (' . $this->client->getErrors() . ')');
}
return $this->hydrate(json_decode($data[0], true));
}
}