Skip to content

Commit 40102f3

Browse files
author
Martin Brecht-Precht
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # README.md # composer.json # src/Lookup/AbstractLookup.php
2 parents 22e778d + 10bd7f3 commit 40102f3

7 files changed

+34
-4
lines changed

.codeclimate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ ratings:
2525
- "**.rb"
2626
exclude_paths:
2727
- test/
28-
- vendor/
28+
- vendor/

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ php:
99
- '5.4'
1010
- '5.5'
1111
- '7.0'
12+
- '7.1'
1213
- hhvm
1314

1415
matrix:

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,20 @@ require_once('path/to/vendor/autoload.php');
3434

3535
#### Resolving an address
3636

37+
The API provides an optional usage of an API key to circumvent API quota limits. Please visit the [Google API console](https://console.developers.google.com/apis/api/geocoding_backend?project=_) to receive an API key.
38+
3739
```{php}
3840
use ChromaX\CommonException;
3941
4042
try{
4143
// Perform lookup
4244
$addressLookup = new ChromaX\GoogleGeocode\Lookup\AddressLookup();
45+
$addressLookup = new Markenwerk\GoogleGeocode\Lookup\AddressLookup();
46+
47+
// Optional adding an API key
48+
$addressLookup->setApiKey('MY_GOOGLE_GEOCODING_API_KEY');
49+
50+
// Submit lookup
4351
$addressLookup->lookup('Germany, 24105 Kiel, Lornsenstraße 43');
4452
4553
// Retrieving the lookup as an array of ChromaX\GoogleGeocode\Result\GeoLookupResult instances
@@ -65,12 +73,20 @@ try{
6573

6674
#### Resolving a geo location
6775

76+
The API provides an optional usage of an API key to circumvent API quota limits. Please visit the [Google API console](https://console.developers.google.com/apis/api/geocoding_backend?project=_) to receive an API key.
77+
6878
```{php}
6979
use ChromaX\CommonException;
7080
7181
try{
7282
// Perform lookup
7383
$geoLocationLookup = new ChromaX\GoogleGeocode\Lookup\GeoLocationLookup();
84+
$geoLocationLookup = new Markenwerk\GoogleGeocode\Lookup\GeoLocationLookup();
85+
86+
// Optional adding an API key
87+
$geoLocationLookup->setApiKey('MY_GOOGLE_GEOCODING_API_KEY');
88+
89+
// Submit lookup
7490
$geoLocationLookup->lookup(54.334123, 10.1364007);
7591
7692
// Retrieving the lookup as an array of ChromaX\GoogleGeocode\Result\GeoLookupResult instances

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
</exclude>
1515
</whitelist>
1616
</filter>
17-
</phpunit>
17+
</phpunit>

src/Lookup/AbstractApiKeyGatedLookup.php

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public function getApiKey()
2525
return $this->apiKey;
2626
}
2727

28+
/**
29+
* @return bool
30+
*/
31+
public function hasApiKey()
32+
{
33+
return !is_null($this->apiKey);
34+
}
35+
2836
/**
2937
* @param string $apiKey
3038
* @return $this
@@ -43,6 +51,9 @@ public function setApiKey($apiKey)
4351
*/
4452
protected function addApiKey($url)
4553
{
54+
if (!$this->hasApiKey()) {
55+
return $url;
56+
}
4657
return $url . '&key=' . $this->getApiKey();
4758
}
4859

src/Lookup/AddressLookup.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @package ChromaX\GoogleGeocode\Lookup
1111
*/
12-
class AddressLookup extends AbstractLookup
12+
class AddressLookup extends AbstractApiKeyGatedLookup
1313
{
1414

1515
/**
@@ -24,6 +24,7 @@ class AddressLookup extends AbstractLookup
2424
public function lookup($address)
2525
{
2626
$requestUrl = self::API_BASE_URL . $this->encodeUrlParameter($address);
27+
$requestUrl = $this->addApiKey($requestUrl);
2728
$responseData = $this->request($requestUrl);
2829
$this
2930
->clearResults()

src/Lookup/GeoLocationLookup.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @package ChromaX\GoogleGeocode\Lookup
1111
*/
12-
class GeoLocationLookup extends AbstractLookup
12+
class GeoLocationLookup extends AbstractApiKeyGatedLookup
1313
{
1414

1515
/**
@@ -25,6 +25,7 @@ class GeoLocationLookup extends AbstractLookup
2525
public function lookup($latitude, $longitude)
2626
{
2727
$requestUrl = self::API_BASE_URL . $this->encodeUrlParameter($latitude . ',' . $longitude);
28+
$requestUrl = $this->addApiKey($requestUrl);
2829
$responseData = $this->request($requestUrl);
2930
$this
3031
->clearResults()

0 commit comments

Comments
 (0)