Skip to content

Commit

Permalink
Adds support for the max_results parameter to the availability endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
CronofyMatt committed Jan 25, 2024
1 parent 834d7ae commit 6a574cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pycronofy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,18 @@ def availability(
start_interval=None,
buffer=(),
response_format=None,
query_slots=None
query_slots=None,
max_results=None
):
""" Performs an availability query.
:param list participants: An Array of participant groups or a dict for a single participant group.
:param dict or int required_duration - An Integer representing the minimum number of minutes of availability required.
:param list available_periods - An Array of available time periods dicts, each must specify a start and end Time.
:param dict or int start_interval - An Interger representing the start interval minutes for the event.
:param dict or int start_interval - An Integer representing the start interval minutes for the event.
:param dict buffer - An Dict representing the buffer to apply to the request.
:param string response_format - periods, slots or overlapping_slots (Optional, default periods)
:param list query_slots - An Array of query slots, each much specify a start Time.
:param int max_results - An Integer describing the maximum number of available periods or slots to return from the query.
:rtype: ``list``
"""
Expand Down Expand Up @@ -488,6 +490,9 @@ def availability(
if response_format in ['slots', 'overlapping_slots']:
response_element = 'available_slots'

if max_results:
options['max_results'] = max_results

return self.request_handler.post(endpoint='availability', data=options).json()[response_element]

def sequenced_availability(self, sequence=(), available_periods=()):
Expand Down
10 changes: 9 additions & 1 deletion pycronofy/tests/test_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ def request_callback(request):
]
}
]
assert payload['max_results'] == 42

return (200, {}, json.dumps(TEST_AVAILABLITY_RESPONSE))

responses.add_callback(
Expand Down Expand Up @@ -307,7 +309,13 @@ def request_callback(request):
}
}

result = client.availability(required_duration={'minutes': 30}, available_periods=periods, participants=example_participants, buffer=example_buffer)
result = client.availability(
required_duration={'minutes': 30},
available_periods=periods,
participants=example_participants,
buffer=example_buffer,
max_results=42
)
assert len(result) == 1


Expand Down

0 comments on commit 6a574cd

Please sign in to comment.