forked from app-vise/kvk-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
KvkClient.php
92 lines (70 loc) · 2.93 KB
/
KvkClient.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
namespace Appvise\KvkApi;
use Appvise\KvkApi\Model\Link;
use Appvise\KvkApi\Http\QueryInterface;
use Appvise\KvkApi\Http\ClientInterface;
use Appvise\KvkApi\Http\SearchMapper;
use Appvise\KvkApi\Model\Company\EigenaarFactory;
use Appvise\KvkApi\Model\Company\VestigingFactory;
use Appvise\KvkApi\Model\Company\BasisProfielFactory;
use Appvise\KvkApi\Model\Company\VestigingListFactory;
final class KvkClient implements KvkClientInterface
{
private $baseUrl;
/** @var ClientInterface */
private $client;
public function __construct(ClientInterface $client, string $url)
{
$this->baseUrl = $url;
$this->client = $client;
}
public function getBasisProfielEigenaar(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v1/basisprofielen/{$query->toArray()['kvkNummer']}/eigenaar?geoData={$query->toArray()['geoData']}");
$result = $this->decodeJson($response);
return EigenaarFactory::fromResponse($result);
}
public function getBasisProfielHoofdVestiging(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v1/basisprofielen/{$query->toArray()['kvkNummer']}/hoofdvestiging?geoData={$query->toArray()['geoData']}");
$response = $this->decodeJson($response);
return VestigingFactory::fromResponse($response);
}
public function getBasisProfielVestigingen(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v1/basisprofielen/{$query->toArray()['kvkNummer']}/vestigingen");
$result = $this->decodeJson($response);
return VestigingListFactory::fromResponse($result);
}
public function getLink(Link $link)
{
$response = $this->client->hitEndpoint($link->getHref());
$result = $this->decodeJson($response);
return $result;
}
public function search(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v1/zoeken", $query);
$result = $this->decodeJson($response);
return SearchMapper::fromResponse($result);
}
public function getBasisProfiel(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v1/basisprofielen/{$query->toArray()['kvkNummer']}");
$result = $this->decodeJson($response);
return BasisProfielFactory::fromResponse($result);
}
public function getVestigingsProfiel(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v1/vestigingsprofielen/{$query->toArray()['vestigingsnummer']}");
$result = $this->decodeJson($response);
return VestigingFactory::fromResponse($result);
}
private function decodeJson($response)
{
$body = $response->getBody();
$contents = $body->getContents();
return json_decode($contents, true);
}
}