digitalcz /
digisign
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace DigitalCz\DigiSign\Endpoint; |
||
| 6 | |||
| 7 | use DigitalCz\DigiSign\Resource\ApiKey; |
||
| 8 | use DigitalCz\DigiSign\Resource\BaseResource; |
||
| 9 | use DigitalCz\DigiSign\Resource\ResourceInterface; |
||
| 10 | use DigitalCz\DigiSign\Resource\User; |
||
| 11 | use DigitalCz\DigiSign\Stream\FileResponse; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @extends ResourceEndpoint<BaseResource> |
||
| 15 | */ |
||
| 16 | final class AccountMeEndpoint extends ResourceEndpoint |
||
| 17 | { |
||
| 18 | public function __construct(AccountEndpoint $parent) |
||
| 19 | { |
||
| 20 | parent::__construct($parent, '/me', BaseResource::class); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @return User|ApiKey |
||
| 25 | */ |
||
| 26 | public function get(): ResourceInterface |
||
| 27 | { |
||
| 28 | $result = $this->getRequest(); |
||
| 29 | |||
| 30 | // identify resource User/ApiKey |
||
| 31 | $resourceClass = isset($result->firstName) ? User::class : ApiKey::class; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 32 | |||
| 33 | return $this->createResource($result, $resourceClass); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param mixed[] $body |
||
| 38 | * @return User |
||
| 39 | */ |
||
| 40 | public function update(array $body): User |
||
| 41 | { |
||
| 42 | return $this->createResource($this->putRequest('', ['json' => $body]), User::class); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param mixed[] $body |
||
| 47 | */ |
||
| 48 | public function changePassword(array $body): void |
||
| 49 | { |
||
| 50 | $this->postRequest('/change-password', ['json' => $body]); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param mixed[] $body |
||
| 55 | */ |
||
| 56 | public function verifyPassword(array $body): void |
||
| 57 | { |
||
| 58 | $this->postRequest('/verify-password', ['json' => $body]); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function signatureImageContent(): FileResponse |
||
| 62 | { |
||
| 63 | return $this->stream(self::METHOD_GET, '/signature-image/content'); |
||
| 64 | } |
||
| 65 | } |
||
| 66 |