Skip to content

Commit 03df0e5

Browse files
committed
* Version 6.1.1
* Add `excludemessagebody` parameter for Transactional message details endpoint and update tests. * Update README with sample code for using message details and timeline endpoint. * Add Python 3.8 to `tox.ini`.
1 parent ff6500c commit 03df0e5

7 files changed

Lines changed: 64 additions & 8 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ python:
55
- 3.5
66
- 3.6
77
- 3.7
8+
- 3.8
89
install:
910
- pip install coverage coveralls
1011
script:

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# createsend-python history
22

3+
## v6.1.1 - 10 Feb, 2021
4+
* Add `excludemessagebody` parameter for Transactional message details endpoint
5+
and update tests.
6+
* Update README with sample code for using message details and timeline endpoint.
7+
* Add Python 3.8 to `tox.ini`.
8+
39
## v6.1.0 - 29 August, 2019
410
* Added support for Journeys endpoints
511
* This includes client/journeys, journeys/summary and the journeys/email/... endpoints

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,52 @@ Client: Second Client
120120
- News for January 2013
121121
```
122122

123+
## Transactional
124+
125+
Sample code that uses Transactional message detail and timeline endpoint API.
126+
```python
127+
from createsend import Transactional
128+
import os
129+
import sys
130+
131+
auth = {'api_key': os.getenv('CREATESEND_API_KEY', '')}
132+
msg_id = os.getenv('MESSAGE_ID', '')
133+
134+
if len(auth) == 0:
135+
print("API Key Not Provided")
136+
sys.exit(1)
137+
138+
if len(msg_id) == 0:
139+
print("Message ID Not Provided")
140+
sys.exit(1)
141+
142+
#auth = {'api_key': '[api_key]'}
143+
#msg_id = "[message id]" # e.g., becd8473-6a19-1feb-84c5-28d16948a5fc
144+
145+
tx = Transactional(auth)
146+
147+
# Get message details using message id
148+
msg_details = tx.message_details(msg_id, statistics=True, exclude_message_body=False)
149+
print(f'smart email id: {msg_details.SmartEmailID}')
150+
print(f'bounce type: {msg_details.BounceType}')
151+
print(f'bounce category: {msg_details.BounceCategory}')
152+
print(f'html: {msg_details.Message.Body.Html}')
153+
print('--')
154+
155+
# Count the number of bounced mail using message timeline
156+
msg_timeline = tx.message_timeline()
157+
num_bounced = 0
158+
for m in msg_timeline:
159+
print('--')
160+
print(f'message id: {m.MessageID}')
161+
if str.lower(m.Status) == 'bounced':
162+
num_bounced += 1
163+
print(f'bounce type: {m.BounceType}')
164+
print(f'bounce category: {m.BounceCategory}')
165+
print('--')
166+
print(f"total bounces: {num_bounced}")
167+
```
168+
123169
## Handling errors
124170
If the Campaign Monitor API returns an error, an exception will be raised. For example, if you attempt to create a campaign and enter empty values for subject and other required fields:
125171

lib/createsend/transactional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ def message_timeline(self, params={}):
9090
response = self._get("/transactional/messages", params)
9191
return json_to_py(response)
9292

93-
def message_details(self, message_id, statistics=False):
93+
def message_details(self, message_id, statistics=False, exclude_message_body=False):
9494
"""Gets the details of this message."""
9595
response = self._get(
96-
"/transactional/messages/%s?statistics=%s" % (message_id, statistics))
96+
"/transactional/messages/%s?statistics=%s&excludemessagebody=%s" % (message_id, statistics, exclude_message_body))
9797
return json_to_py(response)
9898

9999
def message_resend(self, message_id):

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="createsend",
5-
version='6.1.0',
5+
version='6.1.1',
66
description="A library which implements the complete functionality of the Campaign Monitor API.",
77
author='Campaign Monitor',
88
author_email='support@campaignmonitor.com',
@@ -45,5 +45,8 @@
4545
"Programming Language :: Python :: 3.3",
4646
"Programming Language :: Python :: 3.4",
4747
"Programming Language :: Python :: 3.5",
48+
"Programming Language :: Python :: 3.6",
49+
"Programming Language :: Python :: 3.7",
50+
"Programming Language :: Python :: 3.8",
4851
]
4952
)

test/test_transactional.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ def test_timeline_smart_with_options(self):
100100
self.assertEqual(timeline[0].SmartEmailID, self.smart_email_id)
101101

102102
def test_message_details(self):
103-
self.tx.stub_request('transactional/messages/%s?statistics=False' %
103+
self.tx.stub_request('transactional/messages/%s?statistics=False&excludemessagebody=False' %
104104
(self.message_id), "tx_message_details.json")
105-
msg = self.tx.message_details(self.message_id, statistics=False)
105+
msg = self.tx.message_details(self.message_id, statistics=False, exclude_message_body=False)
106106
self.assertEqual(msg.MessageID, self.message_id)
107107

108108
def test_message_details_with_stats(self):
109-
self.tx.stub_request('transactional/messages/%s?statistics=True' %
109+
self.tx.stub_request('transactional/messages/%s?statistics=True&excludemessagebody=False' %
110110
(self.message_id), "tx_message_details_with_statistics.json")
111-
msg = self.tx.message_details(self.message_id, statistics=True)
111+
msg = self.tx.message_details(self.message_id, statistics=True, exclude_message_body=False)
112112
self.assertEqual(len(msg.Opens), 1)
113113
self.assertEqual(len(msg.Clicks), 1)
114114

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[tox]
77
# pip is broken on py32
8-
envlist = py27, py30, py31, py33, py34, py35, py36, py37
8+
envlist = py27, py30, py31, py33, py34, py35, py36, py37, py38
99

1010
[testenv]
1111
install_command=pip install {packages}

0 commit comments

Comments
 (0)