Skip to content

Commit

Permalink
Merge pull request #55 from NodeJSmith/fix/cleanup_old_cli_code
Browse files Browse the repository at this point in the history
Fix/cleanup old cli code, fix return type of `DoW.get_case_insensitive`
  • Loading branch information
NodeJSmith authored Sep 24, 2024
2 parents 1cb5d6c + d08c643 commit cd6cf06
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.6.2"
current_version = "0.6.3"

parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(?:-(?P<dev_l>dev)(?P<dev>0|[1-9]\\d*))?"

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: check-yaml
args: [--unsafe]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.6.7
hooks:
- id: ruff
language_version: python3
Expand Down
4 changes: 2 additions & 2 deletions examples/class_bookings_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from otf_api import Otf
from otf_api.models.responses.bookings import BookingStatus
from otf_api.models.responses.classes import ClassType
from otf_api.models.responses.classes import ClassType, DoW

USERNAME = os.getenv("OTF_EMAIL")
PASSWORD = os.getenv("OTF_PASSWORD")
Expand All @@ -27,7 +27,7 @@ async def main():
# You can pass a list of studio_uuids or, if you want to get classes from your home studio, leave it empty
# this also takes a start date, end date, and limit - these are not sent to the API, they are used in the
# client to filter the results
classes = await otf.get_classes(studio_uuids)
classes = await otf.get_classes(studio_uuids, day_of_week=[DoW.tuesday, DoW.thursday, DoW.saturday])

