@@ -25,14 +25,14 @@ class FloatingIps extends Model
2525 * Returns all floating ip objects.
2626 *
2727 * @see https://docs.hetzner.cloud/#resources-floating-ips-get
28- * @param RequestOpts|null $requestOpts
28+ * @param FloatingIPRequestOpts| RequestOpts|null $requestOpts
2929 * @return array
3030 * @throws \LKDev\HetznerCloud\APIException
3131 */
32- public function all (RequestOpts $ requestOpts = null ): array
32+ public function all (FloatingIPRequestOpts $ requestOpts = null ): array
3333 {
3434 if ($ requestOpts == null ) {
35- $ requestOpts = new RequestOpts ();
35+ $ requestOpts = new FloatingIPRequestOpts ();
3636 }
3737 $ response = $ this ->httpClient ->get ('floating_ips ' . $ requestOpts ->buildQuery ());
3838 if (!HetznerAPIClient::hasError ($ response )) {
@@ -56,6 +56,22 @@ public function get(int $floatingIpId): FloatingIp
5656 }
5757 }
5858
59+ /**
60+ * Returns a specific Floating IP object by its name.
61+ *
62+ * @see https://docs.hetzner.cloud/#resources-floating-ips-get-1
63+ * @param string $name
64+ * @return \LKDev\HetznerCloud\Models\FloatingIps\FloatingIp
65+ * @throws \LKDev\HetznerCloud\APIException
66+ */
67+ public function getByName (string $ name )
68+ {
69+ $ floatingIPs = $ this ->all (new FloatingIPRequestOpts ($ name ));
70+
71+ return (count ($ floatingIPs ) > 0 ) ? $ floatingIPs [0 ] : null ;
72+ }
73+
74+
5975 /**
6076 * Creates a new Floating IP assigned to a server.
6177 *
@@ -64,21 +80,24 @@ public function get(int $floatingIpId): FloatingIp
6480 * @param string|null $description
6581 * @param \LKDev\HetznerCloud\Models\Locations\Location|null $location
6682 * @param \LKDev\HetznerCloud\Models\Servers\Server|null $server
83+ * @param string|null $name
6784 * @return \LKDev\HetznerCloud\Models\FloatingIps\FloatingIp
6885 * @throws \LKDev\HetznerCloud\APIException
6986 */
7087 public function create (
7188 string $ type ,
7289 string $ description = null ,
7390 Location $ location = null ,
74- Server $ server = null
91+ Server $ server = null ,
92+ string $ name = null
7593 ): FloatingIp
7694 {
7795 $ response = $ this ->httpClient ->post ('floating_ips ' , [
7896 'type ' => $ type ,
7997 'description ' => $ description ,
8098 'server ' => $ server ?: $ server ->id ,
8199 'home_location ' => $ location ?: $ location ->name ,
100+ 'name ' => $ name ?: $ name ,
82101 ]);
83102 if (!HetznerAPIClient::hasError ($ response )) {
84103 return FloatingIp::parse (json_decode ((string )$ response ->getBody ())->floating_ip );
@@ -106,4 +125,4 @@ public static function parse($input)
106125 {
107126 return (new self ())->setAdditionalData ($ input );
108127 }
109- }
128+ }
0 commit comments