1212from aiohttp import ClientResponse , ClientSession , ClientError
1313
1414from typing import Any , Awaitable , Callable , Dict , List , Optional
15- from .const import (
16- GEOCACHING_API_BASE_PATH ,
17- GEOCACHING_API_HOST ,
18- GEOCACHING_API_PORT ,
19- GEOCACHING_API_SCHEME ,
20- GEOCACHING_API_VERSION ,
21- )
15+ from .const import ENVIRONMENT_SETTINGS
2216from .exceptions import (
2317 GeocachingApiConnectionError ,
2418 GeocachingApiConnectionTimeoutError ,
2822
2923from .models import (
3024 GeocachingStatus ,
31- GeocachingSettings
25+ GeocachingSettings ,
26+ GeocachingApiEnvironment ,
27+ GeocachingApiEnvironmentSettings
3228)
3329
3430_LOGGER = logging .getLogger (__name__ )
@@ -38,9 +34,11 @@ class GeocachingApi:
3834 _close_session : bool = False
3935 _status : GeocachingStatus = None
4036 _settings : GeocachingSettings = None
37+ _environment_settings : GeocachingApiEnvironmentSettings = None
4138 def __init__ (
4239 self ,
4340 * ,
41+ environment : GeocachingApiEnvironment ,
4442 token : str ,
4543 settings : GeocachingSettings = None ,
4644 request_timeout : int = 8 ,
@@ -49,6 +47,7 @@ def __init__(
4947
5048 ) -> None :
5149 """Initialize connection with the Geocaching API."""
50+ self ._environment_settings = ENVIRONMENT_SETTINGS [environment ]
5251 self ._status = GeocachingStatus ()
5352 self ._settings = settings or GeocachingSettings (False )
5453 self ._session = session
@@ -67,11 +66,12 @@ async def _request(self, method, uri, **kwargs) -> ClientResponse:
6766 _LOGGER .debug (f'Token refresh method called.' )
6867
6968 url = URL .build (
70- scheme = GEOCACHING_API_SCHEME ,
71- host = GEOCACHING_API_HOST ,
72- port = GEOCACHING_API_PORT ,
73- path = GEOCACHING_API_BASE_PATH ,
74- ).join (URL (uri ))
69+ scheme = self ._environment_settings ["api_scheme" ],
70+ host = self ._environment_settings ["api_host" ],
71+ port = self ._environment_settings ["api_port" ],
72+ path = self ._environment_settings ["api_base_bath" ],
73+ )
74+ url = str (url ) + uri
7575 _LOGGER .debug (f'Executing { method } API request to { url } .' )
7676 headers = kwargs .get ("headers" )
7777
@@ -155,7 +155,7 @@ async def _update_user(self, data: Dict[str, Any] = None) -> None:
155155 "awardedFavoritePoints" ,
156156 "membershipLevelId"
157157 ])
158- data = await self ._request ("GET" , f"/{ GEOCACHING_API_VERSION } / users/me?fields={ fields } " )
158+ data = await self ._request ("GET" , f"/users/me?fields={ fields } " )
159159 self ._status .update_user_from_dict (data )
160160 _LOGGER .debug (f'User updated.' )
161161
0 commit comments