Coverage for fio_wrapper/endpoints/endpoints_v1/group.py: 100%
31 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-16 11:50 +0100
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-16 11:50 +0100
1from typing import List, Optional
2from fio_wrapper.decorator import apikey_required
3from fio_wrapper.endpoints.abstracts.abstract_endpoint import AbstractEndpoint
4from fio_wrapper.endpoints.abstracts.abstract_group import AbstractGroup
5from fio_wrapper.models.group_models import (
6 BurnList,
7 GroupHub,
8 GroupList,
9 Group as GroupModel,
10 GroupMembershipList,
11)
14class Group(AbstractGroup, AbstractEndpoint):
15 @apikey_required
16 def all(self, timeout: Optional[float] = None) -> GroupList:
17 """Gets all groups from FIO
19 Note:
20 FIO API Key Required
22 Args:
23 timeout (float, optional): Request timeout in seconds. Defaults to None.
25 Raises:
26 UnknownFIOResponse: FIO returned an unknown response
28 Returns:
29 GroupList: List of Groups
30 """
31 (status, data) = self.adapter.get(
32 endpoint=self.urls.group_all_url(), timeout=timeout
33 )
35 if status == 200:
36 return GroupList.model_validate(data)
38 @apikey_required
39 def get(self, groupid: int, timeout: Optional[float] = None) -> GroupModel:
40 """Gets group information for specified GroupID from FIO
42 Note:
43 FIO API Key Required
45 Args:
46 groupid (int): GroupModelId
47 timeout (float, optional): Request timeout in seconds. Defaults to None.
49 Raises:
50 UnknownFIOResponse: FIO returned an unknown response
52 Returns:
53 GroupModel: GroupModel
54 """
55 (status, data) = self.adapter.get(
56 endpoint=self.urls.group_get_url(groupid=groupid), timeout=timeout
57 )
59 if status == 200:
60 return GroupModel.model_validate(data)
62 @apikey_required
63 def memberships(self, timeout: Optional[float] = None) -> GroupMembershipList:
64 """Gets all groups the FIO API Key is member of
66 Note:
67 FIO API Key Required
69 Args:
70 timeout (float, optional): Request timeout in seconds. Defaults to None.
72 Raises:
73 UnknownFIOResponse: FIO returned an unknown response
75 Returns:
76 GroupMembershipList: List of Group Memberships
77 """
78 (status, data) = self.adapter.get(
79 endpoint=self.urls.group_memberships_url(), timeout=timeout
80 )
82 if status == 200:
83 return GroupMembershipList.model_validate(data)
85 @apikey_required
86 def hub(self, members: List[str], timeout: Optional[float] = None) -> GroupHub:
87 """Gets the groups Hub information from FIO
89 Note:
90 FIO API Key Required
92 Args:
93 members (List[str]): List of members, e.g. ["NAME1", "NAME2"]
94 timeout (float, optional): Request timeout in seconds. Defaults to None.
96 Raises:
97 UnknownFIOResponse: FIO returned an unknown response
99 Returns:
100 GroupHub: GroupHub data from FIO
101 """
102 (status, data) = self.adapter.post(
103 endpoint=self.urls.group_hub_url(), data=members, timeout=timeout
104 )
106 if status == 200:
107 return GroupHub.model_validate(data)
109 @apikey_required
110 def burn(self, groupid: int, timeout: Optional[float] = None) -> BurnList:
111 """Gets the groups Burn information from FIO
113 Note:
114 FIO API Key Required
116 Args:
117 groupid (int): GroupModelId
118 timeout (float, optional): Request timeout in seconds. Defaults to None.
120 Raises:
121 UnknownFIOResponse: FIO returned an unknown response
123 Returns:
124 BurnList: List of Burn data
125 """
126 (status, data) = self.adapter.get(
127 endpoint=self.urls.group_burn_url(groupid=groupid), timeout=timeout
128 )
130 if status == 200:
131 return BurnList.model_validate(data)