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 , \
57 XIVAPIInvalidLanguage , XIVAPIError , XIVAPIInvalidIndex , XIVAPIInvalidColumns , XIVAPIInvalidAlgo
@@ -14,15 +16,17 @@ class XIVAPIClient:
1416 Asynchronous client for accessing XIVAPI's endpoints.
1517 Parameters
1618 ------------
17- session: aiohttp.ClientSession()
18- The aiohttp session used with which to make http requests
1919 api_key: str
2020 The API key used for identifying your application with XIVAPI.com.
21+ session: Optional[ClientSession]
22+ Optionally include your aiohttp session
2123 """
24+ base_url = "https://xivapi.com"
25+ languages = ["en" , "fr" , "de" , "ja" ]
2226
23- def __init__ (self , session , api_key ):
24- self .session = session
27+ def __init__ (self , api_key : str , session : Optional [ClientSession ] = None ) -> None :
2528 self .api_key = api_key
29+ self ._session = session
2630
2731 self .base_url = "https://xivapi.com"
2832 self .languages = ["en" , "fr" , "de" , "ja" ]
@@ -31,6 +35,14 @@ def __init__(self, session, api_key):
3135 "match_phrase_prefix" , "multi_match" , "query_string"
3236 ]
3337
38+
39+ @property
40+ def session (self ) -> ClientSession :
41+ if self ._session is None or self ._session .closed :
42+ self ._session = ClientSession ()
43+ return self ._session
44+
45+
3446 @timed
3547 async def character_search (self , world , forename , surname , page = 1 ):
3648 """|coro|
0 commit comments