Skip to content

Commit 6a0bbd0

Browse files
authored
Merge pull request #75 from campaignmonitor/EL-281
EL-281 -- Update the phyton wrapper
2 parents 7399f44 + 16ae7e2 commit 6a0bbd0

18 files changed

Lines changed: 195 additions & 41 deletions

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ python:
66
- 3.6
77
- 3.7
88
- 3.8
9+
- 3.9
10+
- 3.10
911
install:
1012
- pip install coverage coveralls
1113
script:

HISTORY.md

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

3+
## v7.0.0 - 19 Nov, 2021
4+
* Upgrades to Createsend API v3.3 which includes new breaking changes
5+
* Breaking: 'client.campaigns' now returned an object to support pagination (use .Results to get the array of campaigns)
6+
* Added 'Tags' as another field that is returned in 'client.scheduled', 'client.drafts' and client.campaigns'
7+
* Added 'Name' as another field that is returned in 'campaign.summary'
8+
* Add new support for 'client.tags' endpoint (ie: getting list of tags for the client)
9+
* Add support for pagination, filtering and sorting to 'client.campaigns' endpoint
10+
* Add Python 3.10 to `tox.ini`
11+
312
## v6.1.2 - 10 Feb, 2021
413
* Add `excludemessagebody` parameter for Transactional message details endpoint
514
and update tests.

README.md

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

