Skip to content

Commit

Permalink
Merge pull request #14 from peterjaap/master
Browse files Browse the repository at this point in the history
Add list method to API
  • Loading branch information
vdloo authored Mar 27, 2023
2 parents d0b79d0 + 0e0a902 commit 93d8d97
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Here's a list of Hypernode API features implemented in the client.
- Listing Hypernodes related to your API key
- Updating one or multiple Hypernode settings at once.
- Querying/polling the logbook for the status of a job.
- Creating and cancelling Brancher Hypernode instances.
- Listing, creating and cancelling Brancher Hypernode instances.

## Related projects

Expand Down
22 changes: 22 additions & 0 deletions src/Service/BrancherApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@

class BrancherApp extends AbstractService
{
/**
* List all brancher nodes for given parent app.
*
* @param string $app Name of the parent app
* @param array|null $data Extra data to be provided
* @return array Array containing brancher nodes
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function list(string $app, ?array $data = null): array
{
$url = sprintf(App::V2_BRANCHER_APP_URL, $app);

$response = $this->client->api->get($url, [], $data ? json_encode($data) : null);

$this->client->maybeThrowApiExceptions($response);

$data = $this->client->getJsonFromResponse($response);

return $data['branchers'];
}

/**
* Create a brancher app for given parent app.
*
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/Service/BrancherAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,49 @@

class BrancherAppTest extends HypernodeClientTestCase
{
public function testListBrancherApp()
{
$this->responses->append(
new Response(200, [], json_encode([
'name' => 'johndoe-eph123456',
'parent' => 'johndoe',
'type' => 'brancher',
'branchers' => []
])),
);

$branchers = $this->client->brancherApp->list('johndoe');

$request = $this->responses->getLastRequest();
$this->assertEquals('GET', $request->getMethod());
$this->assertEquals('/v2/brancher/app/johndoe/', $request->getUri());
$this->assertEquals([], $branchers);
}

public function testListBrancherAppRaisesClientExceptions()
{
$badRequestResponse = new Response(400, [], json_encode([
'non_field_errors' => ['Your request was invalid.']
]));
$this->responses->append($badRequestResponse);

$this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse));

$this->client->brancherApp->list('johndoe');
}

public function testListBrancherAppRaisesServerExceptions()
{
$badRequestResponse = new Response(500, [], json_encode([
'non_field_errors' => ['Something went wrong processing your request.']
]));
$this->responses->append($badRequestResponse);

$this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse));

$this->client->brancherApp->list('johndoe');
}

public function testCreateBrancherApp()
{
$this->responses->append(
Expand Down

0 comments on commit 93d8d97

Please sign in to comment.