Skip to content

Commit

Permalink
Get Inbound by ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Nov 11, 2024
1 parent 3d13bd7 commit 6c61894
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
40 changes: 40 additions & 0 deletions py3xui/api/api_inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,46 @@ def get_list(self) -> list[Inbound]:
inbounds = [Inbound.model_validate(data) for data in inbounds_json]
return inbounds

def get_by_id(self, inbound_id: int) -> Inbound:
"""This route is used to retrieve statistics and details for a specific inbound connection
identified by specified ID. This includes information about the inbound itself, its
statistics, and the clients connected to it.
If the inbound is not found, the method will raise an exception.
[Source documentation](https://www.postman.com/hsanaei/3x-ui/request/uu7wm1k/inbound)
Arguments:
inbound_id (int): The ID of the inbound to retrieve.
Returns:
Inbound | None: The inbound object if found, otherwise None.
Examples:
```python
import py3xui
api = py3xui.Api.from_env()
api.login()
inbound_id = 1
inbound = api.inbound.get_by_id(inbound_id)
"""
endpoint = f"panel/api/inbounds/get/{inbound_id}"
headers = {"Accept": "application/json"}

url = self._url(endpoint)
self.logger.info("Getting inbound by ID: %s", inbound_id)

response = self._get(url, headers)

inbound_json = response.json().get(ApiFields.OBJ)
inbound = Inbound.model_validate(inbound_json)
return inbound

def add(self, inbound: Inbound) -> None:
"""This route is used to add a new inbound configuration.
Expand Down
40 changes: 40 additions & 0 deletions py3xui/async_api/async_api_inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,46 @@ async def get_list(self) -> list[Inbound]:
inbounds = [Inbound.model_validate(data) for data in inbounds_json]
return inbounds

async def get_by_id(self, inbound_id: int) -> Inbound:
"""This route is used to retrieve statistics and details for a specific inbound connection
identified by specified ID. This includes information about the inbound itself, its
statistics, and the clients connected to it.
If the inbound is not found, the method will raise an exception.
[Source documentation](https://www.postman.com/hsanaei/3x-ui/request/uu7wm1k/inbound)
Arguments:
inbound_id (int): The ID of the inbound to retrieve.
Returns:
Inbound | None: The inbound object if found, otherwise None.
Examples:
```python
import py3xui
api = py3xui.AsyncApi.from_env()
await api.login()
inbound_id = 1
inbound = await api.inbound.get_by_id(inbound_id)
"""
endpoint = f"panel/api/inbounds/get/{inbound_id}"
headers = {"Accept": "application/json"}

url = self._url(endpoint)
self.logger.info("Getting inbound by ID: %s", inbound_id)

response = await self._get(url, headers)

inbound_json = response.json().get(ApiFields.OBJ)
inbound = Inbound.model_validate(inbound_json)
return inbound

async def add(self, inbound: Inbound) -> None:
"""This route is used to add a new inbound configuration.
Expand Down
4 changes: 3 additions & 1 deletion py3xui/inbound/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class Inbound(BaseModel):
total: int = 0

expiry_time: int = Field(default=0, alias=InboundFields.EXPIRY_TIME) # type: ignore
client_stats: list[Client] = Field(default=[], alias=InboundFields.CLIENT_STATS) # type: ignore
client_stats: list[Client] | None = Field(
default=[], alias=InboundFields.CLIENT_STATS
) # type: ignore

tag: str = ""

Expand Down

0 comments on commit 6c61894

Please sign in to comment.