Skip to content

Commit 979c4b0

Browse files
committed
Add Action Shortcut method
Remove Server from Action Constructor
1 parent 4578a81 commit 979c4b0

File tree

4 files changed

+14
-35
lines changed

4 files changed

+14
-35
lines changed

src/HetznerAPIClient.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use LKDev\HetznerCloud\Models\Images\Images;
1111
use LKDev\HetznerCloud\Models\ISOs\ISOs;
1212
use LKDev\HetznerCloud\Models\Prices\Prices;
13+
use LKDev\HetznerCloud\Models\Servers\Servers;
1314
use LKDev\HetznerCloud\Models\Servers\Types\ServerTypes;
1415
use LKDev\HetznerCloud\Models\SSHKeys\SSHKeys;
1516
use Psr\Http\Message\ResponseInterface;
@@ -119,13 +120,19 @@ public static function hasError(ResponseInterface $response)
119120

120121
return false;
121122
}
122-
123123
/**
124-
* @return Models\Servers\Servers
124+
* @return Actions
125+
*/
126+
public function actions()
127+
{
128+
return new Actions($this->httpClient);
129+
}
130+
/**
131+
* @return Servers
125132
*/
126133
public function servers()
127134
{
128-
return new Models\Servers\Servers($this->httpClient);
135+
return new Servers($this->httpClient);
129136
}
130137

131138
/**

src/Models/Actions/Action.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ class Action extends Model
4949
*/
5050
public $error;
5151

52-
/**
53-
* @var null|string
54-
*/
55-
public $root_password = null;
56-
57-
/**
58-
* @var null|string
59-
*/
60-
public $wss_url = null;
61-
6252
/**
6353
* Action constructor.
6454
*
@@ -81,9 +71,7 @@ public function __construct(
8171
string $started,
8272
string $finished = null,
8373
$resources = null,
84-
$error = null,
85-
string $root_password = null,
86-
string $wss_url = null
74+
$error = null
8775
)
8876
{
8977
$this->id = $id;
@@ -129,6 +117,6 @@ public static function parse($input)
129117
return null;
130118
}
131119

132-
return new self($input->id, $input->command, $input->progress, $input->status, $input->started, $input->finished, $input->resources, $input->error, (property_exists($input, 'root_password') ? $input->root_password : null), (property_exists($input, 'wss_url') ? $input->wss_url : null));
120+
return new self($input->id, $input->command, $input->progress, $input->status, $input->started, $input->finished, $input->resources, $input->error);
133121
}
134122
}

src/Models/Actions/Actions.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ class Actions extends Model
1616
*/
1717
public $actions;
1818

19-
/**
20-
* @var \LKDev\HetznerCloud\Models\Servers\Server
21-
*/
22-
public $server;
23-
24-
/**
25-
* Actions constructor.
26-
*
27-
* @param \LKDev\HetznerCloud\Models\Servers\Server $server
28-
*/
29-
public function __construct(Server $server)
30-
{
31-
$this->server = $server;
32-
parent::__construct();
33-
}
3419

3520
/**
3621
* @return \LKDev\HetznerCloud\Models\Actions\Actions
@@ -41,7 +26,6 @@ public function all(): array
4126
$response = $this->httpClient->get('actions');
4227
if (!HetznerAPIClient::hasError($response)) {
4328
$resp = json_decode((string)$response->getBody(), false);
44-
$resp->server = $this->server;
4529
return self::parse($resp)->actions;
4630
}
4731
}

tests/tests/BasicClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Tests;
1010

1111
use LKDev\HetznerCloud\HetznerAPIClient;
12+
use LKDev\HetznerCloud\Models\Actions\Actions;
1213
use LKDev\HetznerCloud\Models\Datacenters\Datacenters;
1314
use LKDev\HetznerCloud\Models\FloatingIps\FloatingIps;
1415
use LKDev\HetznerCloud\Models\Images\Images;
@@ -17,8 +18,6 @@
1718
use LKDev\HetznerCloud\Models\Servers\Servers;
1819
use LKDev\HetznerCloud\Models\Servers\Types\ServerTypes;
1920
use LKDev\HetznerCloud\Models\SSHKeys\SSHKeys;
20-
use PHPUnit\Framework\TestCase;
21-
2221
/**
2322
* Class BasicClientTest
2423
* @package Tests
@@ -40,6 +39,7 @@ public function testGetApiToken()
4039
*/
4140
public function testMethodsReturnCorrectInstance()
4241
{
42+
$this->assertInstanceOf(Actions::class, $this->hetznerApi->actions());
4343
$this->assertInstanceOf(Servers::class, $this->hetznerApi->servers());
4444
$this->assertInstanceOf(ServerTypes::class, $this->hetznerApi->serverTypes());
4545
$this->assertInstanceOf(Images::class, $this->hetznerApi->images());

0 commit comments

Comments
 (0)