Skip to content

Commit

Permalink
Integrate PR #493
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingserious committed Jul 12, 2018
1 parent 3b705ed commit 7ed4338
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions sendgrid/helpers/mail/personalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Personalization(object):
"""

def __init__(self):
"""Create an empty Personalization."""
"""Create an empty Personalization and initialize member variables."""
self._tos = []
self._ccs = []
self._bccs = []
Expand Down Expand Up @@ -166,36 +166,23 @@ def get(self):
:rtype: dict
"""
personalization = {}
if self.tos:
personalization["to"] = self.tos

if self.ccs:
personalization["cc"] = self.ccs

if self.bccs:
personalization["bcc"] = self.bccs

if self.subject is not None:
personalization["subject"] = self.subject

if self.headers:
headers = {}
for key in self.headers:
headers.update(key)
personalization["headers"] = headers

if self.substitutions:
substitutions = {}
for key in self.substitutions:
substitutions.update(key)
personalization["substitutions"] = substitutions

if self.custom_args:
custom_args = {}
for key in self.custom_args:
custom_args.update(key)
personalization["custom_args"] = custom_args

if self.send_at is not None:
personalization["send_at"] = self.send_at

for key in ['tos', 'ccs', 'bccs']:
value = getattr(self, key)
if value:
personalization[key[:-1]] = value

for key in ['subject', 'send_at']:
value = getattr(self, key)
if value:
personalization[key] = value

for prop_name in ['headers', 'substitutions', 'custom_args']:
prop = getattr(self, prop_name)
if prop:
obj = {}
for key in prop:
obj.update(key)
personalization[prop_name] = obj

return personalization

0 comments on commit 7ed4338

Please sign in to comment.