otf-api 0.14.0__py3-none-any.whl → 0.14.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
otf_api/__init__.py CHANGED
@@ -36,7 +36,7 @@ def _setup_logging() -> None:
36
36
 
37
37
  _setup_logging()
38
38
 
39
- __version__ = "0.14.0"
39
+ __version__ = "0.14.1"
40
40
 
41
41
 
42
42
  __all__ = ["Otf", "OtfUser", "models"]
otf_api/auth/auth.py CHANGED
@@ -3,6 +3,7 @@ import platform
3
3
  import typing
4
4
  from collections.abc import Generator
5
5
  from datetime import datetime
6
+ from functools import lru_cache
6
7
  from logging import getLogger
7
8
  from time import sleep
8
9
  from typing import Any, ClassVar
@@ -119,15 +120,21 @@ class OtfCognito(Cognito):
119
120
  self.mfa_tokens: dict[str, Any] = {}
120
121
  self.pool_domain_url: str | None = None
121
122
 
122
- self.idp_client: CognitoIdentityProviderClient = Session().client(
123
- "cognito-idp", config=BOTO_CONFIG, region_name=REGION
124
- ) # type: ignore
123
+ self.handle_login(password)
125
124
 
126
- self.id_client: CognitoIdentityClient = Session().client(
127
- "cognito-identity", config=BOTO_CONFIG, region_name=REGION
128
- ) # type: ignore
125
+ @property
126
+ @lru_cache(maxsize=1)
127
+ def idp_client(self) -> "CognitoIdentityProviderClient":
128
+ """Returns the Cognito Identity Provider client."""
129
+ LOGGER.debug("Creating Cognito Identity Provider client")
130
+ return Session().client("cognito-idp", config=BOTO_CONFIG, region_name=REGION) # type: ignore
129
131
 
130
- self.handle_login(password)
132
+ @property
133
+ @lru_cache(maxsize=1)
134
+ def id_client(self) -> "CognitoIdentityClient":
135
+ """Returns the Cognito Identity client."""
136
+ LOGGER.debug("Creating Cognito Identity client")
137
+ return Session().client("cognito-identity", config=BOTO_CONFIG, region_name=REGION) # type: ignore
131
138
 
132
139
  def handle_login(self, password: str | None = None) -> None:
