Skip to content

Commit

Permalink
Merge pull request #136 from MyParcelCOM/feature/MP-2632-label-mime-t…
Browse files Browse the repository at this point in the history
…ypes

🐛 Shipment meta should be outside of data
  • Loading branch information
yoan-myparcel authored Dec 15, 2020
2 parents dadad39 + dfd4d3e commit 95fcce9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/MyParcelComApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public function createShipment(ShipmentInterface $shipment)
throw $exception;
}

return $this->postResource($shipment);
return $this->postResource($shipment, $shipment->getMeta());
}

/**
Expand All @@ -492,7 +492,7 @@ public function updateShipment(ShipmentInterface $shipment)
throw $exception;
}

return $this->patchResource($shipment);
return $this->patchResource($shipment, $shipment->getMeta());
}

/**
Expand Down Expand Up @@ -764,40 +764,46 @@ public function getResourcesFromUri($uri)
* Patch given resource and return the resource that was returned by the request.
*
* @param ResourceInterface $resource
* @param array $meta
* @return ResourceInterface|null
* @throws RequestException
*/
protected function patchResource(ResourceInterface $resource)
protected function patchResource(ResourceInterface $resource, $meta = [])
{
return $this->sendResource($resource, 'patch');
return $this->sendResource($resource, 'patch', $meta);
}

/**
* Post given resource and return the resource that was returned by the request.
*
* @param ResourceInterface $resource
* @param array $meta
* @return ResourceInterface|null
* @throws RequestException
*/
protected function postResource(ResourceInterface $resource)
protected function postResource(ResourceInterface $resource, $meta = [])
{
return $this->sendResource($resource);
return $this->sendResource($resource, 'post', $meta);
}

/**
* Send given resource to the API and return the resource that was returned.
*
* @param ResourceInterface $resource
* @param string $method
* @param array $meta
* @return ResourceInterface|null
* @throws RequestException
*/
protected function sendResource(ResourceInterface $resource, $method = 'post')
protected function sendResource(ResourceInterface $resource, $method = 'post', $meta = [])
{
$response = $this->doRequest(
$this->getResourceUri($resource->getType(), $resource->getId()),
$method,
['data' => $resource],
array_filter([
'data' => $resource,
'meta' => array_filter($meta),
]),
$this->authenticator->getAuthorizationHeader() + [
AuthenticatorInterface::HEADER_ACCEPT => AuthenticatorInterface::MIME_TYPE_JSONAPI,
]
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/Proxy/ShipmentProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public function getType()
return $this->type;
}

/**
* @return array
*/
public function getMeta()
{
return $this->getResource()->getMeta();
}

/**
* @param AddressInterface $recipientAddress
* @return $this
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public function getType()
return $this->type;
}

/**
* @return array
*/
public function getMeta()
{
return $this->meta;
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 95fcce9

Please sign in to comment.