otf-api 0.2.0__tar.gz

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.
Files changed (38) hide show
  1. otf_api-0.2.0/AUTHORS.md +9 -0
  2. otf_api-0.2.0/LICENSE +21 -0
  3. otf_api-0.2.0/PKG-INFO +28 -0
  4. otf_api-0.2.0/README.md +1 -0
  5. otf_api-0.2.0/pyproject.toml +70 -0
  6. otf_api-0.2.0/src/otf_api/__init__.py +70 -0
  7. otf_api-0.2.0/src/otf_api/__version__.py +1 -0
  8. otf_api-0.2.0/src/otf_api/api.py +143 -0
  9. otf_api-0.2.0/src/otf_api/classes_api.py +44 -0
  10. otf_api-0.2.0/src/otf_api/member_api.py +380 -0
  11. otf_api-0.2.0/src/otf_api/models/__init__.py +63 -0
  12. otf_api-0.2.0/src/otf_api/models/auth.py +141 -0
  13. otf_api-0.2.0/src/otf_api/models/base.py +7 -0
  14. otf_api-0.2.0/src/otf_api/models/responses/__init__.py +60 -0
  15. otf_api-0.2.0/src/otf_api/models/responses/bookings.py +130 -0
  16. otf_api-0.2.0/src/otf_api/models/responses/challenge_tracker_content.py +38 -0
  17. otf_api-0.2.0/src/otf_api/models/responses/challenge_tracker_detail.py +68 -0
  18. otf_api-0.2.0/src/otf_api/models/responses/classes.py +57 -0
  19. otf_api-0.2.0/src/otf_api/models/responses/enums.py +87 -0
  20. otf_api-0.2.0/src/otf_api/models/responses/favorite_studios.py +106 -0
  21. otf_api-0.2.0/src/otf_api/models/responses/latest_agreement.py +21 -0
  22. otf_api-0.2.0/src/otf_api/models/responses/member_detail.py +134 -0
  23. otf_api-0.2.0/src/otf_api/models/responses/member_membership.py +25 -0
  24. otf_api-0.2.0/src/otf_api/models/responses/member_purchases.py +135 -0
  25. otf_api-0.2.0/src/otf_api/models/responses/out_of_studio_workout_history.py +41 -0
  26. otf_api-0.2.0/src/otf_api/models/responses/performance_summary_detail.py +77 -0
  27. otf_api-0.2.0/src/otf_api/models/responses/performance_summary_list.py +67 -0
  28. otf_api-0.2.0/src/otf_api/models/responses/studio_detail.py +111 -0
  29. otf_api-0.2.0/src/otf_api/models/responses/studio_services.py +57 -0
  30. otf_api-0.2.0/src/otf_api/models/responses/telemetry.py +53 -0
  31. otf_api-0.2.0/src/otf_api/models/responses/telemetry_hr_history.py +34 -0
  32. otf_api-0.2.0/src/otf_api/models/responses/telemetry_max_hr.py +13 -0
  33. otf_api-0.2.0/src/otf_api/models/responses/total_classes.py +8 -0
  34. otf_api-0.2.0/src/otf_api/models/responses/workouts.py +78 -0
  35. otf_api-0.2.0/src/otf_api/performance_api.py +54 -0
  36. otf_api-0.2.0/src/otf_api/py.typed +0 -0
  37. otf_api-0.2.0/src/otf_api/studios_api.py +96 -0
  38. otf_api-0.2.0/src/otf_api/telemetry_api.py +95 -0
