Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add huisnummerToevoeging as search option #8

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
365c4c5
add huisnummerToevoeging as search option
it-can Jan 12, 2024
8b70778
add missing result parameters
it-can Jan 12, 2024
1bfee3b
set order same as kvk api docs
it-can Jan 12, 2024
23af1f0
huisnummer is zero because it's empty when only searching a kvk
it-can Jan 12, 2024
4b32673
Change return type of getHuisnummer() to string. Update ResultaatItem…
it-can Jan 12, 2024
6ea328f
Change huisnummer data type from int to string in Adres class
it-can Jan 12, 2024
2761527
Refactor pluck methods in AbstractFactory to cast return values
it-can Jan 12, 2024
51a4533
revert to int for profile data
it-can Jan 12, 2024
f19131d
Change type of huisnummer and huisletter properties
it-can Jan 12, 2024
c8116f8
Change 'huisletter' to be plucked as a string instead of an integer
it-can Jan 12, 2024
76e9bc1
Refactor variable names and method names to use consistent naming con…
it-can Jan 12, 2024
805cf79
need to pass to MaterieleRegistratieFactory::fromResponse
it-can Jan 12, 2024
8da8152
add toArray() methods
it-can Jan 12, 2024
ad2c1f2
Add v2 of search
it-can Feb 22, 2024
36a4a57
fix test
it-can Feb 22, 2024
65a7105
Merge branch 'main' of github.com:it-can/kvk-api
it-can Apr 5, 2024
e410561
refactor(SearchQueryV2.php, Adres.php, Adres.php, Adres.php): change …
it-can Apr 5, 2024
b39dd71
fix(AdresFactory.php): change huisnummer property type from integer t…
it-can Apr 5, 2024
c275ee9
perf(KvkClientFactory.php): improve performance by adding timeout an…
it-can Jul 16, 2024
5aedd02
remove ssl check
it-can Nov 14, 2024
0e398a9
fix
it-can Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
</whitelist>
</filter>
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/Integration</directory>
</testsuite>
Expand Down
33 changes: 33 additions & 0 deletions src/Http/SearchMapperV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Appvise\KvkApi\Http;

use Appvise\KvkApi\Model\Resultaat;
use Appvise\KvkApi\Model\SearchV2\ResultaatItemFactory;

class SearchMapperV2
{
public static function fromResponse(array $response)
{
return new Resultaat(
$response['pagina'],
$response['resultatenPerPagina'],
$response['totaal'],
self::extractCompanies($response['resultaten']),
(array_key_exists('volgende', $response)) ? $response['volgende'] : null,
(array_key_exists('vorige', $response)) ? $response['vorige'] : null,
);
}

private static function extractCompanies(array $results): array
{
$companies = [];
foreach ($results as $result) {
$companies[] = ResultaatItemFactory::fromResponse($result);
}

return $companies;
}
}
19 changes: 14 additions & 5 deletions src/Http/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,29 @@ class SearchQuery implements QueryInterface
private $straatnaam;

/** @var string */
private $plaats;
private $huisnummer;

/** @var string */
private $huisnummerToevoeging;

/** @var string */
private $postcode;

/** @var string */
private $huisnummer;
private $plaats;

/** @var string */
private $type;

/** @var bool */
private $inclusiefinactieveregistraties;

/** @var int */
private $pagina;

/** @var int */
private $aantal;

/** @var bool */
private $inclusiefinactieveregistraties;

public function setKvkNumber(string $kvkNumber)
{
$this->kvkNumber = $kvkNumber;
Expand Down Expand Up @@ -82,6 +85,11 @@ public function setHuisnummer(string $huisnummer)
$this->huisnummer = $huisnummer;
}

public function setHuisnummerToevoeging(string $huisnummerToevoeging)
{
$this->huisnummerToevoeging = $huisnummerToevoeging;
}

