77
88# Local imports
99from fitbit_client .resources .base import BaseResource
10+ from fitbit_client .resources .constants import SortDirection
1011from fitbit_client .utils .date_validation import validate_date_param
12+ from fitbit_client .utils .pagination_validation import validate_pagination_params
1113
1214
1315class IrregularRhythmNotificationsResource (BaseResource ):
@@ -31,13 +33,14 @@ class IrregularRhythmNotificationsResource(BaseResource):
3133
3234 @validate_date_param (field_name = "before_date" )
3335 @validate_date_param (field_name = "after_date" )
36+ @validate_pagination_params (max_limit = 10 )
3437 def get_irn_alerts_list (
3538 self ,
36- sort : str ,
37- limit : int = 10 ,
38- offset : int = 0 ,
3939 before_date : Optional [str ] = None ,
4040 after_date : Optional [str ] = None ,
41+ sort : SortDirection = SortDirection .DESCENDING ,
42+ limit : int = 10 ,
43+ offset : int = 0 ,
4144 user_id : str = "-" ,
4245 debug : bool = False ,
4346 ) -> Dict [str , Any ]:
@@ -47,49 +50,36 @@ def get_irn_alerts_list(
4750 API Reference: https://dev.fitbit.com/build/reference/web-api/irregular-rhythm-notifications/get-irn-alerts-list/
4851
4952 Args:
50- sort: Sort order of entries by date. Use 'asc' with after_date, 'desc' with before_date
51- limit: Number of entries to return (max 10)
52- offset: Pagination offset (only 0 is supported)
5353 before_date: Date in yyyy-MM-ddTHH:mm:ss format (at least yyyy-MM-dd required)
5454 after_date: Date in yyyy-MM-ddTHH:mm:ss format (at least yyyy-MM-dd required)
55+ sort: Sort order - use 'asc' with after_date, 'desc' with before_date
56+ limit: Number of entries to return (max 10)
57+ offset: Pagination offset (only 0 is supported)
5558 user_id: The encoded ID of the user. Use "-" (dash) for current logged-in user.
5659 debug: If True, a prints a curl command to stdout to help with debugging (default: False)
5760
61+ Note:
62+ Either before_date or after_date must be specified.
63+ The offset parameter only supports 0 and using other values may break your application.
64+ Use the pagination links in the response to iterate through results.
65+
5866 Returns:
5967 Dictionary containing:
6068 - alerts: List of IRN alerts with detection times and heart rate data
6169 - pagination: Information for retrieving next/previous pages
6270
6371 Raises:
64- ValueError : If neither before_date nor after_date is specified
65- ValueError : If offset is not 0
66- ValueError : If limit exceeds 10
67- ValueError : If sort is not 'asc' or 'desc'
68- ValueError : If sort direction doesn't match date parameter
72+ PaginatonError : If neither before_date nor after_date is specified
73+ PaginatonError : If offset is not 0
74+ PaginatonError : If limit exceeds 10
75+ PaginatonError : If sort is not 'asc' or 'desc'
76+ PaginatonError : If sort direction doesn't match date parameter
6977 InvalidDateException: If date format is invalid
7078
7179 Note:
7280 Either before_date or after_date must be specified.
7381 """
74- if offset != 0 :
75- raise ValueError ("Only offset=0 is supported for IRN alerts pagination" )
76-
77- if limit > 10 :
78- raise ValueError ("Maximum limit is 10 entries" )
79-
80- if not before_date and not after_date :
81- raise ValueError ("Either before_date or after_date must be specified" )
82-
83- if sort not in ["asc" , "desc" ]:
84- raise ValueError ("Sort must be either 'asc' or 'desc'" )
85-
86- if sort == "asc" and not after_date :
87- raise ValueError ("Must use after_date with ascending sort" )
88-
89- if sort == "desc" and not before_date :
90- raise ValueError ("Must use before_date with descending sort" )
91-
92- params = {"sort" : sort , "limit" : limit , "offset" : offset }
82+ params = {"sort" : sort .value , "limit" : limit , "offset" : offset }
9383
9484 if before_date :
9585 params ["beforeDate" ] = before_date
0 commit comments