Skip to content

Commit

Permalink
Fix method_complexity issue in sendgrid/helpers/mail/ganalytics.py #498
Browse files Browse the repository at this point in the history
  • Loading branch information
Chetan committed Oct 31, 2017
1 parent 7c5bf33 commit f0d3975
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions sendgrid/helpers/mail/ganalytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ def __init__(self,
self._utm_content = None
self._utm_campaign = None

if enable is not None:
self.enable = enable
if utm_source is not None:
self.utm_source = utm_source
if utm_medium is not None:
self.utm_medium = utm_medium
if utm_term is not None:
self.utm_term = utm_term
if utm_content is not None:
self.utm_content = utm_content
if utm_campaign is not None:
self.utm_campaign = utm_campaign
self.__set_field("enable", enable)
self.__set_field("utm_source", utm_source)
self.__set_field("utm_medium", utm_medium)
self.__set_field("utm_term", utm_term)
self.__set_field("utm_content", utm_content)
self.__set_field("utm_campaign", utm_campaign)

def __set_field(self, field, value):
""" Sets a field to the provided value if value is not None
:param field: Name of the field
:type field: String
:param value: value to be set, ignored if None
:type value: Any
"""
if value is not None:
setattr(self, field, value)

@property
def enable(self):
Expand Down Expand Up @@ -123,17 +128,14 @@ def get(self):
:returns: This Ganalytics, ready for use in a request body.
:rtype: dict
"""
keys = ["enable", "utm_source", "utm_medium", "utm_term",
"utm_content", "utm_campaign"]

ganalytics = {}
if self.enable is not None:
ganalytics["enable"] = self.enable
if self.utm_source is not None:
ganalytics["utm_source"] = self.utm_source
if self.utm_medium is not None:
ganalytics["utm_medium"] = self.utm_medium
if self.utm_term is not None:
ganalytics["utm_term"] = self.utm_term
if self.utm_content is not None:
ganalytics["utm_content"] = self.utm_content
if self.utm_campaign is not None:
ganalytics["utm_campaign"] = self.utm_campaign

for key in keys:
value = getattr(self, key, None)
if value is not None:
ganalytics[key] = value

return ganalytics

0 comments on commit f0d3975

Please sign in to comment.