Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinAgarwal1337 committed Mar 13, 2019
2 parents c9628d6 + f359171 commit a50983a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ With just 2 lines of code you can request to any google places api feature. No n
* [Place Autocomplete](#place-autocomplete) This service is Used to automatically fill in the name and/or address of a place as you type.
* [Query Autocomplete](#query-autocomplete) This service is Used to provide a query prediction service for text-based geographic searches, by returning suggested queries as you type.
* [Place Photo](#place-photo) This gives you access to the millions of photos stored in the Google's Places database
* [Custom Headers](#custom-headers) Set Custom Headers.
* [Additional Methods](#additional-methods) Additional Methods Available.

# Installation
Expand Down Expand Up @@ -168,6 +169,18 @@ If you are not familiar with <em>Laravel's Collection</em> you can either refere

---

<a name=custom-headers></a>
# Custom Headers
### withHeaders(array $headers)
Call This method before any other methods to set the headers. You can chain this method.

### new PlacesApi($key = null, $verifySSL = true, array $headers = [])
To have custom headers set for every call, you can pass 3rd parameter as the headers to class constructor.

**Note:** For Laravel Users, you can set this in config file with key `headers`

---

<a name=additional-methods></a>
# Additional Methods
### getStatus()
Expand All @@ -182,6 +195,8 @@ This will set the `API KEY`.
### verifySSL($verifySSL = true)
You can pass `false` to disable Verification of SSL Certification.

**Note:** For Laravel Users, you can set this in config file with key `verify_ssl`

Or You can Pass the path to the certificate.

# Contribution
Expand Down
2 changes: 2 additions & 0 deletions config/google.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
return [
'places' => [
'key' => env('GOOGLE_PLACES_API_KEY', null),
'verify_ssl' => true,
'headers' => []
],
];
30 changes: 25 additions & 5 deletions src/PlacesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class PlacesApi

const PLACE_PHOTO_URL = 'photo';



/**
* @var
*/
Expand All @@ -50,20 +48,26 @@ class PlacesApi
*/
private $verifySSL = true;

/**
* @var array
*/
private $headers = [];

/**
* PlacesApi constructor.
*
* @param null $key
* @param bool $verifySSL
*/
public function __construct($key = null, $verifySSL = true)
public function __construct($key = null, $verifySSL = true, array $headers = [])
{
$this->key = $key;

$this->verifySSL = $verifySSL;

$this->client = new Client([
'base_uri' => self::BASE_URL,
'headers' => $headers,
]);
}

Expand Down Expand Up @@ -177,7 +181,7 @@ public function photo($photoReference, $params = [])

$this->client->get(self::PLACE_PHOTO_URL, $options);

return (string) $url;
return (string)$url;
}

/**
Expand Down Expand Up @@ -381,6 +385,22 @@ private function getOptions($params, $method = 'get')

$options['verify'] = $this->verifySSL;

if (!empty($this->headers)) {
$options['headers'] = $this->headers;
}

return $options;
}

/**
* @param array $headers
*
* @return PlacesApi
*/
public function withHeaders(array $headers)
{
$this->headers = $headers;

return $this;
}
}
8 changes: 7 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ public function register()
$this->app->singleton('GooglePlaces', function ($app) {
$key = isset($app['config']['google.places.key'])
? $app['config']['google.places.key'] : null;

$verifySSL = isset($app['config']['google.places.verify_ssl'])
? $app['config']['google.places.verify_ssl'] : true;

$headers = isset($app['config']['google.places.headers'])
? $app['config']['google.places.headers'] : [];

return new PlacesApi($key);
return new PlacesApi($key, $verifySSL, $headers);
});
}

Expand Down

0 comments on commit a50983a

Please sign in to comment.