From f3beb5b01177774ae98ae53eccb9018dac9967dd Mon Sep 17 00:00:00 2001 From: fabio Date: Tue, 22 Apr 2014 18:35:54 -0300 Subject: [PATCH 01/14] Error in component --- src/GoogleMaps/Parameters/ComponentParameter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GoogleMaps/Parameters/ComponentParameter.php b/src/GoogleMaps/Parameters/ComponentParameter.php index 87a50da..4c23377 100644 --- a/src/GoogleMaps/Parameters/ComponentParameter.php +++ b/src/GoogleMaps/Parameters/ComponentParameter.php @@ -2,7 +2,7 @@ /** * This file is part of Geoxygen * - * (c) 2012 Cédric DERUE + * (c) 2012 C�dric DERUE * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -79,6 +79,6 @@ public function getValue() */ public function toString() { - return $this->key . '|' . $this->value(); + return $this->key . '|' . $this->value; } } \ No newline at end of file From bd31f348d155984d6b9da6653607d1a626f2868a Mon Sep 17 00:00:00 2001 From: fabio Date: Tue, 22 Apr 2014 18:59:11 -0300 Subject: [PATCH 02/14] composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4ac0eda..741ba4b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "cderue/googlemaps", + "name": "pandora-una/googlemaps", "description": "A Zend Framework module that provides a PHP wrapper to the Google Maps Geocoding API", "type": "module", "keywords": [], From 256fd70877c9adff7af84216b68abed5834c9c05 Mon Sep 17 00:00:00 2001 From: fabio Date: Tue, 22 Apr 2014 19:07:46 -0300 Subject: [PATCH 03/14] voltando --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 741ba4b..4ac0eda 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "pandora-una/googlemaps", + "name": "cderue/googlemaps", "description": "A Zend Framework module that provides a PHP wrapper to the Google Maps Geocoding API", "type": "module", "keywords": [], From 9cb7e367361b575ae827abbea2045d449c4721af Mon Sep 17 00:00:00 2001 From: fabio Date: Tue, 22 Apr 2014 19:18:22 -0300 Subject: [PATCH 04/14] charset --- src/GoogleMaps/Parameters/ComponentParameter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GoogleMaps/Parameters/ComponentParameter.php b/src/GoogleMaps/Parameters/ComponentParameter.php index 4c23377..872932b 100644 --- a/src/GoogleMaps/Parameters/ComponentParameter.php +++ b/src/GoogleMaps/Parameters/ComponentParameter.php @@ -2,7 +2,7 @@ /** * This file is part of Geoxygen * - * (c) 2012 C�dric DERUE + * (c) 2012 Cédric DERUE * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. From ebae0edbc10ec774cddef605d8ad04f08b2eb473 Mon Sep 17 00:00:00 2001 From: fabio Date: Tue, 22 Apr 2014 19:47:25 -0300 Subject: [PATCH 05/14] Component in required and optional --- src/GoogleMaps/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GoogleMaps/Request.php b/src/GoogleMaps/Request.php index 450a739..0e5287c 100644 --- a/src/GoogleMaps/Request.php +++ b/src/GoogleMaps/Request.php @@ -2,7 +2,7 @@ /** * This file is part of Geoxygen * - * (c) 2012 Cédric DERUE + * (c) 2012 C�dric DERUE * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -199,7 +199,7 @@ public function setSensor($sensor) public function getUrlParameters() { $requiredParameters = array('address', 'latlng', 'components', 'sensor'); - $optionalParameters = array('bounds', 'language', 'region', 'components'); + $optionalParameters = array('bounds', 'language', 'region'); $url = ''; foreach ($requiredParameters as $parameter) { From de445686a26daa8339a347e3116cc1978e069412 Mon Sep 17 00:00:00 2001 From: fabio Date: Tue, 22 Apr 2014 19:56:02 -0300 Subject: [PATCH 06/14] Error in components parameter --- src/GoogleMaps/Parameters/ComponentParameter.php | 2 +- src/GoogleMaps/Parameters/ComponentSetParameter.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GoogleMaps/Parameters/ComponentParameter.php b/src/GoogleMaps/Parameters/ComponentParameter.php index 872932b..b83a5e5 100644 --- a/src/GoogleMaps/Parameters/ComponentParameter.php +++ b/src/GoogleMaps/Parameters/ComponentParameter.php @@ -79,6 +79,6 @@ public function getValue() */ public function toString() { - return $this->key . '|' . $this->value; + return $this->key . ':' . $this->value; } } \ No newline at end of file diff --git a/src/GoogleMaps/Parameters/ComponentSetParameter.php b/src/GoogleMaps/Parameters/ComponentSetParameter.php index 931acf9..bbd3866 100644 --- a/src/GoogleMaps/Parameters/ComponentSetParameter.php +++ b/src/GoogleMaps/Parameters/ComponentSetParameter.php @@ -2,7 +2,7 @@ /** * This file is part of Geoxygen * - * (c) 2012 Cédric DERUE + * (c) 2012 C�dric DERUE * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -27,8 +27,10 @@ public function __construct() */ public function toString() { - $components = null; + $components = null; foreach ($this->collection as $element) { + if (isset($components)) + $components .= '|'; $components .= $element->toString(); } return $components; From c6b4b6e2b9f9ae8f00a62b1a729eb1f200433f17 Mon Sep 17 00:00:00 2001 From: fabio Date: Tue, 22 Apr 2014 20:05:16 -0300 Subject: [PATCH 07/14] Urlencoded error --- src/GoogleMaps/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GoogleMaps/Request.php b/src/GoogleMaps/Request.php index 0e5287c..724a0a7 100644 --- a/src/GoogleMaps/Request.php +++ b/src/GoogleMaps/Request.php @@ -212,7 +212,7 @@ public function getUrlParameters() if (is_object($requiredParam)) { $requiredParam = $requiredParam->toString(); } - $url .= $parameter . '=' . urlencode($requiredParam); + $url .= $parameter . '=' . $requiredParam; } } if ($url === '') { @@ -226,7 +226,7 @@ public function getUrlParameters() if (is_object($optionParam)) { $optionParam = $optionParam->toString(); } - $url .= '&' . $option . '=' . urlencode($optionParam); + $url .= '&' . $option . '=' . $optionParam; } } return $url; From 2ccc03066825f9de2f05d9403eaf95f14f11f75e Mon Sep 17 00:00:00 2001 From: "fabio.ginzel" Date: Thu, 12 Jun 2014 05:41:56 -0300 Subject: [PATCH 08/14] Schema of request --- src/GoogleMaps/Geocoder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GoogleMaps/Geocoder.php b/src/GoogleMaps/Geocoder.php index 7da2655..425701a 100644 --- a/src/GoogleMaps/Geocoder.php +++ b/src/GoogleMaps/Geocoder.php @@ -93,6 +93,7 @@ public function geocode(Request $request) throw new Exception\InvalidArgumentException('request'); } $uri = new Uri(); + $uri->setScheme('http'); $uri->setHost(self::GOOGLE_MAPS_APIS_URL); $uri->setPath(self::GOOGLE_GEOCODING_API_PATH); @@ -130,4 +131,4 @@ public function geocode(Request $request) return $response; } -} \ No newline at end of file +} From b00382eea2704fae5fa8c59996c54882b71865ba Mon Sep 17 00:00:00 2001 From: "fabio.ginzel" Date: Thu, 12 Jun 2014 08:18:31 -0300 Subject: [PATCH 09/14] setHttpClient --- src/GoogleMaps/Geocoder.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/GoogleMaps/Geocoder.php b/src/GoogleMaps/Geocoder.php index 425701a..8772d51 100644 --- a/src/GoogleMaps/Geocoder.php +++ b/src/GoogleMaps/Geocoder.php @@ -78,7 +78,13 @@ public function getHttpClient() } return $this->httpClient; } + + public function setHttpClient(HttpClient $httpClient) + { + $this->httpClient = httpClient; + return $this; + } /** From d9589578a7e2c639aa74014ff4a2ad6358c94ba2 Mon Sep 17 00:00:00 2001 From: "fabio.ginzel" Date: Thu, 12 Jun 2014 08:24:26 -0300 Subject: [PATCH 10/14] Syntax error --- src/GoogleMaps/Geocoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GoogleMaps/Geocoder.php b/src/GoogleMaps/Geocoder.php index 8772d51..6d45025 100644 --- a/src/GoogleMaps/Geocoder.php +++ b/src/GoogleMaps/Geocoder.php @@ -82,7 +82,7 @@ public function getHttpClient() public function setHttpClient(HttpClient $httpClient) { - $this->httpClient = httpClient; + $this->httpClient = $httpClient; return $this; } From f5cdad1badbd699bc12b9d8d3dd16eab8a6639ec Mon Sep 17 00:00:00 2001 From: "fabio.ginzel" Date: Thu, 12 Jun 2014 08:36:54 -0300 Subject: [PATCH 11/14] Add Language --- src/GoogleMaps/Geocoder.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/GoogleMaps/Geocoder.php b/src/GoogleMaps/Geocoder.php index 6d45025..a10c997 100644 --- a/src/GoogleMaps/Geocoder.php +++ b/src/GoogleMaps/Geocoder.php @@ -40,6 +40,10 @@ class Geocoder */ protected $httpClient; + + + protected $language; + /** * * @param string $format @@ -57,6 +61,14 @@ public function __construct($format = 'json') $this->format = $format; } + public function getLanguage() { + return $this->language; + } + public function setLanguage($language) { + $this->language = $language; + return $this; + } + /** * * @return string @@ -112,6 +124,9 @@ public function geocode(Request $request) $client = $this->getHttpClient(); $client->resetParameters(); $client->setUri($uri->toString()); + if ($this->getLanguage()) + $client->setHeaders(array('Accept-Language',$this->getLanguage())); + $stream = $client->send(); $body = Json::decode($stream->getBody(), Json::TYPE_ARRAY); From 4b125d09f566a4a45eb4e3309b75d4ca1eb1a15c Mon Sep 17 00:00:00 2001 From: "fabio.ginzel" Date: Thu, 12 Jun 2014 08:41:53 -0300 Subject: [PATCH 12/14] Syntax Error --- src/GoogleMaps/Geocoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GoogleMaps/Geocoder.php b/src/GoogleMaps/Geocoder.php index a10c997..2ba6501 100644 --- a/src/GoogleMaps/Geocoder.php +++ b/src/GoogleMaps/Geocoder.php @@ -125,7 +125,7 @@ public function geocode(Request $request) $client->resetParameters(); $client->setUri($uri->toString()); if ($this->getLanguage()) - $client->setHeaders(array('Accept-Language',$this->getLanguage())); + $client->setHeaders(array('Accept-Language'=>$this->getLanguage())); $stream = $client->send(); From 7b57e1522da7dff17acae6a475b727c613454d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius?= Date: Thu, 6 Dec 2018 14:58:59 -0200 Subject: [PATCH 13/14] =?UTF-8?q?Aceita=20chave=20da=20API=20como=20par?= =?UTF-8?q?=C3=A2metro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GoogleMaps/Request.php | 454 +++++++++++++++++++------------------ 1 file changed, 239 insertions(+), 215 deletions(-) diff --git a/src/GoogleMaps/Request.php b/src/GoogleMaps/Request.php index 724a0a7..a396869 100644 --- a/src/GoogleMaps/Request.php +++ b/src/GoogleMaps/Request.php @@ -1,4 +1,5 @@ sensor = $sensor; - } - - /** - * @return the $address - */ - public function getAddress() - { - return $this->address; - } - - /** - * @param string $address - */ - public function setAddress($address) - { - $this->address = $address; - } - - /** - * @return the $latLng - */ - public function getLatLng() - { - return $this->latLng; - } - - /** - * @param LatLngParameter $latLng - */ - public function setLatLng(LatLngParameter $latLng) - { - $this->latLng = $latLng; - } - - /** - * @return the $bounds - */ - public function getBounds() - { - return $this->bounds; - } - - /** - * @param LatLngBoundsParameter $bounds - */ - public function setBounds(LatLngBoundsParameter $bounds) - { - $this->bounds = $bounds; - } - - /** - * @return the $language - */ - public function getLanguage() - { - return $this->language; - } - - /** - * @param string $language - */ - public function setLanguage($language) - { - $this->language = $language; - } - - /** - * @return the $region - */ - public function getRegion() - { - return $this->region; - } - - /** - * @param string $region - */ - public function setRegion($region) - { - $this->region = $region; - } - - /** - * @return the $components - */ - public function getComponents() - { - return $this->components; - } - - /** - * @param \GoogleMaps\unknown_type $componentsFilter - */ - public function setComponents(ComponentSetParameter $components) - { - $this->components = $components; - } - - /** - * @return the $sensor - */ - public function getSensor() - { - return $this->sensor; - } - - /** - * @param boolean $sensor - */ - public function setSensor($sensor) - { - $this->sensor = $sensor; - } - - /** - * Tranform request to URL parameters - * - * @return NULL|string - */ - public function getUrlParameters() - { - $requiredParameters = array('address', 'latlng', 'components', 'sensor'); - $optionalParameters = array('bounds', 'language', 'region'); - - $url = ''; - foreach ($requiredParameters as $parameter) { - $method = 'get' . $parameter; - $requiredParam = $this->$method(); - if (isset($requiredParam)) { - if ($url !== '') { - $url .= '&'; - } - if (is_object($requiredParam)) { - $requiredParam = $requiredParam->toString(); - } - $url .= $parameter . '=' . $requiredParam; - } - } - if ($url === '') { - return null; - } - - foreach ($optionalParameters as $option) { - $method = 'get' . $option; - $optionParam = $this->$method(); - if (!empty($optionParam)) { - if (is_object($optionParam)) { - $optionParam = $optionParam->toString(); - } - $url .= '&' . $option . '=' . $optionParam; - } - } - return $url; - } -} \ No newline at end of file + const SENSOR = 'true'; + const NO_SENSOR = 'false'; + + /** + * Address to perform geocoding (required) + * + * @var string + */ + protected $address; + + /** + * Latitude / longitude to perform reverse geocoding (required) + * + * @var LatLng + */ + protected $latLng; + + /** + * Components filter to perform geocoding (optional if an address is provided else required) + * + * @var array + */ + protected $components; + + /** + * Indicates if the request is provided by a device with a location sensor (required) + * + * @var boolean + */ + protected $sensor; + + /** + * Bounding box to limit results within a given viewport (optional) + * + * @var LatLngBounds + */ + protected $bounds; + + /** + * Region code (ccTLD or ISO-3166-1 value) to limit results within a particular region (optional) + * + * @var string + */ + protected $region; + + /** + * Specify the language in which to return results + * + * @var string + */ + protected $language; + + /** + * Google API key + * + * @var string + */ + protected $key; + + /** + * Contructor + * + * @param boolean $sensor + */ + public function __construct($sensor = self::NO_SENSOR) + { + $this->sensor = $sensor; + } + + /** + * @return the $address + */ + public function getAddress() + { + return $this->address; + } + + /** + * @param string $address + */ + public function setAddress($address) + { + $this->address = $address; + } + + /** + * @return the $latLng + */ + public function getLatLng() + { + return $this->latLng; + } + + /** + * @param LatLngParameter $latLng + */ + public function setLatLng(LatLngParameter $latLng) + { + $this->latLng = $latLng; + } + + /** + * @return the $bounds + */ + public function getBounds() + { + return $this->bounds; + } + + /** + * @param LatLngBoundsParameter $bounds + */ + public function setBounds(LatLngBoundsParameter $bounds) + { + $this->bounds = $bounds; + } + + /** + * @return the $language + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @param string $language + */ + public function setLanguage($language) + { + $this->language = $language; + } + + /** + * @return the $region + */ + public function getRegion() + { + return $this->region; + } + + /** + * @param string $region + */ + public function setRegion($region) + { + $this->region = $region; + } + + /** + * @return the $components + */ + public function getComponents() + { + return $this->components; + } + + /** + * @param \GoogleMaps\unknown_type $componentsFilter + */ + public function setComponents(ComponentSetParameter $components) + { + $this->components = $components; + } + + /** + * @return the $sensor + */ + public function getSensor() + { + return $this->sensor; + } + + /** + * @param boolean $sensor + */ + public function setSensor($sensor) + { + $this->sensor = $sensor; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param string $key Google API key + */ + public function setKey($key) + { + $this->key = $key; + } + + /** + * Tranform request to URL parameters + * + * @return NULL|string + */ + public function getUrlParameters() + { + $requiredParameters = array('address', 'latlng', 'components', 'sensor'); + $optionalParameters = array('bounds', 'language', 'region', 'key'); + + $url = ''; + foreach ($requiredParameters as $parameter) { + $method = 'get' . $parameter; + $requiredParam = $this->$method(); + if (isset($requiredParam)) { + if ($url !== '') { + $url .= '&'; + } + if (is_object($requiredParam)) { + $requiredParam = $requiredParam->toString(); + } + $url .= $parameter . '=' . $requiredParam; + } + } + if ($url === '') { + return null; + } + + foreach ($optionalParameters as $option) { + $method = 'get' . $option; + $optionParam = $this->$method(); + if (!empty($optionParam)) { + if (is_object($optionParam)) { + $optionParam = $optionParam->toString(); + } + $url .= '&' . $option . '=' . $optionParam; + } + } + return $url; + } +} From b96d1f0c86572c537704d594a6bbb8b751b813d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius?= Date: Thu, 6 Dec 2018 15:12:41 -0200 Subject: [PATCH 14/14] =?UTF-8?q?Manda=20requisi=C3=A7=C3=A3o=20em=20https?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GoogleMaps/Geocoder.php | 265 ++++++++++++++++++------------------ 1 file changed, 135 insertions(+), 130 deletions(-) diff --git a/src/GoogleMaps/Geocoder.php b/src/GoogleMaps/Geocoder.php index 2ba6501..10472c8 100644 --- a/src/GoogleMaps/Geocoder.php +++ b/src/GoogleMaps/Geocoder.php @@ -1,8 +1,9 @@ + * (c) 2012 C�dric DERUE * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,137 +20,141 @@ use Zend\Uri\Uri; -class Geocoder +class Geocoder { - const GOOGLE_MAPS_APIS_URL = 'maps.googleapis.com'; - const GOOGLE_GEOCODING_API_PATH = '/maps/api/geocode/json'; - const XML_FORMAT = 'xml'; - const JSON_FORMAT = 'json'; - - /** - * Response format (XML or JSON) - * - * @var string - */ - protected $format; - - /** - * Http client - * - * @var HttpClient - */ - protected $httpClient; - - - - protected $language; - - /** - * - * @param string $format - * @throws Exception\InvalidArgumentException - */ - public function __construct($format = 'json') - { - $validFormats = array( - self::JSON_FORMAT, - self::XML_FORMAT, - ); - if (!in_array($format, $validFormats)) { - throw new Exception\InvalidArgumentException('format'); - } - $this->format = $format; - } - - public function getLanguage() { - return $this->language; - } - public function setLanguage($language) { - $this->language = $language; - return $this; - } - - /** - * - * @return string - */ - public function getFormat() - { - return $this->format; - } - - /** - * Get the HttpClient instance - * - * @return HttpClient - */ - public function getHttpClient() - { - if (empty($this->httpClient)) { + const GOOGLE_MAPS_APIS_URL = 'maps.googleapis.com'; + const GOOGLE_GEOCODING_API_PATH = '/maps/api/geocode/json'; + const XML_FORMAT = 'xml'; + const JSON_FORMAT = 'json'; + + /** + * Response format (XML or JSON) + * + * @var string + */ + protected $format; + + /** + * Http client + * + * @var HttpClient + */ + protected $httpClient; + + + + protected $language; + + /** + * + * @param string $format + * @throws Exception\InvalidArgumentException + */ + public function __construct($format = 'json') + { + $validFormats = array( + self::JSON_FORMAT, + self::XML_FORMAT, + ); + if (!in_array($format, $validFormats)) { + throw new Exception\InvalidArgumentException('format'); + } + $this->format = $format; + } + + public function getLanguage() + { + return $this->language; + } + public function setLanguage($language) + { + $this->language = $language; + return $this; + } + + /** + * + * @return string + */ + public function getFormat() + { + return $this->format; + } + + /** + * Get the HttpClient instance + * + * @return HttpClient + */ + public function getHttpClient() + { + if (empty($this->httpClient)) { $this->httpClient = new HttpClient(); } return $this->httpClient; - } - - - public function setHttpClient(HttpClient $httpClient) - { - $this->httpClient = $httpClient; - return $this; - } - - - /** - * Execute geocoding - * - * @param Request $request - * @return Response - */ - public function geocode(Request $request) - { - if (null === $request) { - throw new Exception\InvalidArgumentException('request'); - } - $uri = new Uri(); - $uri->setScheme('http'); - $uri->setHost(self::GOOGLE_MAPS_APIS_URL); - $uri->setPath(self::GOOGLE_GEOCODING_API_PATH); - - $urlParameters = $request->getUrlParameters(); - if (null === $urlParameters) { - throw new Exception\RuntimeException('Invalid URL parameters'); - } - - $uri->setQuery($urlParameters); - $client = $this->getHttpClient(); - $client->resetParameters(); - $client->setUri($uri->toString()); - if ($this->getLanguage()) - $client->setHeaders(array('Accept-Language'=>$this->getLanguage())); - - $stream = $client->send(); - - $body = Json::decode($stream->getBody(), Json::TYPE_ARRAY); - $hydrator = new ArraySerializable(); - - $response = new Response(); - $response->setRawBody($body); - if (!isset($body['status'])) { - throw new Exception\RuntimeException('Invalid status'); - } - $response->setStatus($body['status']); - if (!isset($body['results'])) { - throw new Exception\RuntimeException('Invalid results'); - } - - $resultSet = new ResultSet(); - foreach ($body['results'] as $data) { - $result = new Result(); - $hydrator->hydrate($data, $result); - $resultSet->addElement($result); - } - $response->setResults($resultSet); - - return $response; - } + } + + + public function setHttpClient(HttpClient $httpClient) + { + $this->httpClient = $httpClient; + return $this; + } + + + /** + * Execute geocoding + * + * @param Request $request + * @return Response + */ + public function geocode(Request $request) + { + if (null === $request) { + throw new Exception\InvalidArgumentException('request'); + } + $uri = new Uri(); + $uri->setScheme('https'); + $uri->setHost(self::GOOGLE_MAPS_APIS_URL); + $uri->setPath(self::GOOGLE_GEOCODING_API_PATH); + + $urlParameters = $request->getUrlParameters(); + if (null === $urlParameters) { + throw new Exception\RuntimeException('Invalid URL parameters'); + } + + $uri->setQuery($urlParameters); + $client = $this->getHttpClient(); + $client->resetParameters(); + $client->setUri($uri->toString()); + $client->setOptions(['sslverifypeer' => false]); + if ($this->getLanguage()) { + $client->setHeaders(array('Accept-Language' => $this->getLanguage())); + } + + $stream = $client->send(); + + $body = Json::decode($stream->getBody(), Json::TYPE_ARRAY); + $hydrator = new ArraySerializable(); + + $response = new Response(); + $response->setRawBody($body); + if (!isset($body['status'])) { + throw new Exception\RuntimeException('Invalid status'); + } + $response->setStatus($body['status']); + if (!isset($body['results'])) { + throw new Exception\RuntimeException('Invalid results'); + } + + $resultSet = new ResultSet(); + foreach ($body['results'] as $data) { + $result = new Result(); + $hydrator->hydrate($data, $result); + $resultSet->addElement($result); + } + $response->setResults($resultSet); + + return $response; + } }