Esempio n. 1
0
 /**
  * @param  array $criteria              Criterias for querying geocoding
  * @return GuzzlePromise                The promise for guzzle request
  *
  * @throws InvalidArgumentException
  */
 public function lookup($criteria)
 {
     // TODO: Discuss criteria validation
     if (!is_array($criteria)) {
         throw new InvalidArgumentException('Criteria must be an array with keys and values');
     }
     $lookup_promise = null;
     $lookup_promise = new GuzzlePromise(function () use($criteria, &$lookup_promise) {
         $this->client_interface->sendAsync(new Request("GET", sprintf(self::GEOCODEURL, $this->response_type, $this->arrayToQueryParams($criteria))))->then(function ($response) use($lookup_promise) {
             if ($response->getStatusCode() === 200) {
                 $geo_location_response = json_decode($response->getBody());
                 if ($geo_location_response->status !== "OK") {
                     $lookup_promise->reject(sprintf("Server responded with status %s", $geo_location_response->status));
                 } else {
                     $lookup_promise->resolve(Factory::create('GoogleGeoCoder\\GeoCollection', $geo_location_response->results));
                 }
             } else {
                 $lookup_promise->reject(sprintf("Server responded with code %s", $response->getStatusCode()));
             }
         }, function ($response) use($lookup_promise) {
             $lookup_promise->reject(sprintf("Server responded with failure"));
         })->wait();
     });
     return $lookup_promise;
 }
 public function __construct($geo_location_properties)
 {
     $this->collection = new ArrayIterator();
     foreach ($geo_location_properties as $geo_location_property) {
         $this->collection[] = Factory::create('GoogleGeoCoder\\GeoLocation', $geo_location_property);
     }
 }