MCPcopy Index your code
hub / github.com/sendgrid/sendgrid-nodejs / fromData

Method fromData

packages/helpers/classes/mail.js:53–116  ·  view source on GitHub ↗

* Build from data

(data)

Source from the content-addressed store, hash-verified

51 * Build from data
52 */
53 fromData(data) {
54
55 //Expecting object
56 if (typeof data !== 'object') {
57 throw new Error('Expecting object for Mail data');
58 }
59
60 //Convert to camel case to make it workable, making a copy to prevent
61 //changes to the original objects
62 data = deepClone(data);
63 data = toCamelCase(data, ['substitutions', 'dynamicTemplateData', 'customArgs', 'headers', 'sections']);
64
65 //Extract properties from data
66 const {
67 to, from, replyTo, cc, bcc, sendAt, subject, text, html, content,
68 templateId, personalizations, attachments, ipPoolName, batchId,
69 sections, headers, categories, category, customArgs, asm, mailSettings,
70 trackingSettings, substitutions, substitutionWrappers, dynamicTemplateData, isMultiple,
71 hideWarnings, replyToList,
72 } = data;
73
74 //Set data
75 this.setFrom(from);
76 this.setReplyTo(replyTo);
77 this.setSubject(subject);
78 this.setSendAt(sendAt);
79 this.setTemplateId(templateId);
80 this.setBatchId(batchId);
81 this.setIpPoolName(ipPoolName);
82 this.setAttachments(attachments);
83 this.setContent(content);
84 this.setSections(sections);
85 this.setHeaders(headers);
86 this.setCategories(category);
87 this.setCategories(categories);
88 this.setCustomArgs(customArgs);
89 this.setAsm(asm);
90 this.setMailSettings(mailSettings);
91 this.setTrackingSettings(trackingSettings);
92 this.setHideWarnings(hideWarnings);
93 this.setReplyToList(replyToList);
94
95 if (this.isDynamic) {
96 this.setDynamicTemplateData(dynamicTemplateData);
97 } else {
98 this.setSubstitutions(substitutions);
99 this.setSubstitutionWrappers(substitutionWrappers);
100 }
101
102 //Add contents from text/html properties
103 this.addTextContent(text);
104 this.addHtmlContent(html);
105
106 //Using "to" property for personalizations
107 if (personalizations) {
108 this.setPersonalizations(personalizations);
109 } else if (isMultiple && Array.isArray(to)) {
110 //Multiple individual emails

Callers 4

constructorMethod · 0.95
from-data.spec.jsFile · 0.45
to-json.spec.jsFile · 0.45

Calls 15

setFromMethod · 0.95
setReplyToMethod · 0.95
setSubjectMethod · 0.95
setSendAtMethod · 0.95
setTemplateIdMethod · 0.95
setBatchIdMethod · 0.95
setIpPoolNameMethod · 0.95
setAttachmentsMethod · 0.95
setContentMethod · 0.95
setSectionsMethod · 0.95
setHeadersMethod · 0.95
setCategoriesMethod · 0.95

Tested by

no test coverage detected