@@ -41,60 +41,27 @@ def get(self):
41
41
:return: response body dict
42
42
"""
43
43
mail = {}
44
- if self .from_email is not None :
45
- mail ["from" ] = self .from_email .get ()
46
- if self .subject is not None :
47
- mail ["subject" ] = self .subject
48
-
49
- if self .personalizations is not None :
50
- mail ["personalizations" ] = [
51
- personalization .get ()
52
- for personalization in self .personalizations
53
- ]
54
-
55
- if self .contents is not None :
56
- mail ["content" ] = [ob .get () for ob in self .contents ]
57
-
58
- if self .attachments is not None :
59
- mail ["attachments" ] = [ob .get () for ob in self .attachments ]
60
-
61
- if self .template_id is not None :
62
- mail ["template_id" ] = self .template_id
63
-
64
- if self .sections is not None :
65
- sections = {}
66
- for key in self .sections :
67
- sections .update (key .get ())
68
- mail ["sections" ] = sections
69
-
70
- if self .headers is not None :
71
- headers = {}
72
- for key in self .headers :
73
- headers .update (key .get ())
74
- mail ["headers" ] = headers
75
44
76
- if self .categories is not None :
77
- mail ["categories" ] = [category .get () for category in
78
- self .categories ]
45
+ KEYS_TO_BE_SENT = [
46
+ 'subject' , 'personalizations' ,'attachments' , 'template_id' ,
47
+ 'sections' , 'headers' , 'categories' , 'custom_args' ,
48
+ 'send_at' , 'batch_id' , 'ip_pool_name'
49
+ ]
79
50
80
- if self .custom_args is not None :
81
- custom_args = {}
82
- for key in self .custom_args :
83
- custom_args .update (key .get ())
84
- mail ["custom_args" ] = custom_args
51
+ for key in KEYS_TO_BE_SENT :
52
+ value = getattr (self , key , None )
53
+ if value is not None :
54
+ mail [key ] = value
85
55
86
- if self .send_at is not None :
87
- mail ["send_at " ] = self .send_at
56
+ if self .contents is not None :
57
+ mail ["content " ] = self .contents
88
58
89
- if self .batch_id is not None :
90
- mail ["batch_id " ] = self .batch_id
59
+ if self .from_email is not None :
60
+ mail ["from " ] = self .from_email . get ()
91
61
92
62
if self .asm is not None :
93
63
mail ["asm" ] = self .asm .get ()
94
64
95
- if self .ip_pool_name is not None :
96
- mail ["ip_pool_name" ] = self .ip_pool_name
97
-
98
65
if self .mail_settings is not None :
99
66
mail ["mail_settings" ] = self .mail_settings .get ()
100
67
@@ -103,6 +70,7 @@ def get(self):
103
70
104
71
if self .reply_to is not None :
105
72
mail ["reply_to" ] = self .reply_to .get ()
73
+
106
74
return mail
107
75
108
76
@property
@@ -187,7 +155,14 @@ def reply_to(self, value):
187
155
188
156
@property
189
157
def personalizations (self ):
190
- return self ._personalizations
158
+ """Returns personalizations as a list of dictionaries as returned
159
+ by Personalization class"""
160
+ if self ._personalizations is not None :
161
+ return [
162
+ personalization .get ()
163
+ for personalization in self ._personalizations
164
+ ]
165
+ return None
191
166
192
167
def add_personalization (self , personalizations ):
193
168
if self ._personalizations is None :
@@ -196,7 +171,11 @@ def add_personalization(self, personalizations):
196
171
197
172
@property
198
173
def contents (self ):
199
- return self ._contents
174
+ """Returns contents as a list of dictionaries as returned by
175
+ Content class"""
176
+ if self ._contents is not None :
177
+ return [ob .get () for ob in self ._contents ]
178
+ return None
200
179
201
180
def add_content (self , content ):
202
181
if self ._contents is None :
@@ -205,7 +184,9 @@ def add_content(self, content):
205
184
206
185
@property
207
186
def attachments (self ):
208
- return self ._attachments
187
+ if self ._attachments is not None :
188
+ return [ob .get () for ob in self ._attachments ]
189
+ return None
209
190
210
191
def add_attachment (self , attachment ):
211
192
if self ._attachments is None :
@@ -214,7 +195,12 @@ def add_attachment(self, attachment):
214
195
215
196
@property
216
197
def sections (self ):
217
- return self ._sections
198
+ if self ._sections is not None :
199
+ sections = {}
200
+ for key in self ._sections :
201
+ sections .update (key .get ())
202
+ return sections
203
+ return None
218
204
219
205
def add_section (self , section ):
220
206
if self ._sections is None :
@@ -223,7 +209,13 @@ def add_section(self, section):
223
209
224
210
@property
225
211
def headers (self ):
226
- return self ._headers
212
+ """Returns headers of emails as dicationary"""
213
+ if self ._headers is not None :
214
+ headers = {}
215
+ for key in self ._headers :
216
+ headers .update (key .get ())
217
+ return headers
218
+ return None
227
219
228
220
def add_header (self , header ):
229
221
if self ._headers is None :
@@ -236,7 +228,11 @@ def add_header(self, header):
236
228
237
229
@property
238
230
def categories (self ):
239
- return self ._categories
231
+ """Returns list of categories"""
232
+ if self ._categories is not None :
233
+ return [category .get () for category in
234
+ self ._categories ]
235
+ return None
240
236
241
237
def add_category (self , category ):
242
238
if self ._categories is None :
@@ -245,7 +241,13 @@ def add_category(self, category):
245
241
246
242
@property
247
243
def custom_args (self ):
248
- return self ._custom_args
244
+ """Returns custom_args as a dicationary"""
245
+ if self ._custom_args is not None :
246
+ custom_args = {}
247
+ for key in self ._custom_args :
248
+ custom_args .update (key .get ())
249
+ return custom_args
250
+ return None
249
251
250
252
def add_custom_arg (self , custom_arg ):
251
253
if self ._custom_args is None :
0 commit comments