Skip to content

Commit 2942cec

Browse files
committed
Prepeare Release 1.5
1 parent 889134e commit 2942cec

File tree

8 files changed

+144
-8
lines changed

8 files changed

+144
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Changelog
22

3+
## 1.5.0 (28.03.2019)
4+
+ Implement `getByName` method on `LKDev\HetznerCloud\Models\Servers\Servers` and `LKDev\HetznerCloud\Models\Volumes\Volumes`.
5+
+ Implement `waitUntilCompleted` method on `LKDev\HetznerCloud\Models\Actions\Action`
6+
+ Add `LKDev\HetznerCloud\Models\Servers\ServerRequestOpts` for better control over the `all`-Method on `LKDev\HetznerCloud\Models\Servers\Servers`
7+
+ Add `LKDev\HetznerCloud\Models\Volumes\VolumeRequestOpts` for better control over the `all`-Method on `LKDev\HetznerCloud\Models\Volumes\Volumes`
8+
39
## 1.4.0 (27.02.2019)
4-
+ Implement `metrics` method on `LKDev\HetznerCloud\Models\Server\Server` (@paulus7, https://github.com/LKDevelopment/hetzner-cloud-php-sdk/pull/10)
10+
+ Implement `metrics` method on `LKDev\HetznerCloud\Models\Servers\Server` (@paulus7, https://github.com/LKDevelopment/hetzner-cloud-php-sdk/pull/10)
511

612
## 1.3.1 (20.02.2019)
713
+ Fix a error on the update methods.

src/Models/Actions/Action.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function __construct(
9292
*/
9393
public function getById($actionId): Action
9494
{
95-
$response = $this->httpClient->get( 'actions/' . $actionId);
95+
$response = $this->httpClient->get('actions/' . $actionId);
9696
if (!HetznerAPIClient::hasError($response)) {
9797
return Action::parse(json_decode((string)$response->getBody())->action);
9898
}
@@ -107,6 +107,17 @@ public function refresh(): Action
107107
return $this->getById($this->id);
108108
}
109109

110+
/**
111+
* Wait for an action to complete.
112+
* @param float $pollingInterval seconds
113+
* @return bool
114+
* @throws \LKDev\HetznerCloud\APIException
115+
*/
116+
public function waitUntilCompleted($pollingInterval = 0.5)
117+
{
118+
return Actions::waitActionCompleted($this, $pollingInterval);
119+
}
120+
110121
/**
111122
* @param $input
112123
* @return \LKDev\HetznerCloud\Models\Actions\Action|static
@@ -119,4 +130,4 @@ public static function parse($input)
119130

120131
return new self($input->id, $input->command, $input->progress, $input->status, $input->started, $input->finished, $input->resources, $input->error);
121132
}
122-
}
133+
}

src/Models/Images/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,4 @@ public static function parse($input)
230230

231231
return new self($input->id, $input->type, (property_exists($input, 'status') ? $input->status : null), $input->name, $input->description, $input->image_size, $input->disk_size, $input->created, $input->created_from, $input->bound_to, $input->os_flavor, $input->os_version, $input->rapid_deploy, Protection::parse($input->protection));
232232
}
233-
}
233+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace LKDev\HetznerCloud\Models\Servers;
4+
5+
6+
use LKDev\HetznerCloud\RequestOpts;
7+
8+
/**
9+
* Class ServerRequestOpts
10+
* @package LKDev\HetznerCloud\Models\Servers
11+
*/
12+
class ServerRequestOpts extends RequestOpts
13+
{
14+
/**
15+
* @var string
16+
*/
17+
public $name;
18+
19+
/**
20+
* @var string
21+
*/
22+
public $status;
23+
24+
/**
25+
* RequestOpts constructor.
26+
*
27+
* @param $name
28+
* @param $perPage
29+
* @param $page
30+
* @param $labelSelector
31+
*/
32+
public function __construct(string $name = null, string $status = null, int $perPage = null, int $page = null, string $labelSelector = null)
33+
{
34+
parent::__construct($perPage, $page, $labelSelector);
35+
$this->name = $name;
36+
$this->status = $status;
37+
}
38+
}

src/Models/Servers/Servers.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Servers extends Model
3939
public function all(RequestOpts $requestOpts = null): array
4040
{
4141
if ($requestOpts == null) {
42-
$requestOpts = new RequestOpts();
42+
$requestOpts = new ServerRequestOpts();
4343
}
4444
$response = $this->httpClient->get('servers' . $requestOpts->buildQuery());
4545
if (!HetznerAPIClient::hasError($response)) {
@@ -63,6 +63,22 @@ public function get(int $serverId): Server
6363
}
6464
}
6565

66+
/**
67+
* Returns a specific server object by its name. The server must exist inside the project.
68+
*
69+
* @see https://docs.hetzner.cloud/#resources-servers-get
70+
* @param string $serverName
71+
* @return \LKDev\HetznerCloud\Models\Servers\Server|null
72+
* @throws \LKDev\HetznerCloud\APIException
73+
*/
74+
public function getByName(string $serverName): Server
75+
{
76+
$servers = $this->all(new ServerRequestOpts($serverName));
77+
78+
return (count($servers) > 0) ? $servers[0] : null;
79+
80+
}
81+
6682
/**
6783
* Creates a new server in a datacenter instead of in a location. Returns preliminary information about the server as well as an action that covers progress of creation
6884
*
@@ -178,4 +194,4 @@ public static function parse($input)
178194

179195
return (new self())->setAdditionalData($input);
180196
}
181-
}
197+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: lukaskammerling
5+
* Date: 2019-03-28
6+
* Time: 13:51
7+
*/
8+
9+
namespace LKDev\HetznerCloud\Models\Volumes;
10+
11+
12+
use LKDev\HetznerCloud\RequestOpts;
13+
14+
class VolumeRequestOpts extends RequestOpts
15+
{
16+
/**
17+
* @var string
18+
*/
19+
public $name;
20+
21+
/**
22+
* @var string
23+
*/
24+
public $status;
25+
26+
/**
27+
* RequestOpts constructor.
28+
*
29+
* @param $name
30+
* @param $perPage
31+
* @param $page
32+
* @param $labelSelector
33+
*/
34+
public function __construct(string $name = null, string $status = null, int $perPage = null, int $page = null, string $labelSelector = null)
35+
{
36+
parent::__construct($perPage, $page, $labelSelector);
37+
$this->name = $name;
38+
$this->status = $status;
39+
}
40+
}

src/Models/Volumes/Volumes.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ public function all(RequestOpts $requestOpts = null): array
4747
}
4848
}
4949

50+
/**
51+
* Returns a specific server object by its name. The server must exist inside the project.
52+
*
53+
* @see https://docs.hetzner.cloud/#resources-volumes-get
54+
* @param string $volumeName
55+
* @return \LKDev\HetznerCloud\Models\Volumes\Volume|null
56+
* @throws \LKDev\HetznerCloud\APIException
57+
*/
58+
public function getByName(string $volumeName): Server
59+
{
60+
$volumes = $this->all(new VolumeRequestOpts($volumeName));
61+
62+
return (count($volumes) > 0) ? $volumes[0] : null;
63+
64+
}
65+
5066
/**
5167
* Returns a specific volume object. The server must exist inside the project.
5268
*
@@ -120,4 +136,4 @@ public static function parse($input)
120136

121137
return (new self())->setAdditionalData($input);
122138
}
123-
}
139+
}

tests/Unit/Servers/ServersTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ public function testGet()
4040
$this->assertEquals($server->name, 'my-server');
4141
$this->assertEquals($server->status, 'running');
4242
}
43-
43+
/**
44+
*
45+
*/
46+
public function testGetByName()
47+
{
48+
$server = $this->servers->getByName('my-server');
49+
$this->assertEquals($server->id, 42);
50+
$this->assertEquals($server->name, 'my-server');
51+
$this->assertEquals($server->status, 'running');
52+
}
4453
/**
4554
*
4655
*/

0 commit comments

Comments
 (0)