-
Notifications
You must be signed in to change notification settings - Fork 30
/
AppleApiClient.php
43 lines (36 loc) · 1.39 KB
/
AppleApiClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php declare(strict_types=1);
namespace Azimo\Apple\Api;
use Azimo\Apple\Api\Exception\PublicKeyFetchingFailedException;
use Azimo\Apple\Api\Factory\ResponseFactory;
use GuzzleHttp;
use GuzzleHttp\Utils;
use InvalidArgumentException;
final class AppleApiClient implements AppleApiClientInterface
{
private GuzzleHttp\ClientInterface $httpClient;
private ResponseFactory $responseFactory;
public function __construct(GuzzleHttp\ClientInterface $httpClient, ResponseFactory $responseFactory)
{
$this->httpClient = $httpClient;
$this->responseFactory = $responseFactory;
}
public function getAuthKeys(): Response\JsonWebKeySetCollection
{
try {
$response = $this->httpClient->send(new GuzzleHttp\Psr7\Request('GET', 'auth/keys'));
} catch (GuzzleHttp\Exception\GuzzleException $exception) {
throw new PublicKeyFetchingFailedException($exception->getMessage(), $exception->getCode(), $exception);
}
try {
return $this->responseFactory->createFromArray(
Utils::jsonDecode($response->getBody()->getContents(), true)
);
} catch (InvalidArgumentException $exception) {
throw new Exception\InvalidResponseException(
'Unable to decode response',
$exception->getCode(),
$exception
);
}
}
}