Skip to content

Commit

Permalink
Added support for getting volume action by id
Browse files Browse the repository at this point in the history
  • Loading branch information
yassirh committed Jul 16, 2016
1 parent ca9c47f commit 0664b4d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
48 changes: 48 additions & 0 deletions spec/DigitalOceanV2/Api/VolumeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,52 @@ public function it_returns_the_action_entity_after_resizing($adapter)
$action->shouldReturnAnInstanceOf('DigitalOceanV2\Entity\Action');
$action->region->shouldReturnAnInstanceOf('DigitalOceanV2\Entity\Region');
}

public function it_returns_the_action_entity_when_retrieving_action($adapter)
{
$response = <<<EOT
{
"action": {
"id": 72531856,
"status": "completed",
"type": "attach_volume",
"started_at": "2015-11-12T17:51:03Z",
"completed_at": "2015-11-12T17:51:14Z",
"resource_id": null,
"resource_type": "volume",
"region": {
"name": "New York 1",
"slug": "nyc1",
"sizes": [
"1gb",
"2gb",
"4gb",
"8gb",
"32gb",
"64gb",
"512mb",
"48gb",
"16gb"
],
"features": [
"private_networking",
"backups",
"ipv6",
"metadata"
],
"available": true
},
"region_slug": "nyc1"
}
}
EOT;
$adapter
->get('https://api.digitalocean.com/v2/volumes/506f78a4-e098-11e5-ad9f-000f53306ae1/actions/72531856')
->willReturn($response);

$action = $this->getActionById('506f78a4-e098-11e5-ad9f-000f53306ae1', 72531856);
$action->id->shouldEqual(72531856);
$action->shouldReturnAnInstanceOf('DigitalOceanV2\Entity\Action');
$action->region->shouldReturnAnInstanceOf('DigitalOceanV2\Entity\Region');
}
}
15 changes: 15 additions & 0 deletions src/Api/Volume.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,19 @@ public function resize($id, $newSize, $regionSlug)

return new ActionEntity($action->action);
}

/**
* @param string $id
* @param int $actionId
*
* @return ActionEntity
*/
public function getActionById($id, $actionId)
{
$action = $this->adapter->get(sprintf('%s/volumes/%s/actions/%d', $this->endpoint, $id, $actionId));

$action = json_decode($action);

return new ActionEntity($action->action);
}
}

0 comments on commit 0664b4d

Please sign in to comment.