public function setType(string $type)
{
$this->type = $type;
Expand Down Expand Up @@ -113,6 +121,7 @@ public function toArray(): array
'plaats' => $this->plaats,
'postcode' => $this->postcode,
'huisnummer' => $this->huisnummer,
'huisnummerToevoeging' => $this->huisnummerToevoeging,
'type' => $this->type,
'inclusiefinactieveregistraties' => $this->inclusiefinactieveregistraties,
'pagina' => $this->pagina,
Expand Down
140 changes: 140 additions & 0 deletions src/Http/SearchQueryV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

declare(strict_types=1);

namespace Appvise\KvkApi\Http;

class SearchQueryV2 implements QueryInterface
{
/** @var string */
private $kvkNummer;

/** @var string */
private $rsin;

/** @var string */
private $vestigingsnummer;

/** @var string */
private $naam;

/** @var string */
private $straatnaam;

/** @var string */
private $huisnummer;

/** @var string */
private $huisletter;

/** @var string */
private $postcode;

/** @var string */
private $plaats;

/** @var int */
private $postbusnummer;

/** @var string */
private $type;

/** @var bool */
private $inclusiefinactieveregistraties;

/** @var int */
private $pagina;

/** @var int */
private $resultatenPerPagina;


public function setKvkNummer(string $kvkNummer)
{
$this->kvkNummer = $kvkNummer;
}

public function setRsin(string $rsin)
{
$this->rsin = $rsin;
}

public function setVestigingsnummer(string $vestigingsnummer)
{
$this->vestigingsnummer = $vestigingsnummer;
}

public function setNaam(string $naam)
{
$this->naam = $naam;
}

public function setStraatnaam(string $straatnaam)
{
$this->straatnaam = $straatnaam;
}

public function setHuisnummer(string $huisnummer)
{
$this->huisnummer = $huisnummer;
}

public function setHuisletter(string $huisletter)
{
$this->huisletter = $huisletter;
}

public function setPostcode(string $postcode)
{
$this->postcode = $postcode;
}

public function setPlaats(string $plaats)
{
$this->plaats = $plaats;
}

public function setPostbusnummer(int $postbusnummer)
{
$this->postbusnummer = $postbusnummer;
}

public function setType(string $type)
{
$this->type = $type;
}

public function setInclusiefinactieveregistraties(bool $inclusiefinactieveregistraties)
{
$this->inclusiefinactieveregistraties = $inclusiefinactieveregistraties;
}

public function setPagina(int $pagina)
{
$this->pagina = $pagina;
}

public function setResultatenPerPagina(int $resultatenPerPagina)
{
$this->resultatenPerPagina = $resultatenPerPagina;
}

public function toArray(): array
{
return [
'kvkNummer' => $this->kvkNummer,
'rsin' => $this->rsin,
'vestigingsnummer' => $this->vestigingsnummer,
'naam' => $this->naam,
'straatnaam' => $this->straatnaam,
'huisnummer' => $this->huisnummer,
'huisletter' => $this->huisletter,
'postcode' => $this->postcode,
'plaats' => $this->plaats,
'type' => $this->type,
'inclusiefinactieveregistraties' => $this->inclusiefinactieveregistraties,
'pagina' => $this->pagina,
'resultatenPerPagina' => $this->resultatenPerPagina,
];
}
}
15 changes: 12 additions & 3 deletions src/KvkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Appvise\KvkApi;

use Appvise\KvkApi\Model\Link;
use Appvise\KvkApi\Http\QueryInterface;
use Appvise\KvkApi\Http\ClientInterface;
use Appvise\KvkApi\Http\QueryInterface;
use Appvise\KvkApi\Http\SearchMapper;
use Appvise\KvkApi\Http\SearchMapperV2;
use Appvise\KvkApi\Model\Company\BasisProfielFactory;
use Appvise\KvkApi\Model\Company\EigenaarFactory;
use Appvise\KvkApi\Model\Company\VestigingFactory;
use Appvise\KvkApi\Model\Company\BasisProfielFactory;
use Appvise\KvkApi\Model\Company\VestigingListFactory;
use Appvise\KvkApi\Model\Link;

final class KvkClient implements KvkClientInterface
{
Expand Down Expand Up @@ -66,6 +67,14 @@ public function search(QueryInterface $query)
return SearchMapper::fromResponse($result);
}

public function searchV2(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v2/zoeken", $query);
$result = $this->decodeJson($response);

return SearchMapperV2::fromResponse($result);
}

public function getBasisProfiel(QueryInterface $query)
{
$response = $this->client->hitEndpoint("{$this->baseUrl}api/v1/basisprofielen/{$query->toArray()['kvkNummer']}");
Expand Down
10 changes: 4 additions & 6 deletions src/KvkClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ class KvkClientFactory
private const PRODUCTION_URL = 'https://api.kvk.nl/';
private const DEVELOPMENT_URL = 'https://developers.kvk.nl/test/';

public static function create(string $userKey, string $stage = 'test', string $rootCertificate = null): KvkClientInterface
public static function create(string $userKey, string $stage = 'test', ?string $rootCertificate = null): KvkClientInterface
{
if ($rootCertificate === null) {
trigger_error('Root certificate is required. Please configure your system or supply one here.', E_USER_DEPRECATED);
}

switch ($stage) {
case 'production':
return new KvkClient(self::createHttpClient($userKey, $rootCertificate), self::PRODUCTION_URL);
Expand All @@ -45,8 +41,10 @@ private static function createHttpClient(string $userKey, ?string $rootCertifica

$client = new Client([
'debug' => false,
'verify' => $rootCertificate ?? false,
'verify' => $rootCertificate ?: false,
'handler' => $stack,
'timeout' => 10,
'connect_timeout' => 3,
]);

return new GuzzleClient($client);
Expand Down
2 changes: 2 additions & 0 deletions src/KvkClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface KvkClientInterface
{
public function search(QueryInterface $query);

public function searchV2(QueryInterface $query);

public function getBasisProfiel(QueryInterface $query);

public function getBasisProfielEigenaar(QueryInterface $query);
Expand Down
10 changes: 5 additions & 5 deletions src/Model/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ class AbstractFactory
{
protected static function pluckString($needle, $haystack): ?string
{
return self::extract($needle, $haystack);
return (string) self::extract($needle, $haystack);
}

protected static function pluckFloat($needle, $haystack): ?float
{
return (float)self::extract($needle, $haystack);
return (float) self::extract($needle, $haystack);
}

protected static function pluckInteger($needle, $haystack): ?int
{
return (int)self::extract($needle, $haystack);
return (int) self::extract($needle, $haystack);
}

protected static function pluckArray($needle, $haystack): ?array
{
return (array)self::extract($needle, $haystack);
return (array) self::extract($needle, $haystack);
}

protected static function pluckDate($needle, $haystack, $format = 'Ymd'): ?DateTime
{
$date = (string)self::extract($needle, $haystack);
$date = (string) self::extract($needle, $haystack);
if (! $date) {
return null;
}
Expand Down
Loading