Skip to content

Commit

Permalink
Merge pull request #8 from tpeyrou-clever/dev
Browse files Browse the repository at this point in the history
Add toArray to Event and Step classes + Return error code into Tracki…
  • Loading branch information
rvigneron64 authored Jan 20, 2025
2 parents 6eb8379 + 46884fe commit a8967af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Model/Tracking/Response/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,15 @@ public function setSiteZipCode(?string $siteZipCode): Event

return $this;
}

public function toArray(): array
{
return [
'date' => $this->getDate(),
'code' => $this->getCode(),
'labelLong' => $this->getLabelLong(),
'siteName' => $this->getSiteName(),
'siteZipCode' => $this->getSiteZipCode(),
];
}
}
12 changes: 12 additions & 0 deletions Model/Tracking/Response/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,16 @@ public function setDate(?string $date): Step

return $this;
}

public function toArray(): array
{
return [
'id' => $this->getStepId(),
'stepLabel' => $this->getStepLabel(),
'longLabel' => $this->getLongLabel(),
'status' => $this->getStatus(),
'country' => $this->getCountry(),
'date' => $this->getDate(),
];
}
}
5 changes: 4 additions & 1 deletion Service/TrackingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ public function validateDataBeforeCall(array $dataToValidate): void
}
}

/**
* @throws TrackingRequestException
*/
public function parseResponse($response): TrackingResponse
{
$responses = $this->slsResponseParser->parse($response);

$body = $responses[0]['body'];
$status = $body['status'][0];
if ($status['code'] !== "0") {
throw new TrackingRequestException($status['message']);
throw new TrackingRequestException($status['message'], $status['code']);
}

$parcel = $body['parcel'];
Expand Down

0 comments on commit a8967af

Please sign in to comment.