Skip to content

Commit

Permalink
Allow Uhura to make multiple sequential requests
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
colindecarlo committed Mar 8, 2016
1 parent bd22aaa commit 81d7378
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Uhura.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ public function getResource()
return implode('/', $this->resource);
}

private function request($method, $payload = null)
public function reset()
{
$options = $this->buildOptionsForRequest($method, $payload);
$this->resource = [];
}

return $this->responseHandler->handle(
$this->http->request($method, $this->getResource(), $options)
private function request($method, $payload = null)
{
$response = $this->responseHandler->handle(
$this->http->request($method, $this->getResource(), $this->buildOptionsForRequest($method, $payload))
);

$this->reset();

return $response;
}

private function buildOptionsForRequest($method, $payload)
Expand Down
15 changes: 15 additions & 0 deletions tests/UhuraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,19 @@ public function test_that_uhura_respects_the_version_specifier_of_apis()

$this->assertEquals('https://example.com/v2/users/1/blog', (string)$handler->getLastRequest()->getUri());
}

public function test_that_uhura_can_make_multiple_requests()
{
$handler = $this->uhura->getHttp()->getConfig('handler');
$handler->append(
new Response,
new Response
);

$this->uhura->users->get();
$this->assertEquals('https://example.com/users', (string)$handler->getLastRequest()->getUri());

$this->uhura->users(1)->blog->get();
$this->assertEquals('https://example.com/users/1/blog', (string)$handler->getLastRequest()->getUri());
}
}

0 comments on commit 81d7378

Please sign in to comment.