Skip to content

Task 2: Centralize query parameter construction#21

Merged
godely merged 4 commits intomainfrom
task-2-centralize-params
Jun 8, 2025
Merged

Task 2: Centralize query parameter construction#21
godely merged 4 commits intomainfrom
task-2-centralize-params

Conversation

@godely
Copy link
Copy Markdown
Owner

@godely godely commented Jun 8, 2025

Summary

  • Fixes issue Task 2: Centralize query parameter construction #9: Extract common logic for date conversion, pagination, and filtering out None values
  • Creates a shared helper in oura_api_client/utils for parameter construction
  • Refactors all endpoint methods to use the new utility

Changes

  1. Created build_query_params utility function:

    • Converts date objects to ISO format strings automatically
    • Handles None value filtering
    • Supports additional parameters via kwargs
    • Located in oura_api_client/utils/query_params.py
  2. Refactored 16 endpoint modules to use the new utility:

    • Replaced repetitive parameter building code with single function call
    • Reduced ~10-15 lines of code per endpoint to just 1 line
    • Maintains exact same functionality with cleaner implementation
  3. Maintained backward compatibility:

    • All parameters work exactly as before
    • No changes to public API
    • All 101 tests continue to pass

Benefits

  • DRY principle: Eliminates code duplication across endpoints
  • Maintainability: Central location for parameter logic
  • Consistency: Ensures all endpoints handle parameters the same way
  • Testability: Parameter logic can now be unit tested separately

Test plan

  • Run existing test suite: python -m pytest tests/test_client.py
  • Verify all 101 tests pass
  • Run flake8 linting: flake8 oura_api_client/ (all issues fixed)
  • No changes needed to existing tests

Closes #9

🤖 Generated with Claude Code

godely and others added 4 commits June 8, 2025 10:33
- Refactor OuraClient._make_request to handle URL construction centrally
- Add logic to ensure endpoints start with / and remove duplicate /v2 prefixes
- Update all endpoint modules to use relative paths without /v2 prefix
- Update all tests to match new URL construction pattern
- All 101 tests passing

This fixes issue #8 where URLs were constructed as:
https://api.ouraring.com/v2/v2/usercollection/...

Now they correctly resolve to:
https://api.ouraring.com/v2/usercollection/...

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Create build_query_params utility function in oura_api_client/utils
- Handles date conversion from date objects to ISO strings
- Filters out None values automatically
- Refactor all endpoint modules to use the new utility
- Reduces code duplication across 16 endpoint files
- All 101 tests passing

This centralizes the common pattern:
- Converting date objects to ISO format strings
- Building params dict with start_date, end_date, next_token
- Filtering out None values

Closes #9

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix undefined variable in ring_configuration.py
- Remove unused List import from webhook.py
- Add newline at end of query_params.py
@godely godely merged commit 8292284 into main Jun 8, 2025
1 check passed
@godely godely deleted the task-2-centralize-params branch June 21, 2025 11:37
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.

Task 2: Centralize query parameter construction

1 participant