From 5d4863d4b64652c1b05b502601f1adde675f1dd0 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Mon, 11 Jul 2016 14:11:57 -0700 Subject: [PATCH] Fix for issue 189 --- sendgrid/helpers/mail/mail.py | 218 +++++++++++++++++----------------- 1 file changed, 110 insertions(+), 108 deletions(-) diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index 720d57018..48d25f161 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -40,48 +40,48 @@ def get(self): :return: response body dict """ mail = {} - if self.from_email: + if self.from_email != None: mail["from"] = self.from_email.get() - if self.subject: + if self.subject != None: mail["subject"] = self.subject - if self.personalizations: + if self.personalizations != None: mail["personalizations"] = [personalization.get() for personalization in self.personalizations] - if self.contents: + if self.contents != None: mail["content"] = [ob.get() for ob in self.contents] - if self.attachments: + if self.attachments != None: mail["attachments"] = [ob.get() for ob in self.attachments] - if self.template_id: + if self.template_id != None: mail["template_id"] = self.template_id - if self.sections: + if self.sections != None: sections = {} for key in self.sections: sections.update(key.get()) mail["sections"] = sections - if self.headers: + if self.headers != None: headers = {} for key in self.headers: headers.update(key.get()) mail["headers"] = headers - if self.categories: + if self.categories != None: mail["categories"] = [category.get() for category in self.categories] - if self.custom_args: + if self.custom_args != None: custom_args = {} for key in self.custom_args: custom_args.update(key.get()) mail["custom_args"] = custom_args - if self.send_at: + if self.send_at != None: mail["send_at"] = self.send_at - if self.batch_id: + if self.batch_id != None: mail["batch_id"] = self.batch_id - if self.asm: + if self.asm != None: mail["asm"] = self.asm - if self.ip_pool_name: + if self.ip_pool_name != None: mail["ip_pool_name"] = self.ip_pool_name - if self.mail_settings: + if self.mail_settings != None: mail["mail_settings"] = self.mail_settings.get() - if self.tracking_settings: + if self.tracking_settings != None: mail["tracking_settings"] = self.tracking_settings.get() - if self.reply_to: + if self.reply_to != None: mail["reply_to"] = self.reply_to.get() return mail @@ -157,8 +157,8 @@ def set_reply_to(self, reply_to): class Email(object): def __init__(self, email=None, name=None): - self.name = name if name else None - self.email = email if email else None + self.name = name if name != None else None + self.email = email if email != None else None def set_name(self, name): self.name = name @@ -168,17 +168,17 @@ def set_email(self, email): def get(self): email = {} - if self.name: + if self.name != None: email["name"] = self.name - if self.email: + if self.email != None: email["email"] = self.email return email class Content(object): def __init__(self, type=None, value=None): - self.type = type if type else None - self.value = value if value else None + self.type = type if type != None else None + self.value = value if value != None else None def set_type(self, type): self.type = type @@ -188,17 +188,17 @@ def set_value(self, value): def get(self): content = {} - if self.type: + if self.type != None: content["type"] = self.type - if self.value: + if self.value != None: content["value"] = self.value return content class Header(object): def __init__(self, key=None, value=None): - self.key = key if key else None - self.value = value if value else None + self.key = key if key != None else None + self.value = value if value != None else None def set_key(self, key): self.key = key @@ -208,15 +208,15 @@ def set_value(self, value): def get(self): header = {} - if self.key and self.value: + if self.key != None and self.value != None: header[self.key] = self.value return header class Substitution(object): def __init__(self, key=None, value=None): - self.key = key if key else None - self.value = value if value else None + self.key = key if key != None else None + self.value = value if value != None else None def set_key(self, key): self.key = key @@ -226,15 +226,15 @@ def set_value(self, value): def get(self): substitution = {} - if self.key and self.value: + if self.key != None and self.value != None: substitution[self.key] = self.value return substitution class Section(object): def __init__(self, key=None, value=None): - self.key = key if key else None - self.value = value if value else None + self.key = key if key != None else None + self.value = value if value != None else None def set_key(self, key): self.key = key @@ -244,15 +244,15 @@ def set_value(self, value): def get(self): section = {} - if self.key and self.value: + if self.key != None and self.value != None: section[self.key] = self.value return section class CustomArg(object): def __init__(self, key=None, value=None): - self.key = key if key else None - self.value = value if value else None + self.key = key if key != None else None + self.value = value if value != None else None def set_key(self, key): self.key = key @@ -262,7 +262,7 @@ def set_value(self, value): def get(self): custom_arg = {} - if self.key and self.value: + if self.key != None and self.value != None: custom_arg[self.key] = self.value return custom_arg @@ -316,30 +316,30 @@ def set_send_at(self, send_at): def get(self): personalization = {} - if self.tos: + if self.tos != None: personalization["to"] = self.tos - if self.ccs: + if self.ccs != None: personalization["cc"] = self.ccs - if self.bccs: + if self.bccs != None: personalization["bcc"] = self.bccs - if self.subject: + if self.subject != None: personalization["subject"] = self.subject - if self.headers: + if self.headers != None: headers = {} for key in self.headers: headers.update(key) personalization["headers"] = headers - if self.substitutions: + if self.substitutions != None: substitutions = {} for key in self.substitutions: substitutions.update(key) personalization["substitutions"] = substitutions - if self.custom_args: + if self.custom_args != None: custom_args = {} for key in self.custom_args: custom_args.update(key) personalization["custom_args"] = custom_args - if self.send_at: + if self.send_at != None: personalization["send_at"] = self.send_at return personalization @@ -369,22 +369,22 @@ def set_content_id(self, content_id): def get(self): attachment = {} - if self.content: + if self.content != None: attachment["content"] = self.content - if self.type: + if self.type != None: attachment["type"] = self.type - if self.filename: + if self.filename != None: attachment["filename"] = self.filename - if self.disposition: + if self.disposition != None: attachment["disposition"] = self.disposition - if self.content_id: + if self.content_id != None: attachment["content_id"] = self.content_id return attachment class Category(object): def __init__(self, name=None): - self.name = name if name else None + self.name = name if name != None else None def get(self): return self.name @@ -392,28 +392,28 @@ def get(self): class ASM(object): def __init__(self, group_id=None, groups_to_display=None): - self.group_id = group_id if group_id else None - self.groups_to_display = groups_to_display if groups_to_display else None + self.group_id = group_id if group_id != None else None + self.groups_to_display = groups_to_display if groups_to_display != None else None def get(self): asm = {} - if self.group_id: + if self.group_id != None: asm["group_id"] = self.group_id - if self.groups_to_display: + if self.groups_to_display != None: asm["groups_to_display"] = self.groups_to_display return asm class BCCSettings(object): def __init__(self, enable=None, email=None): - self.enable = enable if enable else None - self.email = email if email else None + self.enable = enable if enable != None else None + self.email = email if email != None else None def get(self): bcc_settings = {} - if self.enable: + if self.enable != None: bcc_settings["enable"] = self.enable - if self.email: + if self.email != None: email = self.email.get() bcc_settings["email"] = email["email"] return bcc_settings @@ -421,17 +421,18 @@ def get(self): class BypassListManagement(object): def __init__(self, enable=None): - self.enable = enable if enable else None + self.enable = enable if enable != None else None def get(self): bypass_list_management = {} - bypass_list_management["enable"] = self.enable + if self.enable != None: + bypass_list_management["enable"] = self.enable return bypass_list_management class FooterSettings(object): def __init__(self, enable=None, text=None, html=None): - self.enable = enable if enable else None + self.enable = enable if enable != None else None self.text = text if text else text self.html = html if html else html @@ -446,11 +447,11 @@ def set_html(self, html): def get(self): footer_settings = {} - if self.enable: + if self.enable != None: footer_settings["enable"] = self.enable - if self.text: + if self.text != None: footer_settings["text"] = self.text - if self.html: + if self.html != None: footer_settings["html"] = self.html return footer_settings @@ -461,15 +462,16 @@ def __init__(self, enable=None): def get(self): sandbox_mode = {} - sandbox_mode["enable"] = self.enable + if self.enable != None: + sandbox_mode["enable"] = self.enable return sandbox_mode class SpamCheck(object): def __init__(self, enable=None, threshold=None, post_to_url=None): - self.enable = enable if enable else None - self.threshold = threshold if threshold else None - self.post_to_url = post_to_url if post_to_url else None + self.enable = enable if enable != None else None + self.threshold = threshold if threshold != None else None + self.post_to_url = post_to_url if post_to_url != None else None def set_enable(self, enable): self.enable = enable @@ -482,11 +484,11 @@ def set_post_to_url(self, post_to_url): def get(self): spam_check = {} - if self.enable: + if self.enable != None: spam_check["enable"] = self.enable - if self.threshold: + if self.threshold != None: spam_check["threshold"] = self.threshold - if self.post_to_url: + if self.post_to_url != None: spam_check["post_to_url"] = self.post_to_url return spam_check @@ -516,15 +518,15 @@ def set_spam_check(self, spam_check): def get(self): mail_settings = {} - if self.bcc_settings: + if self.bcc_settings != None: mail_settings["bcc"] = self.bcc_settings.get() - if self.bypass_list_management: + if self.bypass_list_management != None: mail_settings["bypass_list_management"] = self.bypass_list_management.get() - if self.footer_settings: + if self.footer_settings != None: mail_settings["footer"] = self.footer_settings.get() - if self.sandbox_mode: + if self.sandbox_mode != None: mail_settings["sandbox_mode"] = self.sandbox_mode.get() - if self.spam_check: + if self.spam_check != None: mail_settings["spam_check"] = self.spam_check.get() return mail_settings @@ -532,7 +534,7 @@ def get(self): class ClickTracking(object): def __init__(self, enable=None, enable_text=None): self.enable = enable if enable else None - self.enable_text = enable_text if enable_text else None + self.enable_text = enable_text if enable_text !=None else None def set_enable(self, enable): self.enable = enable @@ -542,17 +544,17 @@ def set_enable_text(self, enable_text): def get(self): click_tracking = {} - if self.enable: + if self.enable != None: click_tracking["enable"] = self.enable - if self.enable_text: + if self.enable_text != None: click_tracking["enable_text"] = self.enable_text return click_tracking class OpenTracking(object): def __init__(self, enable=None, substitution_tag=None): - self.enable = enable if enable else None - self.substitution_tag = substitution_tag if substitution_tag else None + self.enable = enable if enable != None else None + self.substitution_tag = substitution_tag if substitution_tag !=None else None def set_enable(self, enable): self.enable = enable @@ -562,19 +564,19 @@ def set_substitution_tag(self, substitution_tag): def get(self): open_tracking = {} - if self.enable: + if self.enable != None: open_tracking["enable"] = self.enable - if self.substitution_tag: + if self.substitution_tag != None: open_tracking["substitution_tag"] = self.substitution_tag return open_tracking class SubscriptionTracking(object): def __init__(self, enable=None, text=None, html=None, substitution_tag=None): - self.enable = enable if enable else None - self.text = text if text else None - self.html = html if html else None - self.substitution_tag = substitution_tag if substitution_tag else None + self.enable = enable if enable != None else None + self.text = text if text != None else None + self.html = html if html != None else None + self.substitution_tag = substitution_tag if substitution_tag != None else None def set_enable(self, enable): self.enable = enable @@ -590,13 +592,13 @@ def set_substitution_tag(self, substitution_tag): def get(self): subscription_tracking = {} - if self.enable: + if self.enable != None: subscription_tracking["enable"] = self.enable - if self.text: + if self.text != None: subscription_tracking["text"] = self.text - if self.html: + if self.html != None: subscription_tracking["html"] = self.html - if self.substitution_tag: + if self.substitution_tag != None: subscription_tracking["substitution_tag"] = self.substitution_tag return subscription_tracking @@ -609,12 +611,12 @@ def __init__(self, utm_term=None, utm_content=None, utm_campaign=None): - self.enable = enable if enable else None - self.utm_source = utm_source if utm_source else None - self.utm_medium = utm_medium if utm_medium else None - self.utm_term = utm_term if utm_term else None - self.utm_content = utm_content if utm_content else None - self.utm_campaign = utm_campaign if utm_campaign else None + self.enable = enable if enable != None else None + self.utm_source = utm_source if utm_source != None else None + self.utm_medium = utm_medium if utm_medium != None else None + self.utm_term = utm_term if utm_term != None else None + self.utm_content = utm_content if utm_content != None else None + self.utm_campaign = utm_campaign if utm_campaign != None else None def set_enable(self, enable): self.enable = enable @@ -636,17 +638,17 @@ def set_utm_campaign(self, utm_campaign): def get(self): ganalytics = {} - if self.enable: + if self.enable != None: ganalytics["enable"] = self.enable - if self.utm_source: + if self.utm_source != None: ganalytics["utm_source"] = self.utm_source - if self.utm_medium: + if self.utm_medium != None: ganalytics["utm_medium"] = self.utm_medium - if self.utm_term: + if self.utm_term != None: ganalytics["utm_term"] = self.utm_term - if self.utm_content: + if self.utm_content != None: ganalytics["utm_content"] = self.utm_content - if self.utm_campaign: + if self.utm_campaign != None: ganalytics["utm_campaign"] = self.utm_campaign return ganalytics @@ -672,12 +674,12 @@ def set_ganalytics(self, ganalytics): def get(self): tracking_settings = {} - if self.click_tracking: + if self.click_tracking != None: tracking_settings["click_tracking"] = self.click_tracking.get() - if self.open_tracking: + if self.open_tracking != None: tracking_settings["open_tracking"] = self.open_tracking.get() - if self.subscription_tracking: + if self.subscription_tracking != None: tracking_settings["subscription_tracking"] = self.subscription_tracking.get() - if self.ganalytics: + if self.ganalytics != None: tracking_settings["ganalytics"] = self.ganalytics.get() return tracking_settings