Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ api.create_template(
name='Email Name',
subject='Email Subject',
html='<html><head></head><body>Valid HTML</body></html>',
text='Optional text content'
text='Optional text content',
preheader='Optional preheader'
)
```

Expand All @@ -71,7 +72,8 @@ api.create_new_locale(
version_name='Version Name',
subject='Email Subject',
html='<html><head></head><body>Valid HTML</body></html>',
text='Optional text content'
text='Optional text content',
preheader='Optional preheader'
)
```

Expand All @@ -84,6 +86,7 @@ api.create_new_version(
subject='Email Subject',
html='<html><head></head><body>Valid HTML</body></html>',
text='Optional text content',
preheader='Optional preheader',
locale='fr-FR'
)
```
Expand All @@ -97,7 +100,8 @@ api.update_template_version(
name='Email Name'
subject='Email Subject',
html='<html><head></head><body>Valid HTML</body></html>',
text='Optional text content'
text='Optional text content',
preheader='Optional preheader'
)
```

Expand Down
32 changes: 18 additions & 14 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pytest
import sendwithus
import os


@pytest.fixture
def api_key():
return 'PYTHON_API_CLIENT_TEST_KEY'
return os.environ.get('SWU_API_KEY')


@pytest.fixture
Expand All @@ -19,12 +20,15 @@ def api(api_key, api_options):

@pytest.fixture
def email_id():
return 'test_fixture_1'
return os.environ.get('TEMPLATE_ID')

@pytest.fixture
def version_id():
return os.environ.get('VERSION_ID')

@pytest.fixture
def translation_template_id():
return 'test_translation_fixture_1'
return os.environ.get('TEMPLATE_ID')


@pytest.fixture
Expand All @@ -34,24 +38,24 @@ def email_address():

@pytest.fixture
def enabled_drip_campaign_id():
return 'dc_Rmd7y5oUJ3tn86sPJ8ESCk'
return os.environ.get('DRIP_CAMPAIGN_ID')


@pytest.fixture
def disabled_drip_campaign_id():
return 'dc_AjR6Ue9PHPFYmEu2gd8x5V'
return os.environ.get('DRIP_CAMPAIGN_DISABLED_ID')


@pytest.fixture
def drip_campaign_step_id():
return 'dcs_yaAMiZNWCLAEGw7GLjBuGY'
return os.environ.get('DRIP_CAMPAIGN_STEP_ID')


@pytest.fixture
def recipient():
return {
'name': 'Matt',
'address': 'us@sendwithus.com'
'name': 'Test User',
'address': 'person@example.com'
}


Expand All @@ -67,17 +71,17 @@ def email_data():
def sender():
return {
'name': 'Company',
'address': 'company@company.com',
'reply_to': 'info@company.com'
'address': 'company@example.com',
'reply_to': 'info@example.com'
}


@pytest.fixture
def cc_test():
return [
{
'name': 'Matt CC',
'address': 'test+cc@sendwithus.com'
'name': 'Test CC',
'address': 'test+cc@example.com'
}
]

Expand All @@ -86,8 +90,8 @@ def cc_test():
def bcc_test():
return [
{
'name': 'Matt BCC',
'address': 'test+bcc@sendwithus.com'
'name': 'Test BCC',
'address': 'test+bcc@example.com'
}
]

Expand Down
31 changes: 29 additions & 2 deletions sendwithus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _api_request(self, endpoint, http_method, *args, **kwargs):
logger.debug('\tresponse code:%s' % r.status_code)
try:
logger.debug('\tresponse: %s' % r.json())
except:
except Exception:
logger.debug('\tresponse: %s' % r.content)

return self._parse_response(r)
Expand Down Expand Up @@ -259,6 +259,8 @@ def create_template(
subject,
html,
text='',
preheader=None,
amp_html=None,
timeout=None
):
""" API call to create a template """
Expand All @@ -269,6 +271,11 @@ def create_template(
'text': text
}

if preheader is not None:
payload['preheader'] = preheader
if amp_html is not None:
payload['amp_html'] = amp_html

return self._api_request(
self.TEMPLATES_ENDPOINT,
self.HTTP_POST,
Expand All @@ -284,6 +291,8 @@ def create_new_locale(
subject,
text='',
html='',
preheader=None,
amp_html=None,
timeout=None
):
""" API call to create a new locale and version of a template """
Expand All @@ -297,6 +306,10 @@ def create_new_locale(
payload['html'] = html
if text:
payload['text'] = text
if preheader is not None:
payload['preheader'] = preheader
if amp_html is not None:
payload['amp_html'] = amp_html

return self._api_request(
self.TEMPLATES_LOCALES_ENDPOINT % template_id,
Expand All @@ -313,6 +326,8 @@ def create_new_version(
template_id=None,
html=None,
locale=None,
preheader=None,
amp_html=None,
timeout=None
):
""" API call to create a new version of a template """
Expand All @@ -330,6 +345,11 @@ def create_new_version(
'text': text
}

if preheader is not None:
payload['preheader'] = preheader
if amp_html is not None:
payload['amp_html'] = amp_html

if locale:
url = self.TEMPLATES_SPECIFIC_LOCALE_VERSIONS_ENDPOINT % (
template_id,
Expand All @@ -353,6 +373,8 @@ def update_template_version(
version_id,
text='',
html=None,
preheader=None,
amp_html=None,
timeout=None
):
""" API call to update a template version """
Expand All @@ -370,6 +392,11 @@ def update_template_version(
'text': text
}

if preheader is not None:
payload['preheader'] = preheader
if amp_html is not None:
payload['amp_html'] = amp_html

return self._api_request(
self.TEMPLATES_VERSION_ENDPOINT % (template_id, version_id),
self.HTTP_PUT,
Expand Down Expand Up @@ -803,7 +830,7 @@ def execute(self, timeout=None):
logger.debug('\tresponse code:%s' % r.status_code)
try:
logger.debug('\tresponse: %s' % r.json())
except:
except Exception:
logger.debug('\tresponse: %s' % r.content)

return r
Expand Down
2 changes: 1 addition & 1 deletion sendwithus/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '5.2.1'
version = '5.3.0'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='sendwithus',
version='5.2.2',
version='5.3.0',
author='sendwithus',
author_email='us@sendwithus.com',
packages=find_packages(),
Expand Down
Loading