Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion oura_api_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _make_request(
"""Make a request to the Oura API.

Args:
endpoint (str): The API endpoint to call
endpoint (str): The API endpoint to call (should start with /)
params (dict, optional): Query parameters for the request
method (str): HTTP method to use (default: GET)

Expand All @@ -81,6 +81,14 @@ def _make_request(
Raises:
requests.exceptions.RequestException: If the API request fails
"""
# Ensure endpoint starts with /
if not endpoint.startswith('/'):
endpoint = f"/{endpoint}"

# Remove any duplicate /v2 prefix if present
if endpoint.startswith('/v2/'):
endpoint = endpoint[3:] # Remove '/v2' prefix

url = f"{self.BASE_URL}{endpoint}"

if method.upper() == "GET":
Expand Down
4 changes: 2 additions & 2 deletions oura_api_client/api/daily_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_daily_activity_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/daily_activity", params=params
"/usercollection/daily_activity", params=params
)
return DailyActivityResponse(**response)

Expand All @@ -50,6 +50,6 @@ def get_daily_activity_document(
DailyActivityModel: Response containing daily activity data.
"""
response = self.client._make_request(
f"/v2/usercollection/daily_activity/{document_id}"
f"/usercollection/daily_activity/{document_id}"
)
return DailyActivityModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/daily_cardiovascular_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_daily_cardiovascular_age_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/daily_cardiovascular_age", params=params
"/usercollection/daily_cardiovascular_age", params=params
)
return DailyCardiovascularAgeResponse(**response)

Expand All @@ -55,6 +55,6 @@ def get_daily_cardiovascular_age_document(
cardiovascular age data.
"""
response = self.client._make_request(
f"/v2/usercollection/daily_cardiovascular_age/{document_id}"
f"/usercollection/daily_cardiovascular_age/{document_id}"
)
return DailyCardiovascularAgeModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/daily_readiness.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_daily_readiness_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/daily_readiness", params=params
"/usercollection/daily_readiness", params=params
)
return DailyReadinessResponse(**response)

Expand All @@ -53,6 +53,6 @@ def get_daily_readiness_document(
DailyReadinessModel: Response containing daily readiness data.
"""
response = self.client._make_request(
f"/v2/usercollection/daily_readiness/{document_id}"
f"/usercollection/daily_readiness/{document_id}"
)
return DailyReadinessModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/daily_resilience.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_daily_resilience_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/daily_resilience", params=params
"/usercollection/daily_resilience", params=params
)
return DailyResilienceResponse(**response)

Expand All @@ -53,6 +53,6 @@ def get_daily_resilience_document(
DailyResilienceModel: Response containing daily resilience data.
"""
response = self.client._make_request(
f"/v2/usercollection/daily_resilience/{document_id}"
f"/usercollection/daily_resilience/{document_id}"
)
return DailyResilienceModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/daily_sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_daily_sleep_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/daily_sleep", params=params
"/usercollection/daily_sleep", params=params
)
return DailySleepResponse(**response)

Expand All @@ -51,6 +51,6 @@ def get_daily_sleep_document(self, document_id: str) -> DailySleepModel:
DailySleepModel: Response containing daily sleep data.
"""
response = self.client._make_request(
f"/v2/usercollection/daily_sleep/{document_id}"
f"/usercollection/daily_sleep/{document_id}"
)
return DailySleepModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/daily_spo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_daily_spo2_documents( # Renamed method
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/daily_spo2", params=params
"/usercollection/daily_spo2", params=params
)
return DailySpO2Response(**response)

Expand All @@ -53,6 +53,6 @@ def get_daily_spo2_document(
DailySpO2Model: Response containing daily SpO2 data.
"""
response = self.client._make_request(
f"/v2/usercollection/daily_spo2/{document_id}"
f"/usercollection/daily_spo2/{document_id}"
)
return DailySpO2Model(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/daily_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_daily_stress_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/daily_stress", params=params
"/usercollection/daily_stress", params=params
)
return DailyStressResponse(**response)

Expand All @@ -51,6 +51,6 @@ def get_daily_stress_document(self, document_id: str) -> DailyStressModel:
DailyStressModel: Response containing daily stress data.
"""
response = self.client._make_request(
f"/v2/usercollection/daily_stress/{document_id}"
f"/usercollection/daily_stress/{document_id}"
)
return DailyStressModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/enhanced_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_enhanced_tag_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/enhanced_tag", params=params
"/usercollection/enhanced_tag", params=params
)
return EnhancedTagResponse(**response)

Expand All @@ -51,6 +51,6 @@ def get_enhanced_tag_document(self, document_id: str) -> EnhancedTagModel:
EnhancedTagModel: Response containing enhanced_tag data.
"""
response = self.client._make_request(
f"/v2/usercollection/enhanced_tag/{document_id}"
f"/usercollection/enhanced_tag/{document_id}"
)
return EnhancedTagModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/rest_mode_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_rest_mode_period_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/rest_mode_period", params=params
"/usercollection/rest_mode_period", params=params
)
return RestModePeriodResponse(**response)

Expand All @@ -53,6 +53,6 @@ def get_rest_mode_period_document(
RestModePeriodModel: Response containing rest_mode_period data.
"""
response = self.client._make_request(
f"/v2/usercollection/rest_mode_period/{document_id}"
f"/usercollection/rest_mode_period/{document_id}"
)
return RestModePeriodModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/ring_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_ring_configuration_documents(
final_params = {k: v for k, v in params.items() if v is not None}

response = self.client._make_request(
"/v2/usercollection/ring_configuration",
"/usercollection/ring_configuration",
params=final_params if final_params else None
)
return RingConfigurationResponse(**response)
Expand All @@ -67,6 +67,6 @@ def get_ring_configuration_document(
RingConfigurationModel: Response containing ring configuration data.
"""
response = self.client._make_request(
f"/v2/usercollection/ring_configuration/{document_id}"
f"/usercollection/ring_configuration/{document_id}"
)
return RingConfigurationModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_session_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/session", params=params
"/usercollection/session", params=params
)
return SessionResponse(**response)

