11import logging
2- from typing import List
2+ from typing import List , Optional
3+
4+ from aiohttp import ClientSession
35
46from .exceptions import XIVAPIBadRequest , XIVAPIForbidden , XIVAPINotFound , XIVAPIServiceUnavailable , XIVAPIInvalidLanguage , XIVAPIError , XIVAPIInvalidIndex , XIVAPIInvalidColumns
57from .decorators import timed
@@ -13,19 +15,23 @@ class XIVAPIClient:
1315 Asynchronous client for accessing XIVAPI's endpoints.
1416 Parameters
1517 ------------
16- session: aiohttp.ClientSession()
17- The aiohttp session used with which to make http requests
1818 api_key: str
1919 The API key used for identifying your application with XIVAPI.com.
20+ session: Optional[ClientSession]
21+ Optionally include your aiohttp session
2022 """
23+ base_url = "https://xivapi.com"
24+ languages = ["en" , "fr" , "de" , "ja" ]
2125
22- def __init__ (self , session , api_key ):
23- self .session = session
26+ def __init__ (self , api_key : str , session : Optional [ClientSession ] = None ) -> None :
2427 self .api_key = api_key
28+ self ._session = session
2529
26- self .base_url = "https://xivapi.com"
27- self .languages = ["en" , "fr" , "de" , "ja" ]
28-
30+ @property
31+ def session (self ) -> ClientSession :
32+ if self ._session is None or self ._session .closed :
33+ self ._session = ClientSession ()
34+ return self ._session
2935
3036 @timed
3137 async def character_search (self , world , forename , surname , page = 1 ):
0 commit comments