Skip to content

Commit

Permalink
Merge pull request #104 from cronofy/add-query_slots-support
Browse files Browse the repository at this point in the history
Add support for query_slots
  • Loading branch information
CronofyMatt authored Jan 18, 2024
2 parents fe3dd4f + 79c9627 commit 834d7ae
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pycronofy/__init__.py
Original file line number Diff line number Diff line change
@@ -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'

"""
Expand Down
26 changes: 23 additions & 3 deletions pycronofy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,24 @@ 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.
: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 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``
"""
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down
67 changes: 67 additions & 0 deletions pycronofy/tests/test_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 834d7ae

Please sign in to comment.