Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ Only tested code will be accepted. Please follow fix the style guide.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please run those for some code standard fixes?

./vendor/bin/broc-code fix src
./vendor/bin/broc-code fix tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did actually! (Well, bro-code, there was no broc-code - that's why I changed it in the README.md.) It didn't seem to have changed anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - can confirm that it's working despite my scepticism, I put in your $options snippet above and it changed the indentation of the arrow slightly. :D

```bash
# Fixes code
./vendor/bin/broc-code fix src
./vendor/bin/broc-code fix tests
./vendor/bin/bro-code fix src
./vendor/bin/bro-code fix tests
```

## Lincense
Expand Down
16 changes: 8 additions & 8 deletions src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@ public function getEndpoint()
return $this->endpoint;
}

public function get($path, array $params = [])
public function get($path, array $params = [], array $options = [])
{
return $this->request('GET', $path, ['query' => $params]);
return $this->request('GET', $path, array_merge($options, ['query' => $params]));
}

public function post($path, array $postData = [])
public function post($path, array $postData = [], array $options = [])
{
return $this->request('POST', $path, ['json' => $postData]);
return $this->request('POST', $path, array_merge($options, ['json' => $postData]));
}

public function put($path, array $putData = [])
public function put($path, array $putData = [], array $options = [])
{
return $this->request('PUT', $path, ['json' => $putData]);
return $this->request('PUT', $path, array_merge($options, ['json' => $putData]));
}

public function delete($endpoint, array $data = [])
public function delete($endpoint, array $data = [], array $options = [])
{
throw new \BadMethodCallException("Not implemented yet");
}

public function patch($endpoint, array $data = [])
public function patch($endpoint, array $data = [], array $options = [])
{
throw new \BadMethodCallException("Not implemented yet");
}
Expand Down
15 changes: 10 additions & 5 deletions src/JsonInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,55 @@ interface JsonInterface
/**
* @param string $path
* @param array $data
* @param array $options additional options to send with the request, if any
*
* @throws Exception
*
* @return array
*/
public function get($path, array $data = []);
public function get($path, array $data = [], array $options = []);

/**
* @param string $path
* @param array $data
* @param array $options additional options to send with the request, if any
*
* @throws Exception
*
* @return array
*/
public function post($path, array $data = []);
public function post($path, array $data = [], array $options = []);

/**
* @param string $path
* @param array $data
* @param array $options additional options to send with the request, if any
*
* @throws Exception
*
* @return array
*/
public function put($path, array $data = []);
public function put($path, array $data = [], array $options = []);

/**
* @param string $path
* @param array $data
* @param array $options additional options to send with the request, if any
*
* @throws Exception
*
* @return array
*/
public function delete($path, array $data = []);
public function delete($path, array $data = [], array $options = []);

/**
* @param string $path
* @param array $data
* @param array $options additional options to send with the request, if any
*
* @throws Exception
*
* @return array
*/
public function patch($path, array $data = []);
public function patch($path, array $data = [], array $options = []);
}
21 changes: 19 additions & 2 deletions tests/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function convertsGuzzleResponseExceptionsIntoFriendlyClientExceptions()
);

$this->mockClient()
->request('GET', $this->url('/foo'), ['query' => []])
->request('GET', $this->url('/foo'), ["query" => []])
->willThrow($originalException);

try {
Expand All @@ -238,12 +238,29 @@ public function convertsGuzzleResponseExceptionsIntoFriendlyClientExceptions()
*/
public function throwsInvalidJsonResponse()
{
$this->mockClient()->request('GET', $this->url('/foo'), ['query' => []])
$this->mockClient()->request('GET', $this->url('/foo'), ["query" => []])
->willReturn($this->mockResponseBody('invalid')->reveal());

$this->client->get('/foo');
}

/**
* @test
*/
public function passesOnHeaders()
{
$options = [
'headers' => ['Content-Type' => 'application/json; charset=utf-8'],
'query' => []
];
$this->mockClient()->request('GET', $this->url('/foo'), $options)
->willReturn($this->fooBarResponse());

$data = $this->client->get('/foo', [], ['headers' => ['Content-Type' => 'application/json; charset=utf-8']]);

$this->assertFooBarResponse($data);
}

/**
* @return \Prophecy\Prophecy\ObjectProphecy
*/
Expand Down