Skip to content

Commit

Permalink
Merge pull request #34 from swisnl/issue/33
Browse files Browse the repository at this point in the history
Add headers to request methods in DocumentClient(Interface)
  • Loading branch information
JaZo authored Dec 25, 2018
2 parents 7c3d64d + 1f8c994 commit f0ac206
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

* Add headers to request methods in `DocumentClientInterface`.
N.B. This is a breaking change if you implement the interface yourself or extend the `DocumentClient`.

### Removed

* Removed obsolete `ItemDocumentSerializer` in favor of `JsonSerializable`.
Expand Down
20 changes: 12 additions & 8 deletions src/DocumentClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,48 @@ public function setBaseUri(string $baseUri)

/**
* @param string $endpoint
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function get(string $endpoint): DocumentInterface
public function get(string $endpoint, array $headers = []): DocumentInterface
{
return $this->parseResponse($this->client->get($endpoint));
return $this->parseResponse($this->client->get($endpoint, $headers));
}

/**
* @param string $endpoint
* @param \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface $body
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function post(string $endpoint, ItemDocumentInterface $body): DocumentInterface
public function post(string $endpoint, ItemDocumentInterface $body, array $headers = []): DocumentInterface
{
return $this->parseResponse($this->client->post($endpoint, $this->prepareBody($body)));
return $this->parseResponse($this->client->post($endpoint, $this->prepareBody($body), $headers));
}

/**
* @param string $endpoint
* @param \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface $body
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function patch(string $endpoint, ItemDocumentInterface $body): DocumentInterface
public function patch(string $endpoint, ItemDocumentInterface $body, array $headers = []): DocumentInterface
{
return $this->parseResponse($this->client->patch($endpoint, $this->prepareBody($body)));
return $this->parseResponse($this->client->patch($endpoint, $this->prepareBody($body), $headers));
}

/**
* @param string $endpoint
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function delete(string $endpoint): DocumentInterface
public function delete(string $endpoint, array $headers = []): DocumentInterface
{
return $this->parseResponse($this->client->delete($endpoint));
return $this->parseResponse($this->client->delete($endpoint, $headers));
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/Interfaces/DocumentClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,37 @@ interface DocumentClientInterface
{
/**
* @param string $endpoint
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function get(string $endpoint): DocumentInterface;
public function get(string $endpoint, array $headers = []): DocumentInterface;

/**
* @param string $endpoint
* @param \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface $document
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function patch(string $endpoint, ItemDocumentInterface $document): DocumentInterface;
public function patch(string $endpoint, ItemDocumentInterface $document, array $headers = []): DocumentInterface;

/**
* @param string $endpoint
* @param \Swis\JsonApi\Client\Interfaces\ItemDocumentInterface $document
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function post(string $endpoint, ItemDocumentInterface $document): DocumentInterface;
public function post(string $endpoint, ItemDocumentInterface $document, array $headers = []): DocumentInterface;

/**
* @param string $endpoint
* @param array $headers
*
* @return \Swis\JsonApi\Client\Interfaces\DocumentInterface
*/
public function delete(string $endpoint): DocumentInterface;
public function delete(string $endpoint, array $headers = []): DocumentInterface;

/**
* @return string
Expand Down

0 comments on commit f0ac206

Please sign in to comment.