Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor personalization.py as in issue #501 #493

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 16 additions & 22 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,6 +166,7 @@ def get(self):
:rtype: dict
"""
personalization = {}

if self.tos:
personalization["to"] = self.tos

Expand All @@ -175,27 +176,20 @@ def get(self):
if self.bccs:
personalization["bcc"] = self.bccs

if self.subject is not None:
if self.subject:
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 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

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

return personalization