8000 Add before and after date param support to Recordings iter method by morrissimo · Pull Request #226 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Add before and after date param support to Recordings iter method #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
18 changes: 18 additions & 0 deletions tests/test_recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ def test_paging(mock):
use_json_extension=True)


@patch("twilio.rest.resources.base.make_twilio_request")
def test_paging_iter(mock):
resp = create_mock_json("tests/resources/recordings_list.json")
mock.return_value = resp

uri = "%s/Recordings" % (BASE_URI)

next(recordings.iter(before=date(2010, 12, 5)))
exp_params = {'DateCreated<': '2010-12-05'}
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
use_json_extension=True)

next(recordings.iter(after=date(2012, 12, 7)))
exp_params = {'DateCreated>': '2012-12-07'}
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
use_json_extension=True)


@patch("twilio.rest.resources.base.make_twilio_request")
def test_get(mock):
resp = create_mock_json("tests/resources/recordings_instance.json")
Expand Down
12 changes: 12 additions & 0 deletions twilio/rest/resources/recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def list(self, before=None, after=None, **kwargs):
kwargs["DateCreated>"] = after
return self.get_instances(kwargs)

@normalize_dates
def iter(self, before=None, after=None, **kwargs):
"""
Returns an iterator of :class:`Recording` resources.

:param date after: Only list recordings logged after this datetime
:param date before: Only list recordings logger before this datetime
"""
kwargs["DateCreated<"] = before
kwargs["DateCreated>"] = after
return super(Recordings, self).iter(**kwargs)

def delete(self, sid):
"""
Delete the given recording
Expand Down
0