Skip to content

Commit 756ecba

Browse files
committed
feat: Add IP management support to the API client
Introduced an `IP` class with methods for handling IP operations such as listing, creating, and deleting IP addresses. Updated the `Client` class to include an `ip()` method for accessing the `IP` class instance. This enhancement extends the API client's functionality to manage IP-related resources.
1 parent 1e8db19 commit 756ecba

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/Client.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use FireAPI\DedicatedServer\DedicatedServer;
77
use FireAPI\Domain\Domain;
88
use FireAPI\Exceptions\ParameterException;
9+
use FireAPI\IP\IP;
910
use FireAPI\RootServer\RootServer;
1011
use GuzzleHttp\Exception\GuzzleException;
1112
use Psr\Http\Message\ResponseInterface;
@@ -21,6 +22,7 @@ class Client
2122
private ?Domain $domainHandler = null;
2223
private ?RootServer $rootServerHandler = null;
2324
private ?DedicatedServer $dedicatedServerHandler = null;
25+
private ?IP $IpHandler = null;
2426

2527
/**
2628
* Client constructor.
@@ -223,4 +225,14 @@ public function dedicatedServer(): DedicatedServer
223225
{
224226
return $this->dedicatedServerHandler ??= new DedicatedServer($this);
225227
}
228+
229+
/**
230+
* Retrieves the IP instance, initializing it if not already created.
231+
*
232+
* @return IP The IP instance.
233+
*/
234+
public function ip(): IP
235+
{
236+
return $this->IpHandler ??= new IP($this);
237+
}
226238
}

src/IP/IP.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace FireAPI\IP;
4+
5+
use FireAPI\Client;
6+
use GuzzleHttp\Exception\GuzzleException;
7+
8+
class IP
9+
{
10+
private Client $client;
11+
12+
/**
13+
* Constructor method for initializing dependencies.
14+
*
15+
* @param Client $client An instance of the Client class.
16+
* @return void
17+
*/
18+
public function __construct(Client $client)
19+
{
20+
$this->client = $client;
21+
}
22+
23+
/**
24+
* Retrieves a list of available IP addresses from the client.
25+
*
26+
* @return mixed The list of available IP addresses.
27+
* @throws GuzzleException
28+
*/
29+
public function getAvailable(): mixed
30+
{
31+
return $this->client->get('ip/available');
32+
}
33+
34+
/**
35+
* Initiates the purchase of an IP address for the specified network ID.
36+
*
37+
* @param int $netID The ID of the network for which the IP address is to be purchased.
38+
* @return mixed The result of the purchase operation.
39+
* @throws GuzzleException
40+
*/
41+
public function create(int $netID): mixed
42+
{
43+
return $this->client->post('ip/purchase', ['netID' => $netID]);
44+
}
45+
46+
/**
47+
* Fetches the list of IP addresses from the client.
48+
*
49+
* @return mixed The list of IP addresses.
50+
* @throws GuzzleException
51+
*/
52+
public function getList(): mixed
53+
{
54+
return $this->client->get('ip/list');
55+
}
56+
57+
/**
58+
* Deletes a network resource using the provided network ID.
59+
*
60+
* @param int $netID The unique identifier of the network to be deleted.
61+
* @return mixed The response from the client after performing the deletion.
62+
* @throws GuzzleException
63+
*/
64+
public function delete(int $netID): mixed
65+
{
66+
return $this->client->delete('ip/delete', ['netID' => $netID]);
67+
}
68+
}

0 commit comments

Comments
 (0)