Skip to content

Commit 409b951

Browse files
authored
Add schedule and send message APIs for ActionNetwork (#1292)
* Add schedule and send message APIs for ActionNetwork See https://actionnetwork.org/docs/v2/schedule_helper and https://actionnetwork.org/docs/v2/send_helper * Add tests for ActionNetwork schedule and send helpers
1 parent 7961328 commit 409b951

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

parsons/action_network/action_network.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,40 @@ def update_message(self, message_id, payload):
928928
"""
929929
return self.api.put_request(f"messages/{message_id}", payload)
930930

931+
def schedule_message(self, message_id, scheduled_start_date):
932+
"""
933+
Schedule a message in Action Network
934+
935+
`Args:`
936+
message_id:
937+
The unique id of the message
938+
scheduled_start_date:
939+
The UTC timestamp to schedule the message at in ISO8601 format.
940+
e.g. "2015-03-14T12:00:00Z"
941+
`Returns:`
942+
A JSON response confirming the scheduling
943+
`Documentation Reference`:
944+
https://actionnetwork.org/docs/v2/schedule_helper
945+
"""
946+
return self.api.post_request(
947+
f"messages/{message_id}/schedule/",
948+
{"scheduled_start_date": scheduled_start_date},
949+
)
950+
951+
def send_message(self, message_id):
952+
"""
953+
Send a message in Action Network
954+
955+
`Args:`
956+
message_id:
957+
The unique id of the message
958+
`Returns:`
959+
A JSON response confirming the message was sent
960+
`Documentation Reference`:
961+
https://actionnetwork.org/docs/v2/send_helper
962+
"""
963+
return self.api.post_request(f"messages/{message_id}/send/", {})
964+
931965
# Metadata
932966
def get_metadata(self):
933967
"""

test/test_action_network/test_action_network.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,31 @@ def test_update_message(self, m):
38533853
self.fake_message,
38543854
)
38553855

3856+
@requests_mock.Mocker()
3857+
def test_schedule_message(self, m):
3858+
message_id = "123"
3859+
scheduled_start_date = "2015-03-14T12:00:00Z"
3860+
m.post(
3861+
f"{self.api_url}/messages/123/schedule/",
3862+
text=json.dumps({"message": "Your message has been scheduled"}),
3863+
)
3864+
assert_matching_tables(
3865+
self.an.schedule_message(message_id, scheduled_start_date),
3866+
{"message": "Your message has been scheduled"},
3867+
)
3868+
3869+
@requests_mock.Mocker()
3870+
def test_send_message(self, m):
3871+
message_id = "123"
3872+
m.post(
3873+
f"{self.api_url}/messages/123/send/",
3874+
text=json.dumps({"message": "Your email has been sent."}),
3875+
)
3876+
assert_matching_tables(
3877+
self.an.send_message(message_id),
3878+
{"message": "Your email has been sent."},
3879+
)
3880+
38563881
# Metadata
38573882
@requests_mock.Mocker()
38583883
def test_get_metadata(self, m):

0 commit comments

Comments
 (0)