Coverage for fio_wrapper/fio.py: 100%
33 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"""FIO class to access game data through FIO REST API endpoints
2"""
3from typing import Dict, Optional
4from fio_wrapper.config import Config
5from fio_wrapper.fio_adapter import FIOAdapter
6from fio_wrapper.exceptions import EndpointNotImplemented
8from fio_wrapper.endpoints.endpoints_v1 import building as building_v1
9from fio_wrapper.endpoints.endpoints_v1 import exchange as exchange_v1
10from fio_wrapper.endpoints.endpoints_v1 import localmarket as localmarket_v1
11from fio_wrapper.endpoints.endpoints_v1 import material as material_v1
12from fio_wrapper.endpoints.endpoints_v1 import planet as planet_v1
13from fio_wrapper.endpoints.endpoints_v1 import recipe as recipe_v1
14from fio_wrapper.endpoints.endpoints_v1 import sites as sites_v1
15from fio_wrapper.endpoints.endpoints_v1 import storage as storage_v1
16from fio_wrapper.endpoints.endpoints_v1 import group as group_v1
17from fio_wrapper.urls import URLs
20class FIO:
21 """FIO API wrapper class
23 Attributes:
24 Building (Building): Building information
25 Exchange (Exchange): Exchange information
26 Group (Group): Group information
27 LocalMarket (LocalMarket): LocalMarket information
28 Material (Material): Material information
29 Planet (Planet): Planet information
30 Recipe (Recipe): Recipe information
31 Sites (Sites): Sites information
32 Storage (Storage): Storage information
34 config (Config): FIO Configuration
35 adapter (FIOAdapter): FIO Adapter
36 urls (URLs): FIO URLs
37 """
39 def __init__(
40 self,
41 version: Optional[str] = None,
42 application: Optional[str] = None,
43 api_key: Optional[str] = None,
44 base_url: Optional[str] = None,
45 timeout: Optional[float] = None,
46 ssl_verify: Optional[bool] = True,
47 config: Optional[str] = None,
48 ) -> None:
49 """Initializes the FIO wrapper
51 Args:
52 version (str, optional): FIO API version. Defaults to None.
53 application (str, optional): Application name. Defaults to None.
54 api_key (str, optional): FIO API-Key. Defaults to None.
55 base_url (str, optional): FIO base url. Defaults to None.
56 timeout (float, optional): Request timeout. Defaults to None.
57 ssl_verify (bool, optional): Verify https connection. Defaults to True.
58 config: (str, optional): User specified configuration file. Defaults to None.
60 Raises:
61 EndpointNotImplemented: _description_
62 """
64 # Config needs to already supercede here !!!
66 self.config = Config(
67 api_key=api_key,
68 version=version,
69 application=application,
70 base_url=base_url,
71 timeout=timeout,
72 ssl_verify=ssl_verify,
73 user_config=config,
74 )
76 # Check version availability
77 if self.config.version not in self.config.versions:
78 raise EndpointNotImplemented("FIO version not supported")
80 # create adapter
81 self.adapter = FIOAdapter(header=self.get_header(), config=self.config)
83 # create urls
84 self.urls: URLs = URLs(self.config)
86 # add version 1.0.0 endpoints
87 if self.config.version == "1.0.0":
88 self.Building = building_v1.Building(self.adapter, self.urls)
89 self.Exchange = exchange_v1.Exchange(self.adapter, self.urls)
90 self.Group = group_v1.Group(self.adapter, self.urls)
91 self.LocalMarket = localmarket_v1.LocalMarket(self.adapter, self.urls)
92 self.Material = material_v1.Material(self.adapter, self.urls)
93 self.Planet = planet_v1.Planet(self.adapter, self.urls)
94 self.Recipe = recipe_v1.Recipe(self.adapter, self.urls)
95 self.Sites = sites_v1.Sites(self.adapter, self.urls)
96 self.Storage = storage_v1.Storage(self.adapter, self.urls)
98 def get_header(self) -> Dict[str, str]:
99 """Creates the header to be included in calls towards FIO
101 Returns:
102 Dict[str, str]: Contains "Authorization" and "X-FIO-Application"
103 """
104 return {
105 "Authorization": self.config.api_key,
106 "X-FIO-Application": self.config.application,
107 }