diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index ac9ce48..6886741 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.10.12] steps: - uses: actions/checkout@v2 @@ -49,7 +49,7 @@ jobs: - name: Set up Python 🐍 uses: actions/setup-python@v1 with: - python-version: "3.x" + python-version: "3.10.12" - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d929d8..5ced689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] +## [v4.5.0] - 2022-07-26 + +Adds support for Cancel Message API + ## [v4.4.0] - 2022-07-26 Adds support for Audit Events API diff --git a/setup.py b/setup.py index 8a0f60e..1173fab 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="trycourier", - version="4.4.0", + version="4.5.0", author="Courier", author_email="support@courier.com", description="A Python Package for communicating with the Courier REST API.", diff --git a/tests/test_messages.py b/tests/test_messages.py index 25b16da..9a52f68 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -4,6 +4,7 @@ from trycourier.client import Courier from trycourier.exceptions import CourierAPIException + @responses.activate def test_success_messages_list(): responses.add( @@ -99,7 +100,8 @@ def test_success_messages_get_history(): c = Courier(auth_token='123456789ABCDF') r = c.messages.get_history(message_id="my.message.id") - assert r == {'results':[]} + assert r == {'results': []} + @responses.activate def test_success_messages_get_history_with_params(): @@ -114,7 +116,7 @@ def test_success_messages_get_history_with_params(): c = Courier(auth_token='123456789ABCDF') r = c.messages.get_history(message_id="my.message.id", type="my.type") - assert r == {'results':[]} + assert r == {'results': []} @responses.activate @@ -133,6 +135,17 @@ def test_fail_messages_get_history(): c.messages.get_history("my.message.id") +@responses.activate +def test_messages_cancel(): + responses.add( + responses.POST, + 'https://api.courier.com/messages/id/cancel', + status=200, + content_type='application/json', + body='{}' + ) + c = Courier(auth_token='123456789ABCDF') + r = c.messages.cancel(message_id="id") - + assert r == {} diff --git a/trycourier/messages.py b/trycourier/messages.py index 7c8070f..4f0f562 100644 --- a/trycourier/messages.py +++ b/trycourier/messages.py @@ -112,3 +112,29 @@ def get_history(self, message_id, type=None): raise CourierAPIException(resp) return resp.json() + + def cancel(self, message_id): + """ + Cancel the message delivery. + + Args: + message_id (str): A unique identifier associated with the message + you wish to retrieve (returned after each 'send()' call. + See + https://www.courier.com/docs/reference/send/message/#requestid-details + for details.) + + Raises: + CourierAPIException: Any error returned by the Courier API + + Returns: + dict: Contains message item + """ + url = "%s/%s/cancel" % (self.uri, message_id) + + resp = self.session.post(url) + + if resp.status_code >= 400: + raise CourierAPIException(resp) + + return resp.json()