3-
A Python library which implements the complete functionality of the [Campaign Monitor API](http://www.campaignmonitor.com/api/). Requires Python 2.7, 3.4, 3.5, 3.6 or 3.7.
3+
A Python library which implements the complete functionality of the [Campaign Monitor API](http://www.campaignmonitor.com/api/). Requires Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9 or 3.10.
44

55
## Installation
66

@@ -89,7 +89,7 @@ clients = cs.clients()
8989
```
9090

9191
## Basic usage
92-
This example of listing all your clients and their campaigns demonstrates basic usage of the library and the data returned from the API:
92+
This example of listing all your clients and their draft campaigns demonstrates basic usage of the library and the data returned from the API:
9393

9494
```python
9595
from createsend import *
@@ -104,7 +104,7 @@ for cl in clients:
104104
print("Client: %s" % cl.Name)
105105
client = Client(auth, cl.ClientID)
106106
print("- Campaigns:")
107-
for cm in client.campaigns():
107+
for cm in client.drafts():
108108
print(" - %s" % cm.Subject)
109109
```
110110

lib/createsend/client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ def details(self):
2929
response = self._get("/clients/%s.json" % self.client_id)
3030
return json_to_py(response)
3131

32-
def campaigns(self):
32+
def campaigns(self, sent_from_date="", sent_to_date="", tags="", page=1, page_size=1000, order_direction="desc"):
3333
"""Gets the sent campaigns belonging to this client."""
34-
response = self._get(self.uri_for("campaigns"))
34+
params = {
35+
"sentfromdate": sent_from_date,
36+
"senttodate": sent_to_date,
37+
"page": page,
38+
"tags": tags,
39+
"pagesize": page_size,
40+
"orderdirection": order_direction,
41+
}
42+
response = self._get(self.uri_for("campaigns"), params=params)
3543
return json_to_py(response)
3644

3745
def scheduled(self):
@@ -44,6 +52,11 @@ def drafts(self):
4452
response = self._get(self.uri_for("drafts"))
4553
return json_to_py(response)
4654

55+
def tags(self):
56+
"""Gets the list of tags belonging to this client."""
57+
response = self._get(self.uri_for("tags"))
58+
return json_to_py(response)
59+
4760
def lists(self):
4861
"""Gets the subscriber lists belonging to this client."""
4962
response = self._get(self.uri_for("lists"))

lib/createsend/createsend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _delete(self, path, params={}):
252252

253253
class CreateSend(CreateSendBase):
254254
"""Provides high level CreateSend functionality/data you'll probably need."""
255-
base_uri = "https://api.createsend.com/api/v3.2"
255+
base_uri = "https://api.createsend.com/api/v3.3"
256256
oauth_uri = "https://api.createsend.com/oauth"
257257
oauth_token_uri = "%s/token" % oauth_uri
258258
platform = os.getenv('SERVER_SOFTWARE') or platform.platform()

lib/createsend/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,6 @@ def createsend_url(self, url):
171171
if url.startswith("http"):
172172
return url
173173
else:
174-
return "https://api.createsend.com/api/v3.2/%s" % url
174+
return "https://api.createsend.com/api/v3.3/%s" % url
175175

176176
return Faker(expected_url, filename, status, body)

samples/campaigns.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from createsend import *
2+
3+
auth = {
4+
'access_token': 'YOUR_ACCESS_TOKEN',
5+
'refresh_token': 'YOUR_REFRESH_TOKEN' }
6+
campaignId = 'YOUR_CAMPAIGN_ID'
7+
8+
campaign = Campaign(auth, campaignId)
9+
10+
# Get the summary info for a campaign
11+
summary = campaign.summary()
12+
for property, value in vars(summary).items():
13+
print(property, ":", value)

samples/clients.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from createsend import *
2+
3+
auth = {
4+
'access_token': 'YOUR_ACCESS_TOKEN',
5+
'refresh_token': 'YOUR_REFRESH_TOKEN' }
6+
clientId = 'YOUR_CLIENT_ID'
7+
8+
9+
cs = CreateSend(auth)
10+
client = Client(auth, clientId)
11+
12+
# Get list of sent campaigns
13+
print("List of sent campaigns:")
14+
pageNumber = 1
15+
pagedCampaigns = client.campaigns(page = 1)
16+
numberOfPages = pagedCampaigns.NumberOfPages
17+
while pageNumber <= numberOfPages:
18+
if (pageNumber > 1):
19+
pagedCampaigns = client.campaigns(page = pageNumber)
20+
21+
print(" Page: %d" % pageNumber)
22+
for cm in pagedCampaigns.Results:
23+
print(" - %s" % cm.Subject)
24+
25+
pageNumber = pageNumber + 1
26+
27+
28+
# Get list of sent campaigns filtered by tags and date
29+
print("List of sent campaigns at 2021 with ABTest tag:")
30+
pageNumber = 1
31+
pagedCampaigns = client.campaigns(page = 1, sent_from_date="2021-01-01", sent_to_date="2022-01-01", tags="ABTest")
32+
numberOfPages = pagedCampaigns.NumberOfPages
33+
while pageNumber <= numberOfPages:
34+
if (pageNumber > 1):
35+
pagedCampaigns = client.campaigns(page = pageNumber, sent_from_date="2021-01-01", sent_to_date="2022-01-01", tags="ABTest")
36+
37+
print(" Page: %d" % pageNumber)
38+
for cm in pagedCampaigns.Results:
39+
print(" - %s" % cm.Subject)
40+
41+
pageNumber = pageNumber + 1
42+
43+
# Get list of drafts campaigns
44+
print("List of drafts campaigns:")
45+
for cm in client.drafts():
46+
print(" - %s" % cm.Subject)
47+
48+
# Get list of scheduled campaigns
49+
print("List of scheduled campaigns:")
50+
for cm in client.scheduled():
51+
print(" - %s" % cm.Subject)
52+
53+
# Get list of tags
54+
print("List of tags:")
55+
for tag in client.tags():
56+
print(" Tag: %s - NumberOfCampaigns: %d" % (tag.Name, tag.NumberOfCampaigns))

samples/general.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from createsend import *
2+
3+
auth = {
4+
'access_token': 'YOUR_ACCESS_TOKEN',
5+
'refresh_token': 'YOUR_REFRESH_TOKEN' }
6+
7+
cs = CreateSend(auth)
8+
clients = cs.clients()
9+
10+
# Get list of clients
11+
for cl in clients:
12+
print("Client: %s - Id: %s" % (cl.Name, cl.ClientID))

setup.py

Lines changed: 3 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.2',
5+
version='7.0.0',
66
description="A library which implements the complete functionality of the Campaign Monitor API.",
77
author='Campaign Monitor',
88
author_email='[email protected]',
@@ -48,5 +48,7 @@
4848
"Programming Language :: Python :: 3.6",
4949
"Programming Language :: Python :: 3.7",
5050
"Programming Language :: Python :: 3.8",
51+
"Programming Language :: Python :: 3.9",
52+
"Programming Language :: Python :: 3.10",
5153
]
5254
)

0 commit comments

Comments
 (0)