Add workout schedule API support#296
Conversation
Integrates the GET /workout-service/schedule/{id} endpoint with get_scheduled_workout_by_id() method.
Add interactive demo that prompts user for scheduled workout ID with validation for required input and numeric format.
|
Warning
|
| Cohort / File(s) | Summary |
|---|---|
DocsREADME.md |
Updated Activity Data description to include scheduled workouts; increased Activities & Workouts method count from 20 to 21. |
Demo CLIdemo.py |
Added menu option "o" under Activities & Workouts; added get_scheduled_workout_by_id command wiring; implemented get_scheduled_workout_by_id_data to prompt for ID, validate, call API, display result, and handle exceptions. |
API Clientgarminconnect/__init__.py |
Added public garmin_workouts_schedule_url; added get_scheduled_workout_by_id(scheduled_workout_id) with positive-integer validation, URL construction, logging, and connectapi call. |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor U as User
participant D as demo.py (menu)
participant X as execute_api_call
participant G as Garmin client
participant C as connectapi (HTTP)
U->>D: Select "Get scheduled workout by ID"
D->>U: Prompt for scheduled_workout_id
U-->>D: Enter ID
D->>X: key="get_scheduled_workout_by_id"
X->>D: Invoke handler
D->>G: get_scheduled_workout_by_id(id)
G->>C: GET /workouts/schedule/{id}
C-->>G: JSON scheduled workout
G-->>D: Data
D-->>U: Display result
alt Invalid/missing ID
D-->>U: Error: ID required/invalid
else API error/exception
G-->>D: Raise error
D-->>U: Report exception
end
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
I hop through sprints and tidy code,
A workout found on data road!
With IDs fetched and menus neat,
I thump my paws to rhythmic beat—
Schedule set, the miles await,
Carrot cached, commit looks great.
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | The title "Add workout schedule API support" accurately reflects the primary change of the pull request, which introduces support for the scheduled workout endpoint via a new get_scheduled_workout_by_id method. It is concise and specific, avoiding vague or overly broad wording while clearly indicating the added API functionality. A reviewer scanning the history would immediately understand that this PR adds schedule-related workout API support. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
demo.py (1)
271-274: Guard against non-numeric IDs before calling the APIIf the user types a non-numeric ID, the underlying call raises
ValueError, which surfaces as “Unexpected error: invalid literal for int()…”. Catch that up front and give the user a clear message.try: scheduled_workout_id = input("Enter scheduled workout ID: ").strip() if not scheduled_workout_id: print("❌ Scheduled workout ID is required") return - call_and_display( - api.get_scheduled_workout_by_id, - scheduled_workout_id, - method_name="get_scheduled_workout_by_id", - api_call_desc=f"api.get_scheduled_workout_by_id({scheduled_workout_id})", - ) + try: + numeric_id = int(scheduled_workout_id) + except ValueError: + print("❌ Scheduled workout ID must be a positive integer") + return + + call_and_display( + api.get_scheduled_workout_by_id, + numeric_id, + method_name="get_scheduled_workout_by_id", + api_call_desc=f"api.get_scheduled_workout_by_id({numeric_id})", + )Also applies to: 1913-1929
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md(2 hunks)demo.py(3 hunks)garminconnect/__init__.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
demo.py (1)
garminconnect/__init__.py (1)
get_scheduled_workout_by_id(2105-2115)
🪛 LanguageTool
README.md
[grammar] ~67-~67: There might be a mistake here.
Context: ...es, training status, performance metrics - Device Information: Connected devices,...
(QB_NEW_EN)
🔇 Additional comments (2)
README.md (1)
41-41: Docs align with the new scheduled-workout supportThe coverage stats and feature list now match the added API surface—looks good.
Also applies to: 67-67
garminconnect/__init__.py (1)
265-266: Nice reuse of existing validation for the new endpointDeriving
garmin_workouts_schedule_urland piping the ID through_validate_positive_integerkeeps this consistent with the rest of the client. No issues spotted.Also applies to: 2104-2115
|
@federicopellegatta thank you for this nice addition! |
I have added support for retrieving scheduled workouts.
Specifically, this PR introduces the
get_scheduled_workout_by_idmethod, which integrates with the GET /workout-service/schedule/{id} API endpoint to fetch a single scheduled workout by its ID.This addition is particularly useful as it complements the work being done in #285. It allows for retrieving the full details of an individual workout after its ID has been obtained from a training plan.
Summary by CodeRabbit
New Features
Documentation