Skip to content

Commit

Permalink
Adding Google Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Feb 19, 2018
1 parent 5ad0f5d commit 124fb16
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 99 deletions.
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"license": "MIT",
"require": {
"php": ">=7.0",
"arcanedev/support": "~4.2.0"
"arcanedev/support": "~4.2.0",
"guzzlehttp/guzzle": "~6.0"
},
"require-dev": {
"orchestra/testbench": "~3.5.0",
"phpunit/phpcov": "~4.0",
"phpunit/phpunit": "~6.0",
"guzzlehttp/guzzle": "~6.0"
"phpunit/phpunit": "~6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -34,8 +34,5 @@
"psr-4": {
"Arcanedev\\GeoLocation\\Tests\\": "tests/"
}
},
"suggest": {
"guzzlehttp/guzzle": "(~6.0) Required if you're going to use the Google webservices."
}
}
47 changes: 47 additions & 0 deletions config/geo-location.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

return [

/* -----------------------------------------------------------------
| Services
| -----------------------------------------------------------------
*/

'services' => [

// GOOGLE
//-----------------------------------------------------
'google' => [

'directions' => [
'service' => Arcanedev\GeoLocation\Google\Directions\DirectionsService::class,
'options' => [
'key' => env('GOOGLE_MAPS_DIRECTIONS_KEY'),
],
],

'distance-matrix' => [
'service' => Arcanedev\GeoLocation\Google\DistanceMatrix\DistanceMatrixService::class,
'options' => [
'key' => env('GOOGLE_MAPS_DISTANCE_MATRIX_KEY'),
],
],

'elevation' => [
'service' => Arcanedev\GeoLocation\Google\Elevation\ElevationService::class,
'options' => [
'key' => env('GOOGLE_MAPS_ELEVATION_KEY'),
],
],

'geocoding' => [
'service' => Arcanedev\GeoLocation\Google\Geocoding\GeocodingService::class,
'options' => [
'key' => env('GOOGLE_MAPS_GEOCODING_KEY'),
],
],
],

],

];
43 changes: 43 additions & 0 deletions src/Contracts/GoogleManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php namespace Arcanedev\GeoLocation\Contracts;

/**
* Interface GoogleManager
*
* @package Arcanedev\GeoLocation\Contracts
* @author ARCANEDEV <[email protected]>
*/
interface GoogleManager
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Create the google directions service.
*
* @return \Arcanedev\GeoLocation\Google\AbstractService
*/
public function createDirectionsDriver();

/**
* Create the google distance matrix service.
*
* @return \Arcanedev\GeoLocation\Google\AbstractService
*/
public function createDistanceMatrixDriver();

/**
* Create the google elevation service.
*
* @return \Arcanedev\GeoLocation\Google\AbstractService
*/
public function createElevationDriver();

/**
* Create the google geocoding service.
*
* @return \Arcanedev\GeoLocation\Google\AbstractService
*/
public function createGeocodingDriver();
}
12 changes: 9 additions & 3 deletions src/GeoLocationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ public function register()
{
parent::register();

//
$this->registerConfig();

$this->bind(\GuzzleHttp\ClientInterface::class, \GuzzleHttp\Client::class);

$this->singleton(Contracts\GoogleManager::class, function ($app) {
return new Google\GoogleManager($app);
});
}

/**
Expand All @@ -44,7 +50,7 @@ public function boot()
{
parent::boot();

//
$this->publishConfig();
}

/**
Expand All @@ -55,7 +61,7 @@ public function boot()
public function provides()
{
return [
//
Contracts\GoogleManager::class,
];
}
}
15 changes: 14 additions & 1 deletion src/Google/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position;
use GuzzleHttp\ClientInterface;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;

/**
Expand Down Expand Up @@ -32,10 +33,12 @@ abstract class AbstractService
* GoogleDistanceMatrix constructor.
*
* @param \GuzzleHttp\ClientInterface $client
* @param array $options
*/
public function __construct(ClientInterface $client)
public function __construct(ClientInterface $client, array $options = [])
{
$this->setHttpClient($client);
$this->setOptions($options);
}

/* -----------------------------------------------------------------
Expand All @@ -57,6 +60,16 @@ public function setHttpClient(ClientInterface $client)
return $this;
}

/**
* Set the options.
*
* @param array $options
*/
protected function setOptions(array $options)
{
$this->setKey(Arr::get($options, 'key'));
}

/**
* Set the API Key.
*
Expand Down
18 changes: 0 additions & 18 deletions src/Google/Directions/DirectionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position;
use Arcanedev\GeoLocation\Google\AbstractService;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\ResponseInterface;

/**
Expand Down Expand Up @@ -41,23 +40,6 @@ class DirectionsService extends AbstractService
*/
protected $destination;

/* -----------------------------------------------------------------
| Constructor
| -----------------------------------------------------------------
*/

/**
* DirectionsService constructor.
*
* @param \GuzzleHttp\ClientInterface $client
*/
public function __construct(ClientInterface $client)
{
parent::__construct($client);

$this->setKey(getenv('GOOGLE_MAPS_DIRECTIONS_KEY'));
}

/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
Expand Down
18 changes: 0 additions & 18 deletions src/Google/DistanceMatrix/DistanceMatrixService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position;
use Arcanedev\GeoLocation\Google\AbstractService;
use GuzzleHttp\ClientInterface;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -37,23 +36,6 @@ class DistanceMatrixService extends AbstractService
/** @var string */
protected $units = 'metric';

/* -----------------------------------------------------------------
| Constructor
| -----------------------------------------------------------------
*/

/**
* GoogleDistanceMatrix constructor.
*
* @param \GuzzleHttp\ClientInterface $client
*/
public function __construct(ClientInterface $client)
{
parent::__construct($client);

$this->setKey(getenv('GOOGLE_MAPS_DISTANCE_MATRIX_KEY'));
}

/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
Expand Down
18 changes: 0 additions & 18 deletions src/Google/Elevation/ElevationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position as PositionContract;
use Arcanedev\GeoLocation\Google\AbstractService;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\ResponseInterface;

/**
Expand All @@ -20,23 +19,6 @@ class ElevationService extends AbstractService

const BASE_URL = 'https://maps.googleapis.com/maps/api/elevation/json';

/* -----------------------------------------------------------------
| Constructor
| -----------------------------------------------------------------
*/

/**
* ElevationService constructor.
*
* @param \GuzzleHttp\ClientInterface $client
*/
public function __construct(ClientInterface $client)
{
parent::__construct($client);

$this->setKey(getenv('GOOGLE_MAPS_ELEVATION_KEY'));
}

/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
Expand Down
18 changes: 0 additions & 18 deletions src/Google/Geocoding/GeocodingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position as PositionContract;
use Arcanedev\GeoLocation\Entities\Coordinates\Position;
use Arcanedev\GeoLocation\Google\AbstractService;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\ResponseInterface;

/**
Expand All @@ -23,23 +22,6 @@ class GeocodingService extends AbstractService

const BASE_URL = 'https://maps.googleapis.com/maps/api/geocode/json';

/* -----------------------------------------------------------------
| Constructor
| -----------------------------------------------------------------
*/

/**
* GoogleDistanceMatrix constructor.
*
* @param \GuzzleHttp\ClientInterface $client
*/
public function __construct(ClientInterface $client)
{
parent::__construct($client);

$this->setKey(getenv('GOOGLE_MAPS_GEOCODING_KEY'));
}

/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
Expand Down
Loading

0 comments on commit 124fb16

Please sign in to comment.