-
Notifications
You must be signed in to change notification settings - Fork 0
feat(laravel-google-maps-client): add GoogleMaps services #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abenevaut
wants to merge
3
commits into
master
Choose a base branch
from
feat/googlemap-service
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'api_key' => env('GOOGLE_MAPS_API_KEY'), | ||
| 'places' => [ | ||
| 'debug' => env('APP_DEBUG', false), | ||
| ], | ||
| 'timezones' => [ | ||
| 'debug' => env('APP_DEBUG', false), | ||
| ], | ||
| ]; | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,7 +3,3 @@ | |
| ## Build | ||
|
|
||
| Maintain composer packages with php 8.3 | ||
|
|
||
| ```bash | ||
| docker-compose up -d | ||
| ``` | ||
This file contains hidden or 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
This file contains hidden or 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,40 @@ | ||
| <?php | ||
|
|
||
| namespace abenevaut\GoogleMaps\Client; | ||
|
|
||
| use abenevaut\Infrastructure\Client\AuthenticatedClientAbstract; | ||
| use abenevaut\Infrastructure\Client\AccessTokenInterface; | ||
|
|
||
| final class TimezonesClient extends AuthenticatedClientAbstract | ||
| { | ||
| public function __construct( | ||
| AccessTokenInterface $accessToken, | ||
| bool $debug = false | ||
| ) { | ||
| parent::__construct( | ||
| 'https://maps.googleapis.com/maps/api/timezone', | ||
| $accessToken, | ||
| $debug | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * https://developers.google.com/maps/documentation/timezone/requests-timezone?hl=fr | ||
| * | ||
| * @return array | ||
| * @throws \Illuminate\Http\Client\ConnectionException | ||
| * @throws \Illuminate\Http\Client\RequestException | ||
| */ | ||
| public function searchTimezone(float $lat, float $lng, $timestamp): array | ||
| { | ||
| return $this | ||
| ->request() | ||
| ->get('/json', [ | ||
| 'location' => "{$lat},{$lng}", | ||
| 'timestamp' => $timestamp, | ||
| 'key' => $this->accessToken->getAccessToken(), | ||
| ]) | ||
| ->throw() | ||
| ->json(); | ||
| } | ||
| } |
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
laravel-google-maps-client/src/Infrastructure/GoogleMapsServiceInterface.php
This file contains hidden or 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,10 @@ | ||
| <?php | ||
|
|
||
| namespace abenevaut\GoogleMaps\Infrastructure; | ||
|
|
||
| use abenevaut\Infrastructure\Client\ClientAbstract; | ||
|
|
||
| interface GoogleMapsServiceInterface | ||
| { | ||
| public function getClient(): ClientAbstract; | ||
| } |
This file contains hidden or 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
44 changes: 44 additions & 0 deletions
44
laravel-google-maps-client/src/Services/GoogleMapsServiceFactory.php
This file contains hidden or 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,44 @@ | ||
| <?php | ||
|
|
||
| namespace abenevaut\GoogleMaps\Services; | ||
|
|
||
| final class GoogleMapsServiceFactory | ||
| { | ||
| public function __construct( | ||
| protected readonly array $applicationResolver, | ||
| private readonly array $services | ||
| ) { | ||
| } | ||
|
|
||
| public function services(): array | ||
| { | ||
| return $this->services; | ||
| } | ||
|
|
||
| public function service(string $driver): object | ||
| { | ||
| if (!in_array($driver, $this->services())) { | ||
| throw new \RuntimeException("Driver doesn't exist."); | ||
abenevaut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| $driver = ucfirst($driver); | ||
|
|
||
| return $this->resolve("{$driver}Service"); | ||
| } | ||
|
|
||
| public function classResolution(string $driver): string | ||
| { | ||
| if (!in_array($driver, $this->services())) { | ||
| throw new \RuntimeException("Driver doesn't exist."); | ||
| } | ||
|
|
||
| $driver = ucfirst($driver); | ||
|
|
||
| return "\abenevaut\GoogleMaps\Services\{$driver}Service"; | ||
| } | ||
|
|
||
| protected function resolve(string $driver): object | ||
| { | ||
| return call_user_func($this->applicationResolver, $driver); | ||
| } | ||
| } | ||
This file contains hidden or 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,24 @@ | ||
| <?php | ||
|
|
||
| namespace abenevaut\GoogleMaps\Services; | ||
|
|
||
| use abenevaut\GoogleMaps\Client\PlacesClient; | ||
| use abenevaut\GoogleMaps\Infrastructure\GoogleMapsServiceInterface; | ||
| use abenevaut\Infrastructure\Client\{AccessTokenInterface, ClientAbstract}; | ||
|
|
||
| final class PlacesService implements GoogleMapsServiceInterface | ||
| { | ||
| protected PlacesClient $client; | ||
|
|
||
| public function __construct( | ||
| AccessTokenInterface $accessToken, | ||
| bool $debug = false | ||
| ) { | ||
| $this->client = new PlacesClient($accessToken, $debug); | ||
| } | ||
|
|
||
| public function getClient(): ClientAbstract | ||
| { | ||
| return $this->client; | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
laravel-google-maps-client/src/Services/TimezonesService.php
This file contains hidden or 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,24 @@ | ||
| <?php | ||
|
|
||
| namespace abenevaut\GoogleMaps\Services; | ||
|
|
||
| use abenevaut\GoogleMaps\Client\TimezonesClient; | ||
| use abenevaut\GoogleMaps\Infrastructure\GoogleMapsServiceInterface; | ||
| use abenevaut\Infrastructure\Client\{AccessTokenInterface, ClientAbstract}; | ||
|
|
||
| final class TimezonesService implements GoogleMapsServiceInterface | ||
| { | ||
| protected TimezonesClient $client; | ||
|
|
||
| public function __construct( | ||
| AccessTokenInterface $accessToken, | ||
| bool $debug = false | ||
| ) { | ||
| $this->client = new TimezonesClient($accessToken, $debug); | ||
| } | ||
|
|
||
| public function getClient(): ClientAbstract | ||
| { | ||
| return $this->client; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.