|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the DigitalOceanV2 library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace DigitalOceanV2\Api; |
|
13
|
|
|
|
|
14
|
|
|
use DigitalOceanV2\Entity\Snapshot as SnapshotEntity; |
|
15
|
|
|
use DigitalOceanV2\Exception\HttpException; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Yassir Hannoun <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class Snapshot extends AbstractApi |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @param array $criteria |
|
24
|
|
|
* |
|
25
|
|
|
* @return SnapshotEntity[] |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getAll(array $criteria = []) |
|
28
|
|
|
{ |
|
29
|
|
|
$query = sprintf('%s/snapshots?per_page=%d', $this->endpoint, 200); |
|
30
|
|
|
|
|
31
|
|
|
if (isset($criteria['type']) && in_array($criteria['type'], ['droplet', 'volume'])) { |
|
32
|
|
|
$query = sprintf('%s&resource_type=%s', $query, $criteria['type']); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$snapshots = $this->adapter->get($query); |
|
36
|
|
|
|
|
37
|
|
|
$snapshots = json_decode($snapshots); |
|
38
|
|
|
|
|
39
|
|
|
$this->extractMeta($snapshots); |
|
40
|
|
|
|
|
41
|
|
|
return array_map(function ($snapshots) { |
|
42
|
|
|
return new SnapshotEntity($snapshots); |
|
43
|
|
|
}, $snapshots->snapshots); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $id |
|
48
|
|
|
* |
|
49
|
|
|
* @return SnapshotEntity |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getById($id) |
|
52
|
|
|
{ |
|
53
|
|
|
$snapshot = $this->adapter->get(sprintf('%s/snapshots/%s', $this->endpoint, $id)); |
|
54
|
|
|
|
|
55
|
|
|
$snapshot = json_decode($snapshot); |
|
56
|
|
|
|
|
57
|
|
|
return new SnapshotEntity($snapshot->snapshot); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $id |
|
62
|
|
|
* |
|
63
|
|
|
* @throws HttpException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function delete($id) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->adapter->delete(sprintf('%s/snapshots/%s', $this->endpoint, $id)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|