Skip to content

Commit

Permalink
Allow to get service points by ids
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jun 10, 2024
1 parent 9f08335 commit 68a77d7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/Client/Endpoint/ServicePointsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ final class ServicePointsEndpoint extends Endpoint implements ServicePointsEndpo
{
public function getNearestByAddress(Query $query): ServicePointInformationResponse
{
$source = new JsonSource($this->client->get(sprintf('%s/nearest/byaddress', $this->endpoint), $query));
return $this
->mapperBuilder
->mapper()
->map(
ServicePointInformationResponse::class,
Source::iterable(new JsonSource($this->client->get(sprintf('%s/nearest/byaddress', $this->endpoint), $query))),
);
}

return $this->mapperBuilder->mapper()->map(ServicePointInformationResponse::class, Source::iterable($source));
public function getByIds(Query $query): ServicePointInformationResponse
{
return $this
->mapperBuilder
->mapper()
->map(
ServicePointInformationResponse::class,
Source::iterable(new JsonSource($this->client->get(sprintf('%s/ids', $this->endpoint), $query))),
);
}
}
2 changes: 2 additions & 0 deletions src/Client/Endpoint/ServicePointsEndpointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
interface ServicePointsEndpointInterface extends EndpointInterface
{
public function getNearestByAddress(Query $query): ServicePointInformationResponse;

public function getByIds(Query $query): ServicePointInformationResponse;
}
35 changes: 35 additions & 0 deletions src/Request/Query/ServicePoints/ByIdsQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Setono\PostNord\Request\Query\ServicePoints;

use Setono\PostNord\Request\Query\Query;

final class ByIdsQuery extends Query
{
/**
* @param list<string|int> $ids
*/
public static function create(
array $ids,
string $countryCode,
string $responseFilter = null,
string $grouped = null,
string $located = null,
string $callback = null,
string $whiteLabelName = null,
string $returnType = 'json',
): self {
return new self([
'ids' => implode(',', $ids),
'countryCode' => $countryCode,
'responseFilter' => $responseFilter,
'grouped' => $grouped,
'located' => $located,
'callback' => $callback,
'whiteLabelName' => $whiteLabelName,
'returnType' => $returnType,
]);
}
}
2 changes: 1 addition & 1 deletion src/Response/ServicePoints/ServicePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class ServicePoint
public function __construct(
public readonly string $name,
public readonly string $servicePointId,
public readonly int $routeDistance,
public readonly ?int $routeDistance,
public readonly Address $visitingAddress,
) {
}
Expand Down

0 comments on commit 68a77d7

Please sign in to comment.