Skip to content

Commit

Permalink
Merge pull request #9 from industrydive/TECH-1615-workaround-sailthru…
Browse files Browse the repository at this point in the history
…-blast-api-limit

TECH-1615 - Workaround for Sailthru blast API not returning full results
  • Loading branch information
MiriamSexton authored May 4, 2017
2 parents 63d402f + b7ff944 commit 76eb356
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dive_sailthru_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,26 @@ def get_campaigns_in_range(self, start_date, end_date, list_name=None):
'status': 'sent',
'start_date': page_start_date.strftime("%Y-%m-%d"),
'end_date': page_end_date.strftime("%Y-%m-%d"),
'limit': 999999, # workaround for limited data returned, see TECH-1615.
}
if list_name is not None:
api_params['list'] = list_name

result = self.api_get('blast', api_params)

data = result.json
blasts = data.get('blasts', [])
filtered_count = data.get('filtered_count', 0)
# We discovered in TECH-1615 that Sailthru is (accidentally?) limiting number of results. So let's
# specifically raise an exception if the expected number of records doesn't match the actual returned.
if filtered_count != len(blasts):
raise SailthruApiError(
"Incomplete 'blast' API data. Expected %d records, got %d" % (filtered_count, len(blasts))
)

# We reverse the results to keep everything in ascending
# chronological order.
for c in reversed(data.get('blasts', [])):
for c in reversed(blasts):
c['dive_email_type'] = self._infer_dive_email_type(c)
# technically below gets the pub, but keeping key `dive_brand` for backwards compatability
c['dive_brand'] = self._infer_dive_publication(c)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="dive_sailthru_client",
version="0.0.8",
version="0.0.9",
description="Industry Dive abstraction of the Sailthru API client",
author='David Barbarisi',
author_email='dbarbarisi@industrydive.com',
Expand Down

0 comments on commit 76eb356

Please sign in to comment.