133
140
  """Handles the login process for the user.
@@ -340,20 +347,6 @@ class OtfCognito(Cognito):
340
347
  self.device_group_key = device_metadata.get("DeviceGroupKey", self.device_group_key)
341
348
  CACHE.write_device_data_to_cache(self.device_metadata)
342
349
 
343
- def __getstate__(self):
344
- """Get the state of the object for pickling."""
345
- state = self.__dict__.copy()
346
- del state["idp_client"]
347
- del state["id_client"]
348
- return state
349
-
350
- def __setstate__(self, state): # noqa
351
- """Set the state of the object from a pickled state."""
352
- self.__dict__.update(state)
353
- self.idp_client = Session().client("cognito-idp", config=BOTO_CONFIG, region_name=REGION) # type: ignore
354
-
355
- self.id_client = Session().client("cognito-identity", config=BOTO_CONFIG, region_name=REGION) # type: ignore
356
-
357
350
 
358
351
  class HttpxCognitoAuth(httpx.Auth):
359
352
  http_header: str = "Authorization"
otf_api/cache.py CHANGED
@@ -130,3 +130,13 @@ def get_cache() -> OtfCache:
130
130
  LOGGER.debug("Using cache directory: %s", cache_dir)
131
131
  _CACHE = OtfCache(cache_dir)
132
132
  return _CACHE
133
+
134
+
135
+ def clear_cache() -> None:
136
+ """Clears the cache."""
137
+ try:
138
+ cache = get_cache()
139
+ cache.clear_device_data()
140
+ cache.clear_tokens()
141
+ except Exception:
142
+ LOGGER.exception("Failed to clear cache")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: otf-api
3
- Version: 0.14.0
3
+ Version: 0.14.1
4
4
  Summary: Python OrangeTheory Fitness API Client
5
5
  Author-email: Jessica Smith <j.smith.git1@gmail.com>
6
6
  License-Expression: MIT
@@ -1,5 +1,5 @@
1
- otf_api/__init__.py,sha256=gg7_JvYNdWRmAD0TtUR0XXwcfH_erUEdWRYsPfH2un0,1150
2
- otf_api/cache.py,sha256=m4xUBhaS0MkcZypon1jjfhJzZPRQBE5Fto4_RMReXZ0,4311
1
+ otf_api/__init__.py,sha256=y82vG9gK0GDrROU77pcel1uEWZsjN0E0zwJpDYpetGE,1150
2
+ otf_api/cache.py,sha256=7cOCZT9aabGyq3YeGFjHJBay76zkLZJahRxqafASdso,4540
3
3
  otf_api/exceptions.py,sha256=b6ZdH1dtYyUfXSupdVGGni6d66qqhzD0SGzyuty89gM,2174
4
4
  otf_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  otf_api/api/__init__.py,sha256=YC6bwYiAN6BSE7sqbxr2l34vwSdZPMGDv3wwPIQ_S3o,51
@@ -20,7 +20,7 @@ otf_api/api/workouts/__init__.py,sha256=GPb2cEsAxoaiJIP8Finrk9x9vUeL9NXA9iz2eya9
20
20
  otf_api/api/workouts/workout_api.py,sha256=6h-ErOOfGRcQ2a3NaOyvbCYfWuHCteugaqNWQwZ7UHY,13374
21
21
  otf_api/api/workouts/workout_client.py,sha256=GA8jYCOp313uDMwhNUvmX5G4NMS3LarJCPkM-dJbTuM,6736
22
22
  otf_api/auth/__init__.py,sha256=uTvFTNQVvfogTN_-4D3bRSundAf2enUJ5ji6PwO0xm8,104
23
- otf_api/auth/auth.py,sha256=N7PRohWlN4TMf6xWkD3LQTPaztGYqPFKgpHYMhzfZV8,17031
23
+ otf_api/auth/auth.py,sha256=QFI-FiMSjs38f_Fx7LRdrig5QpvnhGWKuaRIk6EUtEE,16788
24
24
  otf_api/auth/user.py,sha256=OChRG0EhZ63vEtT_Sg3NmXWmOD1vZcILuHhRXlwaG0I,2156
25
25
  otf_api/auth/utils.py,sha256=YBxqg2h59u4V1ij5kgqJDyKh0gtgOlXrSZdpAKSdelY,3954
26
26
  otf_api/models/__init__.py,sha256=P0IjxRUPIfzUI-e3VDMpipJeWr6BlypWAED2ovnZw-w,1545
@@ -52,8 +52,8 @@ otf_api/models/workouts/out_of_studio_workout_history.py,sha256=-BKp-MnIp_5-U2KW
52
52
  otf_api/models/workouts/performance_summary.py,sha256=R1p-g1L4XWWEiBYaGtX5JFvoS3Z6bzQrsPIfTQHDqyM,3464
53
53
  otf_api/models/workouts/telemetry.py,sha256=rKsmLbsOVUxUXH439zxxIEWYGTohKNemqrtMamAl5cA,3465
54
54
  otf_api/models/workouts/workout.py,sha256=_KIR9fLI4LgUlS02Q5SNauHd4aOqJI9H4uaFKf-xJOU,4580
55
- otf_api-0.14.0.dist-info/licenses/LICENSE,sha256=UaPT9ynYigC3nX8n22_rC37n-qmTRKLFaHrtUwF9ktE,1071
56
- otf_api-0.14.0.dist-info/METADATA,sha256=Ut4IOCHQto6qCo9cd-bmUpbmw-dqHLXDss4gQU8cqSU,2162
57
- otf_api-0.14.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
58
- otf_api-0.14.0.dist-info/top_level.txt,sha256=KAhYg1X2YG0LkTuVRhUV1I_AReNZUVNdEan7cp0pEE4,8
59
- otf_api-0.14.0.dist-info/RECORD,,
55
+ otf_api-0.14.1.dist-info/licenses/LICENSE,sha256=UaPT9ynYigC3nX8n22_rC37n-qmTRKLFaHrtUwF9ktE,1071
56
+ otf_api-0.14.1.dist-info/METADATA,sha256=5wsDwt1KWDalZTTIGo5wuZQ4EogEhLuB5wZs4sqhS5Y,2162
57
+ otf_api-0.14.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
58
+ otf_api-0.14.1.dist-info/top_level.txt,sha256=KAhYg1X2YG0LkTuVRhUV1I_AReNZUVNdEan7cp0pEE4,8
59
+ otf_api-0.14.1.dist-info/RECORD,,