1
1
import logging
2
- from typing import List
2
+ from typing import List , Optional
3
+
4
+ from aiohttp import ClientSession
3
5
4
6
from .exceptions import XIVAPIBadRequest , XIVAPIForbidden , XIVAPINotFound , XIVAPIServiceUnavailable , XIVAPIInvalidLanguage , XIVAPIError , XIVAPIInvalidIndex , XIVAPIInvalidColumns
5
7
from .decorators import timed
@@ -13,19 +15,23 @@ class XIVAPIClient:
13
15
Asynchronous client for accessing XIVAPI's endpoints.
14
16
Parameters
15
17
------------
16
- session: aiohttp.ClientSession()
17
- The aiohttp session used with which to make http requests
18
18
api_key: str
19
19
The API key used for identifying your application with XIVAPI.com.
20
+ session: Optional[ClientSession]
21
+ Optionally include your aiohttp session
20
22
"""
23
+ base_url = "https://xivapi.com"
24
+ languages = ["en" , "fr" , "de" , "ja" ]
21
25
22
- def __init__ (self , session , api_key ):
23
- self .session = session
26
+ def __init__ (self , api_key : str , session : Optional [ClientSession ] = None ) -> None :
24
27
self .api_key = api_key
28
+ self ._session = session
25
29
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
29
35
30
36
@timed
31
37
async def character_search (self , world , forename , surname , page = 1 ):
0 commit comments