Created
April 19, 2017 20:32
-
-
Save axp-dev/c6cbbb8fd82007baa292e67735ca0d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Yandex Taxi. | |
* | |
* @author Alexander Pushkarev <axp-dev@yandex.com> | |
* @link https://github.com/axp-dev | |
* @license MIT License | |
* @version 1.0 | |
*/ | |
class YandexTaxi | |
{ | |
/** | |
* @param $params | |
* | |
* @return array | |
* @internal param array $coordinates | |
* | |
*/ | |
public function preOrder($params) | |
{ | |
$data = [ | |
'id' => md5( time() ), | |
'supports_forced_surge' => true, | |
'parks' => [], | |
'requirements' => new stdClass(), | |
'skip_estimated_waiting' => true, | |
]; | |
$query = $this->query('https://taxi.yandex.ru/3.0/routestats/', array_merge($params, $data)); | |
return json_decode($query, true); | |
} | |
/** | |
* @param string $url | |
* @param array $data | |
* | |
* @return mixed | |
*/ | |
private function query($url, $data = []) | |
{ | |
$ch = curl_init( $url ); | |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); | |
curl_setopt( $ch, CURLOPT_POST, 1); | |
curl_setopt( $ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); | |
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) ); | |
$result = curl_exec($ch); | |
curl_close( $ch ); | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment