Skip to content

Add workout schedule API support#296

Merged
cyberjunky merged 3 commits intocyberjunky:masterfrom
federicopellegatta:feat/workout-schedule
Nov 4, 2025
Merged

Add workout schedule API support#296
cyberjunky merged 3 commits intocyberjunky:masterfrom
federicopellegatta:feat/workout-schedule

Conversation

@federicopellegatta
Copy link
Contributor

@federicopellegatta federicopellegatta commented Oct 15, 2025

I have added support for retrieving scheduled workouts.
Specifically, this PR introduces the get_scheduled_workout_by_id method, 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

    • Added ability to retrieve a scheduled workout by ID.
    • Introduced a new “Get scheduled workout by ID” option in the Activities & Workouts menu of the demo.
  • Documentation

    • Updated Activity Data description to include scheduled workouts alongside workouts, exercises, training status, and performance metrics.
    • Increased Activities & Workouts method count from 20 to 21 in API coverage and README.

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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid enum value. Expected 'chill' | 'assertive', received 'pythonic' at "reviews.profile"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

Adds scheduled workout support: README updates mention scheduled workouts and increment Activities & Workouts method count from 20 to 21; demo adds an interactive command to fetch a scheduled workout by ID; API client adds a schedule URL attribute and a method to fetch a scheduled workout by ID.

Changes

Cohort / File(s) Summary
Docs
README.md
Updated Activity Data description to include scheduled workouts; increased Activities & Workouts method count from 20 to 21.
Demo CLI
demo.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 Client
garminconnect/__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
Loading

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
demo.py (1)

271-274: Guard against non-numeric IDs before calling the API

If 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

📥 Commits

Reviewing files that changed from the base of the PR and between 749c248 and a96ea94.

📒 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 support

The 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 endpoint

Deriving garmin_workouts_schedule_url and piping the ID through _validate_positive_integer keeps this consistent with the rest of the client. No issues spotted.

Also applies to: 2104-2115

@cyberjunky
Copy link
Owner

@federicopellegatta thank you for this nice addition!

@cyberjunky cyberjunky merged commit ff91fb6 into cyberjunky:master Nov 4, 2025
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants