Skip to content

Commit

Permalink
Merge 48b996c into 4bfe2fd
Browse files Browse the repository at this point in the history
  • Loading branch information
zachartmann authored Aug 29, 2019
2 parents 4bfe2fd + 48b996c commit 2407419
Show file tree
Hide file tree
Showing 22 changed files with 647 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cover
htmlcov
.tox
lib/createsend.egg-info
.rake_tasks~
.rake_tasks~
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: python
python:
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
- 3.7
install:
- pip install coverage coveralls
script:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# createsend

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.
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.

## Installation

Expand Down
2 changes: 2 additions & 0 deletions lib/createsend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
ExpiredOAuthToken,
CreateSendBase,
CreateSend)
from createsend.journey_email import JourneyEmail
from createsend.journey import Journey
from createsend.list import List
from createsend.person import Person
from createsend.segment import Segment
Expand Down
5 changes: 5 additions & 0 deletions lib/createsend/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,10 @@ def delete(self):
"""Deletes this client."""
response = self._delete("/clients/%s.json" % self.client_id)

def journeys(self):
"""Retrieves the journeys associated with the client"""
response = self._get(self.uri_for('journeys'))
return json_to_py(response)

def uri_for(self, action):
return "/clients/%s/%s.json" % (self.client_id, action)
17 changes: 17 additions & 0 deletions lib/createsend/journey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import absolute_import

from createsend.createsend import CreateSendBase
from createsend.utils import json_to_py


class Journey(CreateSendBase):
"""Represents a journey and associated functionality"""

def __init__(self, auth=None, journey_id=None):
self.journey_id = journey_id
super(Journey, self).__init__(auth)

def summary(self):
"""Gets the summary of the journey"""
response = self._get("/journeys/%s.json" % self.journey_id)
return json_to_py(response)
50 changes: 50 additions & 0 deletions lib/createsend/journey_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import absolute_import

from createsend.createsend import CreateSendBase
from createsend.utils import json_to_py


class JourneyEmail(CreateSendBase):
"""Represents a journey and associated functionality"""

def __init__(self, auth=None, journey_email_id=None):
self.journey_email_id = journey_email_id
super(JourneyEmail, self).__init__(auth)

def bounces(self, date=None, page=None, page_size=None, order_direction=None):
"""Retrieves the bounces for this journey email."""
return self.get_journey_email_response(date, page, page_size, order_direction, "bounces")

def clicks(self, date=None, page=None, page_size=None, order_direction=None):
"""Retrieves the clicks for this journey email."""
return self.get_journey_email_response(date, page, page_size, order_direction, "clicks")

def opens(self, date=None, page=None, page_size=None, order_direction=None):
"""Retrieves the opens for this journey email."""
return self.get_journey_email_response(date, page, page_size, order_direction, "opens")

def recipients(self, date=None, page=None, page_size=None, order_direction=None):
"""Retrieves the recipients for this journey email."""
return self.get_journey_email_response(date, page, page_size, order_direction, "recipients")

def unsubscribes(self, date=None, page=None, page_size=None, order_direction=None):
"""Retrieves the unsubscribes for this journey email."""
return self.get_journey_email_response(date, page, page_size, order_direction, "unsubscribes")

def get_journey_email_response(self, date, page, page_size, order_direction, uri):
"""Retrieves information for the journey email - based on theuri"""
params = {}
if date is not None:
params["date"] = date
if page is not None:
params["page"] = page
if page_size is not None:
params["pagesize"] = page_size
if order_direction is not None:
params["orderdirection"] = order_direction
response = self._get(self.uri_for(uri), params=params)
return json_to_py(response)

def uri_for(self, action):
return "/journeys/email/%s/%s.json" % (self.journey_email_id, action)

14 changes: 14 additions & 0 deletions test/fixtures/client_journeys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"ListID": "a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1",
"JourneyID": "b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2",
"Name": "Journey 1",
"Status": "Active"
},
{
"ListID": "a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1",
"JourneyID": "b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2",
"Name": "New journey",
"Status": "Active"
}
]
23 changes: 23 additions & 0 deletions test/fixtures/journey_email_bounces_no_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Results": [
{
"EmailAddress": "asdf@softbouncemyemail.comX",
"BounceType": "Soft",
"Date": "2019-08-20 14:24:00",
"Reason": "Soft Bounce - Dns Failure"
},
{
"EmailAddress": "asdf@hardbouncemyemail.com",
"BounceType": "Hard",
"Date": "2019-08-21 04:26:00",
"Reason": "Hard Bounce"
}
],
"ResultsOrderedBy": "Date",
"OrderDirection": "ASC",
"PageNumber": 1,
"PageSize": 1000,
"RecordsOnThisPage": 2,
"TotalNumberOfRecords": 2,
"NumberOfPages": 1
}
23 changes: 23 additions & 0 deletions test/fixtures/journey_email_bounces_with_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Results": [
{
"EmailAddress": "asdf@hardbouncemyemail.com",
"BounceType": "Hard",
"Date": "2019-08-21 04:26:00",
"Reason": "Hard Bounce"
},
{
"EmailAddress": "asdf@softbouncemyemail.comX",
"BounceType": "Soft",
"Date": "2019-08-20 14:24:00",
"Reason": "Soft Bounce - Dns Failure"
}
],
"ResultsOrderedBy": "Date",
"OrderDirection": "DESC",
"PageNumber": 1,
"PageSize": 10,
"RecordsOnThisPage": 2,
"TotalNumberOfRecords": 2,
"NumberOfPages": 1
}
35 changes: 35 additions & 0 deletions test/fixtures/journey_email_clicks_no_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"Results": [
{
"EmailAddress": "asdf@example.com",
"Date": "2019-08-19 10:23:00",
"URL": "http://mail.google.com/mail/?hl=en&tab=wm",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
},
{
"EmailAddress": "asdf+2@example.com",
"Date": "2019-08-19 10:24:00",
"URL": "https://example.com",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
}
],
"ResultsOrderedBy": "Date",
"OrderDirection": "ASC",
"PageNumber": 1,
"PageSize": 1000,
"RecordsOnThisPage": 2,
"TotalNumberOfRecords": 2,
"NumberOfPages": 1
}
35 changes: 35 additions & 0 deletions test/fixtures/journey_email_clicks_with_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"Results": [
{
"EmailAddress": "asdf+2@example.com",
"Date": "2019-08-19 10:24:00",
"URL": "https://example.com",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
},
{
"EmailAddress": "asdf@example.com",
"Date": "2019-08-19 10:23:00",
"URL": "http://mail.google.com/mail/?hl=en&tab=wm",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
}
],
"ResultsOrderedBy": "Date",
"OrderDirection": "DESC",
"PageNumber": 1,
"PageSize": 10,
"RecordsOnThisPage": 2,
"TotalNumberOfRecords": 2,
"NumberOfPages": 1
}
33 changes: 33 additions & 0 deletions test/fixtures/journey_email_opens_no_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"Results": [
{
"EmailAddress": "asdf@example.com",
"Date": "2019-08-19 10:23:00",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
},
{
"EmailAddress": "asdf+2@example.com",
"Date": "2019-08-19 10:24:00",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
}
],
"ResultsOrderedBy": "Date",
"OrderDirection": "ASC",
"PageNumber": 1,
"PageSize": 1000,
"RecordsOnThisPage": 2,
"TotalNumberOfRecords": 2,
"NumberOfPages": 1
}
33 changes: 33 additions & 0 deletions test/fixtures/journey_email_opens_with_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"Results": [
{
"EmailAddress": "asdf+2@example.com",
"Date": "2019-08-19 10:24:00",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
},
{
"EmailAddress": "asdf@example.com",
"Date": "2019-08-19 10:23:00",
"IPAddress": "198.148.196.144",
"Latitude": -33.8591,
"Longitude": 151.200195,
"City": "Sydney",
"Region": "New South Wales",
"CountryCode": "AU",
"CountryName": "Australia"
}
],
"ResultsOrderedBy": "Date",
"OrderDirection": "DESC",
"PageNumber": 1,
"PageSize": 10,
"RecordsOnThisPage": 2,
"TotalNumberOfRecords": 2,
"NumberOfPages": 1
}
27 changes: 27 additions & 0 deletions test/fixtures/journey_email_recipients_no_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"Results": [
{
"EmailAddress": "asdf@example.com",
"SentDate": "2019-08-19 10:23:00"
},
{
"EmailAddress": "asdf+2@example.com",
"SentDate": "2019-08-19 10:23:00"
},
{
"EmailAddress": "asdf@softbouncemyemail.comX",
"SentDate": "2019-08-20 14:24:00"
},
{
"EmailAddress": "asdf@hardbouncemyemail.com",
"SentDate": "2019-08-21 04:26:00"
}
],
"ResultsOrderedBy": "SentDate",
"OrderDirection": "ASC",
"PageNumber": 1,
"PageSize": 1000,
"RecordsOnThisPage": 4,
"TotalNumberOfRecords": 4,
"NumberOfPages": 1
}
27 changes: 27 additions & 0 deletions test/fixtures/journey_email_recipients_with_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"Results": [
{
"EmailAddress": "asdf@hardbouncemyemail.com",
"SentDate": "2019-08-21 04:26:00"
},
{
"EmailAddress": "asdf@softbouncemyemail.comX",
"SentDate": "2019-08-20 14:24:00"
},
{
"EmailAddress": "asdf+2@example.com",
"SentDate": "2019-08-19 10:23:00"
},
{
"EmailAddress": "asdf@example.com",
"SentDate": "2019-08-19 10:23:00"
}
],
"ResultsOrderedBy": "SentDate",
"OrderDirection": "DESC",
"PageNumber": 1,
"PageSize": 10,
"RecordsOnThisPage": 4,
"TotalNumberOfRecords": 4,
"NumberOfPages": 1
}
16 changes: 16 additions & 0 deletions test/fixtures/journey_email_unsubscribes_no_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Results": [
{
"EmailAddress": "asdf@example.com",
"Date": "2019-08-19 10:24:00",
"IPAddress": "198.148.196.144"
}
],
"ResultsOrderedBy": "Date",
"OrderDirection": "ASC",
"PageNumber": 1,
"PageSize": 1000,
"RecordsOnThisPage": 1,
"TotalNumberOfRecords": 1,
"NumberOfPages": 1
}
Loading

0 comments on commit 2407419

Please sign in to comment.