|
5 | 5 | Dotdigital helpers.
|
6 | 6 | """
|
7 | 7 |
|
8 |
| -import os |
| 8 | +import json |
| 9 | +import logging |
9 | 10 | import typing as t
|
10 | 11 | from dataclasses import dataclass
|
11 | 12 |
|
12 | 13 | import requests
|
| 14 | +from django.conf import settings |
13 | 15 |
|
14 | 16 | from .types import JsonDict
|
15 | 17 |
|
@@ -72,7 +74,7 @@ def add_contact(
|
72 | 74 | # pylint: enable=line-too-long
|
73 | 75 |
|
74 | 76 | if auth is None:
|
75 |
| - auth = os.environ["DOTDIGITAL_AUTH"] |
| 77 | + auth = settings.DOTDIGITAL_AUTH |
76 | 78 |
|
77 | 79 | contact: JsonDict = {"email": email.lower()}
|
78 | 80 | if opt_in_type is not None:
|
@@ -123,6 +125,12 @@ def add_contact(
|
123 | 125 | for preference in preferences
|
124 | 126 | ]
|
125 | 127 |
|
| 128 | + if not settings.DOTDIGITAL_ENABLED: |
| 129 | + logging.info( |
| 130 | + "Added contact to DotDigital:\n%s", json.dumps(body, indent=2) |
| 131 | + ) |
| 132 | + return |
| 133 | + |
126 | 134 | response = requests.post(
|
127 | 135 | # pylint: disable-next=line-too-long
|
128 | 136 | url=f"https://{region}-api.dotdigital.com/v2/contacts/with-consent-and-preferences",
|
@@ -166,8 +174,12 @@ def remove_contact(
|
166 | 174 | """
|
167 | 175 | # pylint: enable=line-too-long
|
168 | 176 |
|
| 177 | + if not settings.DOTDIGITAL_ENABLED: |
| 178 | + logging.info("Removed contact from DotDigital: %s", contact_identifier) |
| 179 | + return |
| 180 | + |
169 | 181 | if auth is None:
|
170 |
| - auth = os.environ["DOTDIGITAL_AUTH"] |
| 182 | + auth = settings.DOTDIGITAL_AUTH |
171 | 183 |
|
172 | 184 | response = requests.get(
|
173 | 185 | # pylint: disable-next=line-too-long
|
@@ -250,7 +262,7 @@ def send_mail(
|
250 | 262 | # pylint: enable=line-too-long
|
251 | 263 |
|
252 | 264 | if auth is None:
|
253 |
| - auth = os.environ["DOTDIGITAL_AUTH"] |
| 265 | + auth = settings.DOTDIGITAL_AUTH |
254 | 266 |
|
255 | 267 | body = {
|
256 | 268 | "campaignId": campaign_id,
|
@@ -282,6 +294,13 @@ def send_mail(
|
282 | 294 | for attachment in attachments
|
283 | 295 | ]
|
284 | 296 |
|
| 297 | + if not settings.DOTDIGITAL_ENABLED: |
| 298 | + logging.info( |
| 299 | + "Sent a triggered email with DotDigital:\n%s", |
| 300 | + json.dumps(body, indent=2), |
| 301 | + ) |
| 302 | + return |
| 303 | + |
285 | 304 | response = requests.post(
|
286 | 305 | url=f"https://{region}-api.dotdigital.com/v2/email/triggered-campaign",
|
287 | 306 | json=body,
|
|
0 commit comments