From 08795ca31ad7d709bdc925275134b40e8f585859 Mon Sep 17 00:00:00 2001 From: Matthew Wade Date: Thu, 18 Jan 2024 10:52:40 +0000 Subject: [PATCH 1/2] Add support for query_slots --- PKG-INFO | 2 +- pycronofy/__init__.py | 2 +- pycronofy/client.py | 26 +++++++++-- pycronofy/tests/test_availability.py | 67 ++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 5 deletions(-) diff --git a/PKG-INFO b/PKG-INFO index ed146cc..f3b6422 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: pycronofy -Version: 2.0.3 +Version: 2.0.4 Summary: Python wrapper for Cronofy Home-page: https://github.com/cronofy/pycronofy Author: VenueBook diff --git a/pycronofy/__init__.py b/pycronofy/__init__.py index 81b1768..5e8032e 100644 --- a/pycronofy/__init__.py +++ b/pycronofy/__init__.py @@ -1,6 +1,6 @@ from pycronofy.client import Client # noqa: F401 from pycronofy import settings -__version__ = '2.0.3' +__version__ = '2.0.4' __name__ = 'PyCronofy' """ diff --git a/pycronofy/client.py b/pycronofy/client.py index 5f81909..55c43b3 100644 --- a/pycronofy/client.py +++ b/pycronofy/client.py @@ -442,7 +442,16 @@ def read_free_busy(self, return Pages(self.request_handler, results, 'free_busy', automatic_pagination) - def availability(self, participants=(), required_duration=(), available_periods=(), start_interval=None, buffer=(), response_format=None): + def availability( + self, + participants=(), + required_duration=(), + available_periods=None, + start_interval=None, + buffer=(), + response_format=None, + query_slots=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. @@ -450,6 +459,7 @@ def availability(self, participants=(), required_duration=(), available_periods= :param dict or int start_interval - An Interger 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. :rtype: ``list`` """ @@ -465,8 +475,13 @@ def availability(self, participants=(), required_duration=(), available_periods= response_element = 'available_periods' - self.translate_available_periods(available_periods) - options['available_periods'] = available_periods + if available_periods: + self.translate_available_periods(available_periods) + options['available_periods'] = available_periods + + if query_slots: + self.translate_query_slots(query_slots) + options['query_slots'] = query_slots if response_format: options['response_format'] = response_format @@ -850,6 +865,11 @@ def translate_available_periods(self, periods): if params[tp]: params[tp] = format_event_time(params[tp]) + def translate_query_slots(self, query_slots): + for params in query_slots: + if params['start']: + params['start'] = format_event_time(params['start']) + def map_availability_sequence(self, sequence): if isinstance(sequence, collections.abc.Iterable): return list(map(lambda item: self.map_sequence_item(item), sequence)) diff --git a/pycronofy/tests/test_availability.py b/pycronofy/tests/test_availability.py index ff83f01..437162c 100644 --- a/pycronofy/tests/test_availability.py +++ b/pycronofy/tests/test_availability.py @@ -398,3 +398,70 @@ def request_callback(request): result = client.sequenced_availability(sequence=sequence, available_periods=periods) assert len(result) == 2 + + +@responses.activate +def test_availablity_with_query_slots(client): + """Test Client.availability(). + + :param Client client: Client instance with test data. + """ + + def request_callback(request): + payload = json.loads(request.body) + assert payload['required_duration'] == {'minutes': 30} + assert payload['start_interval'] == {'minutes': 30} + assert payload['buffer']['before'] == {'minutes': 30} + assert payload['buffer']['after'] == {'minutes': 45} + assert payload['query_slots'] == [ + {'start': '2017-01-03T09:00:00Z'}, + {'start': '2017-01-04T09:00:00Z'} + ] + assert payload['participants'] == [ + { + 'required': 'all', + 'members': [ + {'sub': 'acc_567236000909002'}, + {'sub': 'acc_678347111010113'} + ] + } + ] + assert payload['response_format'] == 'slots' + + return (200, {}, json.dumps(TEST_AVAILABLITY_RESPONSE_SLOTS)) + + responses.add_callback( + responses.POST, + url='%s/%s/availability' % (settings.API_BASE_URL, settings.API_VERSION), + callback=request_callback, + content_type='application/json', + ) + + query_slots = ( + {'start': "2017-01-03T09:00:00Z"}, + {'start': "2017-01-04T09:00:00Z"} + ) + + example_participants = ({ + 'members': [ + "acc_567236000909002", + "acc_678347111010113", + ], + }) + + example_buffer = { + 'before': 30, + 'after': {'minutes': 45} + } + + example_response_format = 'slots' + + result = client.availability( + required_duration=30, + query_slots=query_slots, + participants=example_participants, + start_interval=30, + buffer=example_buffer, + response_format=example_response_format + ) + assert len(result) == 2 From 79c96275115d968039ec5548115a10436d8bad45 Mon Sep 17 00:00:00 2001 From: Matthew Wade Date: Thu, 18 Jan 2024 10:54:32 +0000 Subject: [PATCH 2/2] Update the changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb72ce..d030142 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [2.0.4] +* Added support for the `query_slots` parameter to the `availability` query API [#104] + ## [2.0.3] * Support for event_creation param for Real Time Scheduling [#102] * Bug fix to accept callback_urls param for Real Time Scheduling [#101] @@ -26,6 +29,7 @@ ## [1.9.3] * Add support for Element Token generation [#70] +[2.0.4]: https://github.com/cronofy/pycronofy/releases/tag/2.0.4 [2.0.3]: https://github.com/cronofy/pycronofy/releases/tag/2.0.3 [2.0.2]: https://github.com/cronofy/pycronofy/releases/tag/2.0.2 [2.0.1]: https://github.com/cronofy/pycronofy/releases/tag/2.0.1 @@ -35,6 +39,7 @@ [1.9.4]: https://github.com/cronofy/pycronofy/releases/tag/1.9.4 [1.9.3]: https://github.com/cronofy/pycronofy/releases/tag/1.9.3 +[#104]: https://github.com/cronofy/pycronofy/pull/104 [#102]: https://github.com/cronofy/pycronofy/pull/102 [#101]: https://github.com/cronofy/pycronofy/pull/101 [#99]: https://github.com/cronofy/pycronofy/pull/99