Skip to content

Instantly share code, notes, and snippets.

@axp-dev
Created April 19, 2017 20:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axp-dev/c6cbbb8fd82007baa292e67735ca0d6c to your computer and use it in GitHub Desktop.
Save axp-dev/c6cbbb8fd82007baa292e67735ca0d6c to your computer and use it in GitHub Desktop.
<?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