Skip to content

Commit 8c8cc51

Browse files
zachartmannkatharosada
authored andcommitted
Creating the wrapper for new Journey endpoints (#66)
* Added journey and journey email into library as well as appropriate unit tests * Fixing Travis and accepting higher versions of Python * Removed .idea files * Increased test coverage and handled parameters more efficiently * Improved efficiency and removed unused import * Re-added .idea to gitignore
1 parent 4bfe2fd commit 8c8cc51

22 files changed

+647
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ htmlcov
1010
.tox
1111
lib/createsend.egg-info
1212
.rake_tasks~
13+
.idea

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: python
22
python:
33
- 2.7
4-
- 3.3
54
- 3.4
65
- 3.5
76
- 3.6
7+
- 3.7
88
install:
99
- pip install coverage coveralls
1010
script:

README.md

Lines changed: 1 addition & 1 deletion
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.3, 3.4, or 3.5.
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.
44

55
## Installation
66

lib/createsend/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
ExpiredOAuthToken,
2828
CreateSendBase,
2929
CreateSend)
30+
from createsend.journey_email import JourneyEmail
31+
from createsend.journey import Journey
3032
from createsend.list import List
3133
from createsend.person import Person
3234
from createsend.segment import Segment

lib/createsend/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,10 @@ def delete(self):
167167
"""Deletes this client."""
168168
response = self._delete("/clients/%s.json" % self.client_id)
169169

170+
def journeys(self):
171+
"""Retrieves the journeys associated with the client"""
172+
response = self._get(self.uri_for('journeys'))
173+
return json_to_py(response)
174+
170175
def uri_for(self, action):
171176
return "/clients/%s/%s.json" % (self.client_id, action)

lib/createsend/journey.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from __future__ import absolute_import
2+
3+
from createsend.createsend import CreateSendBase
4+
from createsend.utils import json_to_py
5+
6+
7+
class Journey(CreateSendBase):
8+
"""Represents a journey and associated functionality"""
9+
10+
def __init__(self, auth=None, journey_id=None):
11+
self.journey_id = journey_id
12+
super(Journey, self).__init__(auth)
13+
14+
def summary(self):
15+
"""Gets the summary of the journey"""
16+
response = self._get("/journeys/%s.json" % self.journey_id)
17+
return json_to_py(response)

lib/createsend/journey_email.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from __future__ import absolute_import
2+
3+
from createsend.createsend import CreateSendBase
4+
from createsend.utils import json_to_py
5+
6+
7+
class JourneyEmail(CreateSendBase):
8+
"""Represents a journey and associated functionality"""
9+
10+
def __init__(self, auth=None, journey_email_id=None):
11+
self.journey_email_id = journey_email_id
12+
super(JourneyEmail, self).__init__(auth)
13+
14+
def bounces(self, date=None, page=None, page_size=None, order_direction=None):
15+
"""Retrieves the bounces for this journey email."""
16+
return self.get_journey_email_response(date, page, page_size, order_direction, "bounces")
17+
18+
def clicks(self, date=None, page=None, page_size=None, order_direction=None):
19+
"""Retrieves the clicks for this journey email."""
20+
return self.get_journey_email_response(date, page, page_size, order_direction, "clicks")
21+
22+
def opens(self, date=None, page=None, page_size=None, order_direction=None):
23+
"""Retrieves the opens for this journey email."""
24+
return self.get_journey_email_response(date, page, page_size, order_direction, "opens")
25+
26+
def recipients(self, date=None, page=None, page_size=None, order_direction=None):
27+
"""Retrieves the recipients for this journey email."""
28+
return self.get_journey_email_response(date, page, page_size, order_direction, "recipients")
29+
30+
def unsubscribes(self, date=None, page=None, page_size=None, order_direction=None):
31+
"""Retrieves the unsubscribes for this journey email."""
32+
return self.get_journey_email_response(date, page, page_size, order_direction, "unsubscribes")
33+
34+
def get_journey_email_response(self, date, page, page_size, order_direction, uri):
35+
"""Retrieves information for the journey email - based on theuri"""
36+
params = {}
37+
if date is not None:
38+
params["date"] = date
39+
if page is not None:
40+
params["page"] = page
41+
if page_size is not None:
42+
params["pagesize"] = page_size
43+
if order_direction is not None:
44+
params["orderdirection"] = order_direction
45+
response = self._get(self.uri_for(uri), params=params)
46+
return json_to_py(response)
47+
48+
def uri_for(self, action):
49+
return "/journeys/email/%s/%s.json" % (self.journey_email_id, action)
50+

test/fixtures/client_journeys.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"ListID": "a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1",
4+
"JourneyID": "b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2",
5+
"Name": "Journey 1",
6+
"Status": "Active"
7+
},
8+
{
9+
"ListID": "a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1",
10+
"JourneyID": "b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2",
11+
"Name": "New journey",
12+
"Status": "Active"
13+
}
14+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"Results": [
3+
{
4+
"EmailAddress": "[email protected]",
5+
"BounceType": "Soft",
6+
"Date": "2019-08-20 14:24:00",
7+
"Reason": "Soft Bounce - Dns Failure"
8+
},
9+
{
10+
"EmailAddress": "[email protected]",
11+
"BounceType": "Hard",
12+
"Date": "2019-08-21 04:26:00",
13+
"Reason": "Hard Bounce"
14+
}
15+
],
16+
"ResultsOrderedBy": "Date",
17+
"OrderDirection": "ASC",
18+
"PageNumber": 1,
19+
"PageSize": 1000,
20+
"RecordsOnThisPage": 2,
21+
"TotalNumberOfRecords": 2,
22+
"NumberOfPages": 1
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"Results": [
3+
{
4+
"EmailAddress": "[email protected]",
5+
"BounceType": "Hard",
6+
"Date": "2019-08-21 04:26:00",
7+
"Reason": "Hard Bounce"
8+
},
9+
{
10+
"EmailAddress": "[email protected]",
11+
"BounceType": "Soft",
12+
"Date": "2019-08-20 14:24:00",
13+
"Reason": "Soft Bounce - Dns Failure"
14+
}
15+
],
16+
"ResultsOrderedBy": "Date",
17+
"OrderDirection": "DESC",
18+
"PageNumber": 1,
19+
"PageSize": 10,
20+
"RecordsOnThisPage": 2,
21+
"TotalNumberOfRecords": 2,
22+
"NumberOfPages": 1
23+
}

0 commit comments

Comments
 (0)