Coverage for fio_wrapper/endpoints/endpoints_v1/sites.py: 100%
43 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
1"""Access site information from FIO.
2"""
4from typing import List, Optional
5from fio_wrapper.endpoints.abstracts.abstract_endpoint import AbstractEndpoint
6from fio_wrapper.endpoints.abstracts.abstract_sites import AbstractSites
7from fio_wrapper.decorator import apikey_required
8from fio_wrapper.exceptions import NoSiteData, NotAuthenticated
9from fio_wrapper.models.sites_models import Site, SiteList, WarehouseList
12class Sites(AbstractSites, AbstractEndpoint):
13 @apikey_required
14 def get(self, username: str, timeout: Optional[float] = None) -> SiteList:
15 """Gets site data for given username from FIO
17 Note:
18 FIO API Key Required
20 Args:
21 username (str): Prosperous Universe username
22 timeout (float, optional): Request timeout in seconds. Defaults to None.
24 Raises:
25 NoSiteData: Username has no site data
26 NotAuthenticated: Not authenticated or no appropiate permissions
28 Returns:
29 Site | SiteList: Site or List of Sites
30 """
32 (status, data) = self.adapter.get(
33 endpoint=self.urls.sites_get_url(username=username),
34 err_codes=[204, 401],
35 timeout=timeout,
36 )
38 if status == 200:
39 return SiteList.model_validate(data)
41 elif status == 204:
42 raise NoSiteData("Username has no site data")
43 elif status == 401:
44 raise NotAuthenticated("Not authenticated or no appropiate permissions")
46 @apikey_required
47 def get_planet(
48 self, username: str, planet: str, timeout: Optional[float] = None
49 ) -> Site:
50 """Gets site data for given username and planet from FIO
52 Note:
53 FIO API Key Required
55 Args:
56 username (str): Prosperous Universe username
57 planet (str): PlanetId, PlanetNaturalId or PlanetName. Defaults to None.
58 timeout (float, optional): Request timeout in seconds. Defaults to None.
60 Raises:
61 NoSiteData: Username has no site data
62 NotAuthenticated: Not authenticated or no appropiate permissions
64 Returns:
65 Site: Site
66 """
68 (status, data) = self.adapter.get(
69 endpoint=self.urls.sites_planets_get_planet_url(
70 username=username, planet=planet
71 ),
72 err_codes=[204, 401],
73 timeout=timeout,
74 )
76 if status == 200:
77 return Site.model_validate(data)
78 elif status == 204:
79 raise NoSiteData("Username has no site data")
80 elif status == 401:
81 raise NotAuthenticated("Not authenticated or no appropiate permissions")
83 @apikey_required
84 def planets(self, username: str, timeout: Optional[float] = None) -> List[str]:
85 """Gets a list of SiteIds from FIO for given username
87 Note:
88 FIO API Key Required
90 Args:
91 username (str): Prosperous Universe username
92 timeout (float, optional): Request timeout in seconds. Defaults to None.
94 Raises:
95 NoSiteData: Username has no site data
96 NotAuthenticated: Not authenticated or no appropiate permissions
98 Returns:
99 List[str]: List of SiteIds
100 """
101 (status, data) = self.adapter.get(
102 endpoint=self.urls.sites_planets_get_url(username=username),
103 err_codes=[204, 401],
104 timeout=timeout,
105 )
107 if status == 200:
108 return data
109 elif status == 204:
110 raise NoSiteData("Username has no site data")
111 elif status == 401:
112 raise NotAuthenticated("Not authenticated or no appropiate permissions")
114 @apikey_required
115 def warehouses(
116 self, username: str, timeout: Optional[float] = None
117 ) -> WarehouseList:
118 """Get warehouse data for username from FIO
120 Note:
121 FIO API Key Required
123 Args:
124 username (str): Prosperous Universe username
125 timeout (float, optional): Request timeout in seconds. Defaults to None.
127 Raises:
128 NoSiteData: Username has no warehouse site data
129 NotAuthenticated: Not authenticated or no appropiate permissions
131 Returns:
132 WarehouseList: List of Warehouses
133 """
134 (status, data) = self.adapter.get(
135 endpoint=self.urls.sites_warehouses_get(username=username),
136 err_codes=[204, 401],
137 timeout=timeout,
138 )
140 if status == 200:
141 return WarehouseList.model_validate(data)
142 elif status == 204:
143 raise NoSiteData("Username has no warehouse site data")
144 elif status == 401:
145 raise NotAuthenticated("Not authenticated or no appropiate permissions")