-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from saasus-platform/feature/apilog-api
Add client for APILog API
- Loading branch information
Showing
31 changed files
with
964 additions
and
0 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
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Authentication; | ||
|
||
class BearerAuthentication implements \Jane\Component\OpenApiRuntime\Client\AuthenticationPlugin | ||
{ | ||
private $token; | ||
public function __construct(string $token) | ||
{ | ||
$this->{'token'} = $token; | ||
} | ||
public function authentication(\Psr\Http\Message\RequestInterface $request) : \Psr\Http\Message\RequestInterface | ||
{ | ||
$header = sprintf('Bearer %s', $this->{'token'}); | ||
$request = $request->withHeader('Authorization', $header); | ||
return $request; | ||
} | ||
public function getScope() : string | ||
{ | ||
return 'Bearer'; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog; | ||
|
||
class Client extends \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\Client | ||
{ | ||
/** | ||
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE) | ||
* @throws \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\GetLogsInternalServerErrorException | ||
* | ||
* @return null|\AntiPatternInc\Saasus\Sdk\ApiLog\Model\ApiLogs|\Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function getLogs(string $fetch = self::FETCH_OBJECT) | ||
{ | ||
return $this->executeEndpoint(new \AntiPatternInc\Saasus\Sdk\ApiLog\Endpoint\GetLogs(), $fetch); | ||
} | ||
/** | ||
* 指定したIDのAPI実行のログ登録を取得します。 | ||
* | ||
* @param string $apiLogId APIログID(API Log ID) | ||
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE) | ||
* @throws \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\GetLogInternalServerErrorException | ||
* | ||
* @return null|\Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function getLog(string $apiLogId, string $fetch = self::FETCH_OBJECT) | ||
{ | ||
return $this->executeEndpoint(new \AntiPatternInc\Saasus\Sdk\ApiLog\Endpoint\GetLog($apiLogId), $fetch); | ||
} | ||
/** | ||
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE) | ||
* @throws \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\ReturnInternalServerErrorInternalServerErrorException | ||
* | ||
* @return null|\Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function returnInternalServerError(string $fetch = self::FETCH_OBJECT) | ||
{ | ||
return $this->executeEndpoint(new \AntiPatternInc\Saasus\Sdk\ApiLog\Endpoint\ReturnInternalServerError(), $fetch); | ||
} | ||
public static function create($httpClient = null, array $additionalPlugins = array(), array $additionalNormalizers = array()) | ||
{ | ||
if (null === $httpClient) { | ||
$httpClient = \Http\Discovery\Psr18ClientDiscovery::find(); | ||
$plugins = array(); | ||
$uri = \Http\Discovery\Psr17FactoryDiscovery::findUrlFactory()->createUri('https://api.saasus.io/v1/apilog'); | ||
$plugins[] = new \Http\Client\Common\Plugin\AddHostPlugin($uri); | ||
$plugins[] = new \Http\Client\Common\Plugin\AddPathPlugin($uri); | ||
if (count($additionalPlugins) > 0) { | ||
$plugins = array_merge($plugins, $additionalPlugins); | ||
} | ||
$httpClient = new \Http\Client\Common\PluginClient($httpClient, $plugins); | ||
} | ||
$requestFactory = \Http\Discovery\Psr17FactoryDiscovery::findRequestFactory(); | ||
$streamFactory = \Http\Discovery\Psr17FactoryDiscovery::findStreamFactory(); | ||
$normalizers = array(new \Symfony\Component\Serializer\Normalizer\ArrayDenormalizer(), new \AntiPatternInc\Saasus\Sdk\ApiLog\Normalizer\JaneObjectNormalizer()); | ||
if (count($additionalNormalizers) > 0) { | ||
$normalizers = array_merge($normalizers, $additionalNormalizers); | ||
} | ||
$serializer = new \Symfony\Component\Serializer\Serializer($normalizers, array(new \Symfony\Component\Serializer\Encoder\JsonEncoder(new \Symfony\Component\Serializer\Encoder\JsonEncode(), new \Symfony\Component\Serializer\Encoder\JsonDecode(array('json_decode_associative' => true))))); | ||
return new static($httpClient, $requestFactory, $serializer, $streamFactory); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Endpoint; | ||
|
||
class GetLog extends \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\BaseEndpoint implements \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\Endpoint | ||
{ | ||
protected $api_log_id; | ||
/** | ||
* 指定したIDのAPI実行のログ登録を取得します。 | ||
* | ||
* @param string $apiLogId APIログID(API Log ID) | ||
*/ | ||
public function __construct(string $apiLogId) | ||
{ | ||
$this->api_log_id = $apiLogId; | ||
} | ||
use \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\EndpointTrait; | ||
public function getMethod() : string | ||
{ | ||
return 'GET'; | ||
} | ||
public function getUri() : string | ||
{ | ||
return str_replace(array('{api_log_id}'), array($this->api_log_id), '/logs/{api_log_id}'); | ||
} | ||
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null) : array | ||
{ | ||
return array(array(), null); | ||
} | ||
public function getExtraHeaders() : array | ||
{ | ||
return array('Accept' => array('application/json')); | ||
} | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\GetLogInternalServerErrorException | ||
* | ||
* @return null | ||
*/ | ||
protected function transformResponseBody(string $body, int $status, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null) | ||
{ | ||
if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) { | ||
return json_decode($body); | ||
} | ||
if (is_null($contentType) === false && (500 === $status && mb_strpos($contentType, 'application/json') !== false)) { | ||
throw new \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\GetLogInternalServerErrorException($serializer->deserialize($body, 'AntiPatternInc\\Saasus\\Sdk\\ApiLog\\Model\\Error', 'json')); | ||
} | ||
} | ||
public function getAuthenticationScopes() : array | ||
{ | ||
return array('Bearer'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Endpoint; | ||
|
||
class GetLogs extends \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\BaseEndpoint implements \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\Endpoint | ||
{ | ||
use \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\EndpointTrait; | ||
public function getMethod() : string | ||
{ | ||
return 'GET'; | ||
} | ||
public function getUri() : string | ||
{ | ||
return '/logs'; | ||
} | ||
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null) : array | ||
{ | ||
return array(array(), null); | ||
} | ||
public function getExtraHeaders() : array | ||
{ | ||
return array('Accept' => array('application/json')); | ||
} | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\GetLogsInternalServerErrorException | ||
* | ||
* @return null|\AntiPatternInc\Saasus\Sdk\ApiLog\Model\ApiLogs | ||
*/ | ||
protected function transformResponseBody(string $body, int $status, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null) | ||
{ | ||
if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) { | ||
return $serializer->deserialize($body, 'AntiPatternInc\\Saasus\\Sdk\\ApiLog\\Model\\ApiLogs', 'json'); | ||
} | ||
if (is_null($contentType) === false && (500 === $status && mb_strpos($contentType, 'application/json') !== false)) { | ||
throw new \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\GetLogsInternalServerErrorException($serializer->deserialize($body, 'AntiPatternInc\\Saasus\\Sdk\\ApiLog\\Model\\Error', 'json')); | ||
} | ||
} | ||
public function getAuthenticationScopes() : array | ||
{ | ||
return array('Bearer'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Endpoint; | ||
|
||
class ReturnInternalServerError extends \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\BaseEndpoint implements \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\Endpoint | ||
{ | ||
use \AntiPatternInc\Saasus\Sdk\ApiLog\Runtime\Client\EndpointTrait; | ||
public function getMethod() : string | ||
{ | ||
return 'GET'; | ||
} | ||
public function getUri() : string | ||
{ | ||
return '/errors/internal-server-error'; | ||
} | ||
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null) : array | ||
{ | ||
return array(array(), null); | ||
} | ||
public function getExtraHeaders() : array | ||
{ | ||
return array('Accept' => array('application/json')); | ||
} | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\ReturnInternalServerErrorInternalServerErrorException | ||
* | ||
* @return null | ||
*/ | ||
protected function transformResponseBody(string $body, int $status, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null) | ||
{ | ||
if (is_null($contentType) === false && (500 === $status && mb_strpos($contentType, 'application/json') !== false)) { | ||
throw new \AntiPatternInc\Saasus\Sdk\ApiLog\Exception\ReturnInternalServerErrorInternalServerErrorException($serializer->deserialize($body, 'AntiPatternInc\\Saasus\\Sdk\\ApiLog\\Model\\Error', 'json')); | ||
} | ||
} | ||
public function getAuthenticationScopes() : array | ||
{ | ||
return array('Bearer'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Exception; | ||
|
||
interface ApiException extends \Throwable | ||
{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Exception; | ||
|
||
interface ClientException extends ApiException | ||
{ | ||
} |
20 changes: 20 additions & 0 deletions
20
generated/ApiLog/Exception/GetLogInternalServerErrorException.php
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Exception; | ||
|
||
class GetLogInternalServerErrorException extends InternalServerErrorException | ||
{ | ||
/** | ||
* @var \AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error | ||
*/ | ||
private $error; | ||
public function __construct(\AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error $error) | ||
{ | ||
parent::__construct('Internal Server Error'); | ||
$this->error = $error; | ||
} | ||
public function getError() : \AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error | ||
{ | ||
return $this->error; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
generated/ApiLog/Exception/GetLogsInternalServerErrorException.php
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Exception; | ||
|
||
class GetLogsInternalServerErrorException extends InternalServerErrorException | ||
{ | ||
/** | ||
* @var \AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error | ||
*/ | ||
private $error; | ||
public function __construct(\AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error $error) | ||
{ | ||
parent::__construct('Internal Server Error'); | ||
$this->error = $error; | ||
} | ||
public function getError() : \AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error | ||
{ | ||
return $this->error; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
generated/ApiLog/Exception/InternalServerErrorException.php
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Exception; | ||
|
||
class InternalServerErrorException extends \RuntimeException implements ServerException | ||
{ | ||
public function __construct(string $message) | ||
{ | ||
parent::__construct($message, 500); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
generated/ApiLog/Exception/ReturnInternalServerErrorInternalServerErrorException.php
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Exception; | ||
|
||
class ReturnInternalServerErrorInternalServerErrorException extends InternalServerErrorException | ||
{ | ||
/** | ||
* @var \AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error | ||
*/ | ||
private $error; | ||
public function __construct(\AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error $error) | ||
{ | ||
parent::__construct('Internal Server Error'); | ||
$this->error = $error; | ||
} | ||
public function getError() : \AntiPatternInc\Saasus\Sdk\ApiLog\Model\Error | ||
{ | ||
return $this->error; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace AntiPatternInc\Saasus\Sdk\ApiLog\Exception; | ||
|
||
interface ServerException extends ApiException | ||
{ | ||
} |
Oops, something went wrong.