-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use GuzzleHttp\Exception\GuzzleException; | ||
use HerCat\BaiduMap\Kernel\BaseClient; | ||
use HerCat\BaiduMap\Kernel\Exceptions\InvalidConfigException; | ||
use HerCat\BaiduMap\Kernel\Exceptions\RuntimeException; | ||
use HerCat\BaiduMap\Kernel\Http\Response; | ||
use HerCat\BaiduMap\Kernel\Support\Collection; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
@@ -22,21 +23,33 @@ | |
* Class LiteClient. | ||
* | ||
* @author her-cat <[email protected]> | ||
* | ||
* @method array|Response|Collection|mixed|object|ResponseInterface driving($origin, $destination, $options = []) | ||
* @method array|Response|Collection|mixed|object|ResponseInterface riding($origin, $destination, $options = []) | ||
* @method array|Response|Collection|mixed|object|ResponseInterface walking($origin, $destination, $options = []) | ||
* @method array|Response|Collection|mixed|object|ResponseInterface transit($origin, $destination, $options = []) | ||
*/ | ||
class LiteClient extends BaseClient | ||
{ | ||
const ALLOWED_METHODS = ['driving', 'riding', 'walking', 'transit']; | ||
|
||
/** | ||
* @param string $method | ||
* @param string|array $origin | ||
* @param string|array $destination | ||
* @param array $options | ||
* @param array $options | ||
* | ||
* @return array|Response|Collection|mixed|object|ResponseInterface | ||
* | ||
* @throws GuzzleException | ||
* @throws InvalidConfigException | ||
* @throws RuntimeException | ||
*/ | ||
public function get($origin, $destination, $options = []) | ||
public function execute($method, $origin, $destination, $options = []) | ||
{ | ||
if (!$this->isAllowedMethod($method)) { | ||
throw new RuntimeException(sprintf('Method named "%s" not found.', $method)); | ||
} | ||
|
||
$options = array_merge([ | ||
'origin' => implode(',', (array) $origin), | ||
'destination' => implode(',', (array) $destination), | ||
|
@@ -46,6 +59,26 @@ public function get($origin, $destination, $options = []) | |
$options['timestamp'] = time(); | ||
} | ||
|
||
return $this->httpGet('directionlite/v1/driving', $options); | ||
return $this->httpGet(sprintf('directionlite/v1/%s', $method), $options); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param array $arguments | ||
* | ||
* @return array|Response|Collection|mixed|object|ResponseInterface | ||
* | ||
* @throws GuzzleException | ||
* @throws InvalidConfigException | ||
* @throws RuntimeException | ||
*/ | ||
public function __call($name, $arguments) | ||
{ | ||
return $this->execute($name, ...$arguments); | ||
} | ||
|
||
public function isAllowedMethod($method) | ||
{ | ||
return \in_array($method, static::ALLOWED_METHODS); | ||
} | ||
} |
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