Expand All @@ -51,6 +51,6 @@ def get_session_document(self, document_id: str) -> SessionModel:
SessionModel: Response containing session data.
"""
response = self.client._make_request(
f"/v2/usercollection/session/{document_id}"
f"/usercollection/session/{document_id}"
)
return SessionModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_sleep_documents( # Renamed method
params = {k: v for k, v in params.items() if v is not None}
# Corrected endpoint URL from daily_sleep to sleep
response = self.client._make_request(
"/v2/usercollection/sleep", params=params
"/usercollection/sleep", params=params
)
return SleepResponse(**response)

Expand All @@ -57,6 +57,6 @@ def get_sleep_document(
"""
# Corrected endpoint URL from daily_sleep to sleep
response = self.client._make_request(
f"/v2/usercollection/sleep/{document_id}"
f"/usercollection/sleep/{document_id}"
)
return SleepModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/sleep_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_sleep_time_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/sleep_time", params=params
"/usercollection/sleep_time", params=params
)
return SleepTimeResponse(**response)

Expand All @@ -58,6 +58,6 @@ def get_sleep_time_document(self, document_id: str) -> SleepTimeModel:
# sleep_time. Proceeding with the assumption it might exist or
# for future compatibility.
response = self.client._make_request(
f"/v2/usercollection/sleep_time/{document_id}"
f"/usercollection/sleep_time/{document_id}"
)
return SleepTimeModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_tag_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/tag", params=params
"/usercollection/tag", params=params
)
return TagResponse(**response)

Expand All @@ -48,6 +48,6 @@ def get_tag_document(self, document_id: str) -> TagModel:
TagModel: Response containing tag data.
"""
response = self.client._make_request(
f"/v2/usercollection/tag/{document_id}"
f"/usercollection/tag/{document_id}"
)
return TagModel(**response)
4 changes: 2 additions & 2 deletions oura_api_client/api/vo2_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_vo2_max_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/vO2_max", params=params
"/usercollection/vO2_max", params=params
)
return Vo2MaxResponse(**response)

Expand All @@ -48,6 +48,6 @@ def get_vo2_max_document(self, document_id: str) -> Vo2MaxModel:
Vo2MaxModel: Response containing VO2 max data.
"""
response = self.client._make_request(
f"/v2/usercollection/vO2_max/{document_id}"
f"/usercollection/vO2_max/{document_id}"
)
return Vo2MaxModel(**response)
12 changes: 6 additions & 6 deletions oura_api_client/api/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def list_webhook_subscriptions(self) -> List[WebhookSubscriptionModel]:
"""
headers = self._get_webhook_headers()
response_data = self.client._make_request(
"/v2/webhook/subscription",
"/webhook/subscription",
headers=headers
)
# API returns a list of subscriptions directly
Expand Down Expand Up @@ -77,7 +77,7 @@ def create_webhook_subscription(
verification_token=verification_token,
)
response_data = self.client._make_request(
"/v2/webhook/subscription",
"/webhook/subscription",
method="POST",
json_data=request_body.model_dump(
by_alias=True
Expand All @@ -95,7 +95,7 @@ def get_webhook_subscription(
"""
headers = self._get_webhook_headers()
response_data = self.client._make_request(
f"/v2/webhook/subscription/{subscription_id}",
f"/webhook/subscription/{subscription_id}",
headers=headers
)
return WebhookSubscriptionModel(**response_data)
Expand Down Expand Up @@ -123,7 +123,7 @@ def update_webhook_subscription(
data_type=data_type,
)
response_data = self.client._make_request(
f"/v2/webhook/subscription/{subscription_id}",
f"/webhook/subscription/{subscription_id}",
method="PUT",
json_data=request_body.model_dump(
by_alias=True, exclude_none=True
Expand All @@ -139,7 +139,7 @@ def delete_webhook_subscription(self, subscription_id: str) -> None:
"""
headers = self._get_webhook_headers()
self.client._make_request(
f"/v2/webhook/subscription/{subscription_id}",
f"/webhook/subscription/{subscription_id}",
method="DELETE",
headers=headers
)
Expand All @@ -160,7 +160,7 @@ def renew_webhook_subscription(
# headers['Content-Type'] = 'application/json'

response_data = self.client._make_request(
f"/v2/webhook/subscription/renew/{subscription_id}",
f"/webhook/subscription/renew/{subscription_id}",
method="PUT",
headers=headers
# No json_data for this specific renew endpoint as per typical
Expand Down
4 changes: 2 additions & 2 deletions oura_api_client/api/workout.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_workout_documents(
}
params = {k: v for k, v in params.items() if v is not None}
response = self.client._make_request(
"/v2/usercollection/workout", params=params
"/usercollection/workout", params=params
)
return WorkoutResponse(**response)

Expand All @@ -48,6 +48,6 @@ def get_workout_document(self, document_id: str) -> WorkoutModel:
WorkoutModel: Response containing workout data.
"""
response = self.client._make_request(
f"/v2/usercollection/workout/{document_id}"
f"/usercollection/workout/{document_id}"
)
return WorkoutModel(**response)
Loading