gawsoft / rest-api-client-framework
用于API客户端的简单客户端框架
v1.0.8
2023-08-05 18:50 UTC
Requires
- php: >=8.0
- ext-curl: *
- guzzlehttp/guzzle: >=6.5.5
Requires (Dev)
- phpunit/phpunit: >=6
README
为您的PHP API客户端提供REST客户端框架。以下示例说明了如何使用这个简单的脚本
快速编写API客户端
示例
<?php namespace TestClient\Client; use Gawsoft\RestApiClientFramework\Interfaces\ClientInterface; use Gawsoft\RestApiClientFramework\Base; use Gawsoft\RestApiClientFramework\Response; use Gawsoft\RestApiClientFramework\ProjectUrl; use Gawsoft\RestApiClientFramework\Project; class TestClient implements ClientInterface { private $api_key; private $endpoint; private $timeout = 30; /** * @param string $api_key */ function __construct(string $api_key){ $this->api_key = $api_key; $this->endpoint = getenv('WEBSHOTAPI_ENV') == 'dev' ? 'https://:3000' : 'https://api.webshotapi.com/v1'; } /** * Download info about your account * * @return Response * @throws ClientException */ function info(): Response{ $base = new Base($this); return $base->method([ 'path' => '/info', 'method' => 'GET' ]); } /** * Set connection timeout in seconds * * @param $timeout */ function setTimeout(int $timeout){ $this->timeout = $timeout; } function getApiKey(): string{ return $this->api_key; } function getTimeout(): int{ return $this->timeout; } /** * Set api endpoint. This method can use for test or if you want to change version of REST api * @param $endpoint */ function setEndpoint(string $endpoint){ $this->endpoint = $endpoint; } function getEndpoint(): string{ return $this->endpoint; } function projects(): Project{ return new Project($this); } function projectsUrl(): ProjectUrl{ return new ProjectUrl($this); } }