Skip to content

Commit 68a77d7

Browse files
committed
Allow to get service points by ids
1 parent 9f08335 commit 68a77d7

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/Client/Endpoint/ServicePointsEndpoint.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,23 @@ final class ServicePointsEndpoint extends Endpoint implements ServicePointsEndpo
1313
{
1414
public function getNearestByAddress(Query $query): ServicePointInformationResponse
1515
{
16-
$source = new JsonSource($this->client->get(sprintf('%s/nearest/byaddress', $this->endpoint), $query));
16+
return $this
17+
->mapperBuilder
18+
->mapper()
19+
->map(
20+
ServicePointInformationResponse::class,
21+
Source::iterable(new JsonSource($this->client->get(sprintf('%s/nearest/byaddress', $this->endpoint), $query))),
22+
);
23+
}
1724

18-
return $this->mapperBuilder->mapper()->map(ServicePointInformationResponse::class, Source::iterable($source));
25+
public function getByIds(Query $query): ServicePointInformationResponse
26+
{
27+
return $this
28+
->mapperBuilder
29+
->mapper()
30+
->map(
31+
ServicePointInformationResponse::class,
32+
Source::iterable(new JsonSource($this->client->get(sprintf('%s/ids', $this->endpoint), $query))),
33+
);
1934
}
2035
}

src/Client/Endpoint/ServicePointsEndpointInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
interface ServicePointsEndpointInterface extends EndpointInterface
1111
{
1212
public function getNearestByAddress(Query $query): ServicePointInformationResponse;
13+
14+
public function getByIds(Query $query): ServicePointInformationResponse;
1315
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\PostNord\Request\Query\ServicePoints;
6+
7+
use Setono\PostNord\Request\Query\Query;
8+
9+
final class ByIdsQuery extends Query
10+
{
11+
/**
12+
* @param list<string|int> $ids
13+
*/
14+
public static function create(
15+
array $ids,
16+
string $countryCode,
17+
string $responseFilter = null,
18+
string $grouped = null,
19+
string $located = null,
20+
string $callback = null,
21+
string $whiteLabelName = null,
22+
string $returnType = 'json',
23+
): self {
24+
return new self([
25+
'ids' => implode(',', $ids),
26+
'countryCode' => $countryCode,
27+
'responseFilter' => $responseFilter,
28+
'grouped' => $grouped,
29+
'located' => $located,
30+
'callback' => $callback,
31+
'whiteLabelName' => $whiteLabelName,
32+
'returnType' => $returnType,
33+
]);
34+
}
35+
}

src/Response/ServicePoints/ServicePoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class ServicePoint
99
public function __construct(
1010
public readonly string $name,
1111
public readonly string $servicePointId,
12-
public readonly int $routeDistance,
12+
public readonly ?int $routeDistance,
1313
public readonly Address $visitingAddress,
1414
) {
1515
}

0 commit comments

Comments
 (0)