Skip to content

Commit

Permalink
Use same stanza to obtain parcel ID in Client::getParcelDocument()
Browse files Browse the repository at this point in the history
  • Loading branch information
villermen committed Feb 13, 2024
1 parent 1a8803d commit 2bee10e
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function getBulkLabelPdf(array $parcels, int $format): string
* @return string The contents of the requested document
* @throws SendcloudClientException
*/
public function getParcelDocument(Parcel|int $parcelId, string $documentType, string $contentType = Parcel::DOCUMENT_CONTENT_TYPE_PDF, int $dpi = Parcel::DOCUMENT_DPI_72): string
public function getParcelDocument(Parcel|int $parcel, string $documentType, string $contentType = Parcel::DOCUMENT_CONTENT_TYPE_PDF, int $dpi = Parcel::DOCUMENT_DPI_72): string
{
if (!in_array($documentType, Parcel::DOCUMENT_TYPES, true)) {
throw new \InvalidArgumentException(sprintf('Document type "%s" is not accepted. Valid types: %s.', $documentType, implode(', ', Parcel::DOCUMENT_TYPES)));
Expand All @@ -462,11 +462,8 @@ public function getParcelDocument(Parcel|int $parcelId, string $documentType, st
throw new \InvalidArgumentException(sprintf('DPI "%d" is not accepted for "%s". Valid values: %s.', $dpi, $contentType, implode(', ', Parcel::DOCUMENT_DPI_VALUES[$contentType])));
}

if ($parcelId instanceof Parcel) {
$parcelId = $parcelId->getId();
}

try {
$parcelId = is_int($parcel) ? $parcel : $parcel->getId();
return (string)$this->guzzleClient->get(sprintf('parcels/%s/documents/%s', $parcelId, $documentType), [
RequestOptions::QUERY => ['dpi' => $dpi],
RequestOptions::HEADERS => ['Accept' => $contentType],
Expand Down

0 comments on commit 2bee10e

Please sign in to comment.