private function getSpecificPois($latitude, $longitude) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-Gowalla-API-Key: ' . $this->apiKey)); curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); $uri = new Uri('http://api.gowalla.com/spots'); $uri->setQuery(array('lat' => (string) $latitude, 'lng' => (string) $longitude, 'radius' => (string) $this->radius)); curl_setopt($c, CURLOPT_URL, (string) $uri); $result = curl_exec($c); curl_close($c); $json = json_decode($result); if ($json == FALSE) { throw new InvalidStateException('Malformed JSON response.'); } $spots = $json->spots; $pois = array(); foreach ($spots as $spot) { $poi = new Poi(); $poi->name = $spot->name; $poi->address = $spot->address->locality; $poi->latitude = $spot->lat; $poi->longitude = $spot->lng; $poi->url = 'http://gowalla.com' . $spot->url; $id = explode('/', $spot->spot_categories[0]->url); $poi->imageUrl = GowallaCategoryImage::get($id[count($id) - 1]); $types = array(); foreach ($spot->spot_categories as $category) { $types[] = $category->name; } $poi->types = implode(', ', $types); $pois[] = $poi; } return $pois; }
protected function getFlightResults($searchid) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); $uri = new Uri('http://www.kayak.com/s/apibasic/flight'); $uri->setQuery(array('searchid' => $searchid, 'c' => C, 'm' => M, 'd' => D, 's' => S, 'apimode' => APIMODE, "_sid_" => $this->getSessionId(), 'version' => VERSION)); curl_setopt($c, CURLOPT_URL, (string) $uri); $result = curl_exec($c); curl_close($c); return $result; }
private function canonicalizeDestination($destination) { // searching for any string that wikipedia knows $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); curl_setopt($c, CURLOPT_USERAGENT, 'Travelbot 1.0 beta'); curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($c, CURLOPT_MAXREDIRS, 100); $uri = new Uri('http://en.wikipedia.org/w/api.php'); $uri->setQuery(array('format' => 'json', 'action' => 'opensearch', 'search' => $destination, 'limit' => 5)); curl_setopt($c, CURLOPT_URL, (string) $uri); $result = curl_exec($c); curl_close($c); $json = json_decode($result); if ($json === FALSE) { throw new InvalidStateException('Malformed JSON response.'); } if (!isset($json[1][0])) { throw new ArticleException('Article not found.'); } $destination = $json[1][0]; // canonization (redirection to the final article) $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); curl_setopt($c, CURLOPT_USERAGENT, 'Travelbot 1.0 beta'); curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($c, CURLOPT_MAXREDIRS, 100); $uri = new Uri('http://en.wikipedia.org/w/api.php'); $uri->setQuery(array('format' => 'json', 'action' => 'query', 'titles' => $destination, 'redirects' => TRUE)); curl_setopt($c, CURLOPT_URL, (string) $uri); $result = curl_exec($c); curl_close($c); $json = json_decode($result); if ($json === FALSE) { return $destination; } if (isset($json->query->redirects[0])) { return $json->query->redirects[0]->to; } else { if (isset($json->query->normalized[0])) { return String::capitalize($json->query->normalized[0]->to); } } return $destination; }
/** * Returns coordinates by given location string. * @param string * @return array */ public function getCoordinates($location) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); $uri = new Uri('http://maps.googleapis.com/maps/api/geocode/json'); $uri->setQuery(array('address' => $location, 'sensor' => 'false')); curl_setopt($c, CURLOPT_URL, (string) $uri); $result = curl_exec($c); curl_close($c); // parsing json results $json = json_decode($result); if ($json == FALSE || $json->status != 'OK') { throw new InvalidStateException('Malformed JSON data.'); } return array('latitude' => $json->results[0]->geometry->location->lat, 'longitude' => $json->results[0]->geometry->location->lng); }
public function getTripDirections($departure, $arrival) { // curl initialization $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); // using Nette\Web\Uri for escaping GET parameters $uri = new Uri('http://maps.googleapis.com/maps/api/directions/json'); $uri->setQuery(array('origin' => $departure, 'destination' => $arrival, 'sensor' => 'false')); curl_setopt($c, CURLOPT_URL, (string) $uri); $result = curl_exec($c); curl_close($c); $json = json_decode($result); if ($json == FALSE || $json->status != 'OK') { throw new InvalidStateException('Malformed JSON response.'); } return $json; }
public function getEvents($location, DateTime $date) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE); // using Nette\Web\Uri for escaping GET parameters $uri = new Uri('http://api.eventful.com/rest/events/search'); $uri->setQuery(array('user' => $this->user, 'password' => $this->password, 'app_key' => $this->key, 'location' => $location, 'within' => '10', 'units' => 'km')); curl_setopt($c, CURLOPT_URL, (string) $uri); $result = curl_exec($c); curl_close($c); $xml = @simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA); if ($xml == FALSE) { throw new InvalidStateException('Malformed XML response.'); } $events = array(); foreach ($xml->events->event as $xmlEvent) { $event = new Event(); $event->setTitle((string) $xmlEvent->title)->setUrl((string) $xmlEvent->url)->setDescription((string) $xmlEvent->description)->setDate(DateTime::createFromFormat('Y-m-d H:i:s', (string) $xmlEvent->start_time))->setVenue(new Venue((string) $xmlEvent->venue_name, (string) $xmlEvent->venue_url))->setLatitude((string) $xmlEvent->latitude)->setLongitude((string) $xmlEvent->longitude); $events[] = $event; } return $events; }
private function getSignature(Uri $absoluteUri) { $uri = new Uri($absoluteUri->path . $absoluteUri->query); $uri->setQuery(array('sensor' => 'false', 'client' => $this->clientID)); return hash_hmac('sha1', $uri->path . '?' . $uri->query, $this->key); }