Skip to content

Commit

Permalink
[C-9804] - add support for cancel message api (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgradwohl authored Jun 26, 2023
1 parent b40a48e commit e44868d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
19 changes: 16 additions & 3 deletions tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from trycourier.client import Courier
from trycourier.exceptions import CourierAPIException


@responses.activate
def test_success_messages_list():
responses.add(
Expand Down Expand Up @@ -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():
Expand All @@ -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
Expand All @@ -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 == {}
26 changes: 26 additions & 0 deletions trycourier/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit e44868d

Please sign in to comment.