# get all statuses
class_types = dict(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "otf-api"
version = "0.6.2"
version = "0.6.3"
description = "Python OrangeTheory Fitness API Client"
authors = ["Jessica Smith <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/otf_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .api import Otf
from .auth import OtfUser

__version__ = "0.6.2"
__version__ = "0.6.3"


__all__ = ["Otf", "OtfUser"]
Expand Down
2 changes: 0 additions & 2 deletions src/otf_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
DoW,
EquipmentType,
FavoriteStudioList,
HistoryClassStatus,
LatestAgreement,
MemberDetail,
MemberMembership,
Expand Down Expand Up @@ -45,7 +44,6 @@
"DoW",
"EquipmentType",
"FavoriteStudioList",
"HistoryClassStatus",
"LatestAgreement",
"MemberDetail",
"MemberMembership",
Expand Down
3 changes: 1 addition & 2 deletions src/otf_api/models/responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .challenge_tracker_content import ChallengeTrackerContent
from .challenge_tracker_detail import ChallengeTrackerDetailList
from .classes import ClassType, DoW, OtfClassList
from .enums import ChallengeType, EquipmentType, HistoryClassStatus
from .enums import ChallengeType, EquipmentType
from .favorite_studios import FavoriteStudioList
from .latest_agreement import LatestAgreement
from .lifetime_stats import StatsResponse, StatsTime
Expand Down Expand Up @@ -35,7 +35,6 @@
"DoW",
"EquipmentType",
"FavoriteStudioList",
"HistoryClassStatus",
"LatestAgreement",
"MemberDetail",
"MemberMembership",
Expand Down
66 changes: 0 additions & 66 deletions src/otf_api/models/responses/bookings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from enum import Enum
from typing import ClassVar

from inflection import humanize
from pydantic import Field

from otf_api.models.base import OtfItemBase, OtfListBase
Expand All @@ -17,10 +16,6 @@ class StudioStatus(str, Enum):
TEMP_CLOSED = "Temporarily Closed"
PERM_CLOSED = "Permanently Closed"

@classmethod
def all_statuses(cls) -> list[str]:
return list(cls.__members__.values())


class BookingStatus(str, Enum):
CheckedIn = "Checked In"
Expand All @@ -34,46 +29,6 @@ class BookingStatus(str, Enum):
CheckinRequested = "Checkin Requested"
CheckinCancelled = "Checkin Cancelled"

@classmethod
def get_from_key_insensitive(cls, key: str) -> "BookingStatus":
lcase_to_actual = {item.lower(): item for item in cls._member_map_}
val = cls.__members__.get(lcase_to_actual[key.lower()])
if not val:
raise ValueError(f"Invalid BookingStatus: {key}")
return val

@classmethod
def get_case_insensitive(cls, value: str) -> str:
lcase_to_actual = {item.value.lower(): item.value for item in cls}
return lcase_to_actual[value.lower()]

@classmethod
def all_statuses(cls) -> list[str]:
return list(cls.__members__.values())


class BookingStatusCli(str, Enum):
"""Flipped enum so that the CLI does not have values with spaces"""

CheckedIn = "CheckedIn"
CancelCheckinPending = "CancelCheckinPending"
CancelCheckinRequested = "CancelCheckinRequested"
Cancelled = "Cancelled"
LateCancelled = "LateCancelled"
Booked = "Booked"
Waitlisted = "Waitlisted"
CheckinPending = "CheckinPending"
CheckinRequested = "CheckinRequested"
CheckinCancelled = "CheckinCancelled"

@classmethod
def to_standard_case_insensitive(cls, key: str) -> BookingStatus:
lcase_to_actual = {item.lower(): item for item in cls._member_map_}
val = cls.__members__.get(lcase_to_actual[key.lower()])
if not val:
raise ValueError(f"Invalid BookingStatus: {key}")
return BookingStatus(val)

@classmethod
def get_case_insensitive(cls, value: str) -> str:
lcase_to_actual = {item.value.lower(): item.value for item in cls}
Expand Down Expand Up @@ -162,23 +117,6 @@ class OtfClass(OtfItemBase, OtfClassTimeMixin):
location: Location
virtual_class: bool | None = Field(None, alias="virtualClass")

@classmethod
def attr_to_column_header(cls, attr: str) -> str:
attr_map = {k: humanize(k) for k in cls.model_fields}
overrides = {
"day_of_week": "Class DoW",
"date": "Class Date",
"time": "Class Time",
"duration": "Class Duration",
"name": "Class Name",
"is_home_studio": "Home Studio",
"is_booked": "Booked",
}

attr_map.update(overrides)

return attr_map.get(attr, attr)


class Member(OtfItemBase):
member_uuid: str = Field(alias="memberUUId")
Expand Down Expand Up @@ -216,10 +154,6 @@ class Booking(OtfItemBase):
otf_class: OtfClass = Field(alias="class")
is_home_studio: bool | None = Field(None, description="Custom helper field to determine if at home studio")

@property
def id_val(self) -> str:
return self.class_booking_id


class BookingList(OtfListBase):
collection_field: ClassVar[str] = "bookings"
Expand Down
34 changes: 2 additions & 32 deletions src/otf_api/models/responses/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class DoW(str, Enum):
sunday = "sunday"

@classmethod
def get_case_insensitive(cls, value: str) -> str:
lcase_to_actual = {item.value.lower(): item.value for item in cls}
def get_case_insensitive(cls, value: str) -> "DoW":
lcase_to_actual = {item.value.lower(): item for item in cls}
return lcase_to_actual[value.lower()]


Expand All @@ -34,38 +34,12 @@ class ClassType(str, Enum):
VIP_CLASS = "VIP Class"
OTHER = "Other"

@classmethod
def all_statuses(cls) -> list[str]:
return list(cls.__members__.values())

@classmethod
def get_from_key_insensitive(cls, key: str) -> "ClassType":
lcase_to_actual = {item.lower(): item for item in cls._member_map_}
val = cls.__members__.get(lcase_to_actual[key.lower()])
if not val:
raise ValueError(f"Invalid ClassType: {key}")
return val

@classmethod
def get_case_insensitive(cls, value: str) -> str:
lcase_to_actual = {item.value.lower(): item.value for item in cls}
return lcase_to_actual[value.lower()]


class ClassTypeCli(str, Enum):
"""Flipped enum so that the CLI does not have values with spaces"""

ORANGE_60_MIN_2G = "Orange_60_Min_2G"
TREAD_50 = "Tread_50"
STRENGTH_50 = "Strength_50"
ORANGE_3G = "Orange_3G"
ORANGE_60_TORNADO = "Orange_60_Tornado"
ORANGE_TORNADO = "Orange_Tornado"
ORANGE_90_MIN_3G = "Orange_90_Min_3G"
VIP_CLASS = "VIP_Class"
OTHER = "Other"


class Address(OtfItemBase):
line1: str
city: str
Expand Down Expand Up @@ -163,10 +137,6 @@ class OtfClass(OtfItemBase, OtfClassTimeMixin):
def has_availability(self) -> bool:
return not self.full

@property
def id_val(self) -> str:
return self.ot_class_uuid

@property
def day_of_week_enum(self) -> DoW:
dow = self.starts_at_local.strftime("%A")
Expand Down
29 changes: 0 additions & 29 deletions src/otf_api/models/responses/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,3 @@ class ChallengeType(int, Enum):
RemixInSix = 65
Push = 66
BackAtIt = 84


class HistoryBookingStatus(str, Enum):
Attended = "Attended"
Cancelled = "Cancelled"
LateCancelled = "Late Cancelled"

@classmethod
def all_statuses(cls) -> list[str]:
return list(cls.__members__.values())


class HistoryClassStatus(str, Enum):
CheckedIn = "Checked In"
CancelCheckinPending = "Cancel Checkin Pending"
CancelCheckinRequested = "Cancel Checkin Requested"
LateCancelled = "Late Cancelled"
Booked = "Booked"
Waitlisted = "Waitlisted"
CheckinPending = "Checkin Pending"
CheckinRequested = "Checkin Requested"
CheckinCancelled = "Checkin Cancelled"
Pending = "Pending"
Confirmed = "Confirmed"
Requested = "Requested"

@classmethod
def all_statuses(cls) -> list[str]:
return list(cls.__members__.values())
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from otf_api.api import Otf


Expand Down

0 comments on commit cd6cf06

Please sign in to comment.