@@ -0,0 +1,9 @@
1
+ # Credits
2
+
3
+ ## Development Lead
4
+
5
+ * Jessica Smith <j.smith.git1@gmail.com>
6
+
7
+ ## Contributors
8
+
9
+ None yet. Why not be the first?
otf_api-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024, Jessica Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
otf_api-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.1
2
+ Name: otf-api
3
+ Version: 0.2.0
4
+ Summary: Python OrangeTheory Fitness API Client
5
+ License: MIT
6
+ Author: Jessica Smith
7
+ Author-email: j.smith.git1@gmail.com
8
+ Requires-Python: >=3.10,<4.0
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Dist: aiohttp (==3.9.5)
22
+ Requires-Dist: loguru (==0.7.2)
23
+ Requires-Dist: pycognito (==2024.5.1)
24
+ Requires-Dist: pydantic (==2.7.3)
25
+ Description-Content-Type: text/markdown
26
+
27
+ Simple API client for interacting with the OrangeTheory APIs. This project is in now way affiliated with OrangeTheory Fitness.
28
+
@@ -0,0 +1 @@
1
+ Simple API client for interacting with the OrangeTheory APIs. This project is in now way affiliated with OrangeTheory Fitness.
@@ -0,0 +1,70 @@
1
+ [tool.poetry]
2
+ name = "otf-api"
3
+ version = "0.2.0"
4
+ description = "Python OrangeTheory Fitness API Client"
5
+ authors = ["Jessica Smith <j.smith.git1@gmail.com>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+
9
+ classifiers = [
10
+ "Development Status :: 4 - Beta",
11
+ "Intended Audience :: Developers",
12
+ "Programming Language :: Python :: 3.10",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Topic :: Software Development :: Libraries :: Python Modules",
15
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
16
+ "Topic :: Software Development :: Libraries",
17
+ "Topic :: Internet :: WWW/HTTP",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+
21
+
22
+ [tool.poetry.dependencies]
23
+ python = "^3.10"
24
+ aiohttp = "3.9.5"
25
+ loguru = "0.7.2"
26
+ pydantic = "2.7.3"
27
+ pycognito = "2024.5.1"
28
+
29
+
30
+ [tool.poetry.group.dev.dependencies]
31
+ pytest = "8.2.2"
32
+ pytest-loguru = "0.4.0"
33
+ pytest-asyncio = "0.23.7"
34
+ aioresponses = "0.7.6"
35
+ tox = "4.15.1"
36
+ pytest-cov = "5.0.0"
37
+ build = "1.2.1"
38
+ ruff = "0.4.9"
39
+ pre-commit = "3.7.1"
40
+ mypy = "1.10.0"
41
+ twine = "5.1.0"
42
+ black = "^24.4.2"
43
+ httpx = "^0.27.0"
44
+ bump-my-version = "^0.23.0"
45
+
46
+
47
+ [tool.poetry.group.docs.dependencies]
48
+ mkdocs = "1.6.0"
49
+ mkdocs-autorefs = "1.0.1"
50
+ mkdocs-gen-files = "0.5.0"
51
+ mkdocs-get-deps = "0.2.0"
52
+ mkdocs-include-markdown-plugin = "6.2.0"
53
+ mkdocs-literate-nav = "0.6.1"
54
+ mkdocs-material = "9.5.26"
55
+ mkdocs-material-extensions = "1.3.1"
56
+ mkdocs-section-index = "0.3.9"
57
+ mkdocstrings = "0.25.1"
58
+ mkdocstrings-python = "1.10.3"
59
+ griffe-fieldz = "0.1.2"
60
+ mike = "2.1.1"
61
+ setuptools = "^70.0.0"
62
+ pkginfo = "^1.11.1"
63
+ virtualenv = "^20.26.2"
64
+
65
+ [build-system]
66
+ requires = ["poetry-core"]
67
+ build-backend = "poetry.core.masonry.api"
68
+
69
+ [tools.pytest.ini_options]
70
+ pythonpath = ["src"]
@@ -0,0 +1,70 @@
1
+ from . import classes_api, member_api, studios_api, telemetry_api
2
+ from .api import Api
3
+ from .models.auth import User
4
+ from .models.responses import (
5
+ ALL_CLASS_STATUS,
6
+ ALL_HISTORY_CLASS_STATUS,
7
+ ALL_STUDIO_STATUS,
8
+ BookingList,
9
+ BookingStatus,
10
+ ChallengeTrackerContent,
11
+ ChallengeTrackerDetailList,
12
+ ChallengeType,
13
+ EquipmentType,
14
+ FavoriteStudioList,
15
+ HistoryClassStatus,
16
+ LatestAgreement,
17
+ MemberDetail,
18
+ MemberMembership,
19
+ MemberPurchaseList,
20
+ OtfClassList,
21
+ OutOfStudioWorkoutHistoryList,
22
+ PerformanceSummaryDetail,
23
+ PerformanceSummaryList,
24
+ StudioDetail,
25
+ StudioDetailList,
26
+ StudioServiceList,
27
+ StudioStatus,
28
+ Telemetry,
29
+ TelemetryHrHistory,
30
+ TelemetryMaxHr,
31
+ TotalClasses,
32
+ WorkoutList,
33
+ )
34
+
35
+ __all__ = [
36
+ "Api",
37
+ "User",
38
+ "member_api",
39
+ "BookingList",
40
+ "ChallengeTrackerContent",
41
+ "ChallengeTrackerDetailList",
42
+ "ChallengeType",
43
+ "BookingStatus",
44
+ "EquipmentType",
45
+ "HistoryClassStatus",
46
+ "LatestAgreement",
47
+ "MemberDetail",
48
+ "MemberMembership",
49
+ "MemberPurchaseList",
50
+ "OutOfStudioWorkoutHistoryList",
51
+ "StudioServiceList",
52
+ "StudioStatus",
53
+ "TotalClasses",
54
+ "WorkoutList",
55
+ "FavoriteStudioList",
56
+ "OtfClassList",
57
+ "classes_api",
58
+ "studios_api",
59
+ "telemetry_api",
60
+ "TelemetryHrHistory",
61
+ "Telemetry",
62
+ "TelemetryMaxHr",
63
+ "StudioDetail",
64
+ "StudioDetailList",
65
+ "ALL_CLASS_STATUS",
66
+ "ALL_HISTORY_CLASS_STATUS",
67
+ "ALL_STUDIO_STATUS",
68
+ "PerformanceSummaryDetail",
69
+ "PerformanceSummaryList",
70
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
@@ -0,0 +1,143 @@
1
+ import asyncio
2
+ import typing
3
+ from typing import Any
4
+
5
+ import aiohttp
6
+ from loguru import logger
7
+ from yarl import URL
8
+
9
+ from otf_api.classes_api import ClassesApi
10
+ from otf_api.member_api import MemberApi
11
+ from otf_api.models.auth import User
12
+ from otf_api.performance_api import PerformanceApi
13
+ from otf_api.studios_api import StudiosApi
14
+ from otf_api.telemetry_api import TelemtryApi
15
+
16
+ if typing.TYPE_CHECKING:
17
+ from loguru import Logger
18
+
19
+ from otf_api.models.responses.member_detail import MemberDetail
20
+ from otf_api.models.responses.studio_detail import StudioDetail
21
+
22
+ API_BASE_URL = "api.orangetheory.co"
23
+ API_IO_BASE_URL = "api.orangetheory.io"
24
+ API_TELEMETRY_BASE_URL = "api.yuzu.orangetheory.com"
25
+ REQUEST_HEADERS = {"Authorization": None, "Content-Type": "application/json", "Accept": "application/json"}
26
+
27
+
28
+ class Api:
29
+ """The main class of the otf-api library. Create an instance using the async method `create`.
30
+
31
+ Example:
32
+ ---
33
+ ```python
34
+ import asyncio
35
+ from otf_api import Api
36
+
37
+ async def main():
38
+ otf = await Api.create("username", "password")
39
+ print(otf.member)
40
+
41
+ if __name__ == "__main__":
42
+ asyncio.run(main())
43
+ ```
44
+ """
45
+
46
+ logger: "Logger" = logger
47
+ user: User
48
+ session: aiohttp.ClientSession
49
+
50
+ def __init__(self, username: str, password: str):
51
+ self.member: MemberDetail
52
+ self.home_studio: StudioDetail
53
+
54
+ self.user = User.load_from_disk(username, password)
55
+ self.session = aiohttp.ClientSession()
56
+
57
+ self.member_api = MemberApi(self)
58
+ self.classes_api = ClassesApi(self)
59
+ self.studios_api = StudiosApi(self)
60
+ self.telemetry_api = TelemtryApi(self)
61
+ self.performance_api = PerformanceApi(self)
62
+
63
+ @classmethod
64
+ async def create(cls, username: str, password: str) -> "Api":
65
+ """Create a new API instance. The username and password are required arguments because even though
66
+ we cache the token, they expire so quickly that we usually end up needing to re-authenticate.
67
+
68
+ Args:
69
+ username (str): The username of the user.
70
+ password (str): The password of the user.
71
+ """
72
+ self = cls(username, password)
73
+ self.member = await self.member_api.get_member_detail()
74
+ self.home_studio = await self.studios_api.get_studio_detail(self.member.home_studio.studio_uuid)
75
+ return self
76
+
77
+ def __del__(self) -> None:
78
+ try:
79
+ loop = asyncio.get_event_loop()
80
+ asyncio.create_task(self._close_session()) # noqa
81
+ except RuntimeError:
82
+ loop = asyncio.new_event_loop()
83
+ loop.run_until_complete(self._close_session())
84
+
85
+ async def _close_session(self) -> None:
86
+ if not self.session.closed:
87
+ await self.session.close()
88
+
89
+ @property
90
+ def _base_headers(self) -> dict[str, str]:
91
+ """Get the base headers for the API."""
92
+ if not self.user:
93
+ raise ValueError("No user is logged in.")
94
+
95
+ return {
96
+ "Authorization": f"Bearer {self.user.cognito.id_token}",
97
+ "Content-Type": "application/json",
98
+ "Accept": "application/json",
99
+ }
100
+
101
+ async def _do(
102
+ self,
103
+ method: str,
104
+ base_url: str,
105
+ url: str,
106
+ params: dict[str, Any] | None = None,
107
+ headers: dict[str, str] | None = None,
108
+ ) -> Any:
109
+ """Perform an API request."""
110
+
111
+ params = params or {}
112
+ params = {k: v for k, v in params.items() if v is not None}
113
+
114
+ full_url = str(URL.build(scheme="https", host=base_url, path=url))
115
+
116
+ logger.debug(f"Making {method!r} request to {full_url}, params: {params}")
117
+
118
+ if headers:
119
+ headers.update(self._base_headers)
120
+ else:
121
+ headers = self._base_headers
122
+
123
+ async with self.session.request(method, full_url, headers=headers, params=params) as response:
124
+ response.raise_for_status()
125
+ return await response.json()
126
+
127
+ async def _classes_request(self, method: str, url: str, params: dict[str, Any] | None = None) -> Any:
128
+ """Perform an API request to the classes API."""
129
+ return await self._do(method, API_IO_BASE_URL, url, params)
130
+
131
+ async def _default_request(self, method: str, url: str, params: dict[str, Any] | None = None) -> Any:
132
+ """Perform an API request to the default API."""
133
+ return await self._do(method, API_BASE_URL, url, params)
134
+
135
+ async def _telemetry_request(self, method: str, url: str, params: dict[str, Any] | None = None) -> Any:
136
+ """Perform an API request to the Telemetry API."""
137
+ return await self._do(method, API_TELEMETRY_BASE_URL, url, params)
138
+
139
+ async def _performance_summary_request(
140
+ self, method: str, url: str, headers: dict[str, str], params: dict[str, Any] | None = None
141
+ ) -> Any:
142
+ """Perform an API request to the performance summary API."""
143
+ return await self._do(method, API_IO_BASE_URL, url, params, headers)
@@ -0,0 +1,44 @@
1
+ import typing
2
+
3
+ from otf_api.models.responses.classes import OtfClassList
4
+
5
+ if typing.TYPE_CHECKING:
6
+ from otf_api import Api
7
+
8
+
9
+ class ClassesApi:
10
+ def __init__(self, api: "Api"):
11
+ self._api = api
12
+ self.logger = api.logger
13
+
14
+ # simplify access to member_id and member_uuid
15
+ self._member_id = self._api.user.member_id
16
+ self._member_uuid = self._api.user.member_uuid
17
+
18
+ async def get_classes(
19
+ self, studio_uuids: list[str] | None = None, include_home_studio: bool = True
20
+ ) -> OtfClassList:
21
+ """Get the classes for the user.
22
+
23
+ Returns a list of classes that are available for the user, based on the studio UUIDs provided. If no studio
24
+ UUIDs are provided, it will default to the user's home studio.
25
+
26
+ Args:
27
+ studio_uuids (list[str] | None): The studio UUIDs to get the classes for. Default is None, which will\
28
+ default to the user's home studio only.
29
+ include_home_studio (bool): Whether to include the home studio in the classes. Default is True.
30
+
31
+ Returns:
32
+ OtfClassList: The classes for the user.
33
+ """
34
+
35
+ if not studio_uuids:
36
+ studio_uuids = [self._api.home_studio.studio_uuid]
37
+ elif include_home_studio and self._api.home_studio.studio_uuid not in studio_uuids:
38
+ studio_uuids.append(self._api.home_studio.studio_uuid)
39
+
40
+ path = "/v1/classes"
41
+
42
+ params = {"studio_ids": studio_uuids}
43
+ res = await self._api._classes_request("GET", path, params=params)
44
+ return OtfClassList(classes=res["items"])