Last active
December 11, 2015 16:58
-
-
Save slimbo/4631164 to your computer and use it in GitHub Desktop.
Hit the Bits! - What vs. How - Demonstrates the importance of writing code that focuses on What instead of How.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void function sendEmailMessages(string emailTemplate) | |
| { | |
| var msg = ""; | |
| var mailer = new Mail(); | |
| var totalPointCount = 0; | |
| mailer.setSubject("Thank you for your recent purchase"); | |
| mailer.setFrom("[email protected]"); | |
| var userQuery = new Query(); | |
| userQuery.setDataSource("depot"); | |
| userQuery.setSql("select * from EmailList where Category = 5"); | |
| var users = userQuery.execute().getResult(); | |
| for(var i = 1; i lte users.recordCount; i++) | |
| { | |
| mailer.setTo(users.email); | |
| msg = emailTemplate; | |
| msg = replace(msg, "{First}", users.firstName[i], "all"); | |
| msg = replace(msg, "{Last}", users.lastName[i], "all"); | |
| msg = replace(msg, "{PurchaseDate}", dateFormat(users.PurchaseDate[i], "mmmm d"), "all"); | |
| msg = replace(msg, "{Points}", users.PointCount[i], "all"); | |
| mailer.setBody(msg); | |
| totalPointCount += users.PointCount[i]; | |
| mailer.send(); | |
| } | |
| writeLog( | |
| text="Sent email to #users.recordCount# users. Total point count is #totalPointCount#", | |
| file="point-count-emails" | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void function sendEmailMessages(string emailTemplate) | |
| { | |
| var mailer = configureMailService(); | |
| var users = getUserRecords(); | |
| for(var user in users) | |
| { | |
| var msg = fillTemplate(emailTemplate, user); | |
| mailer.setTo(user.email); | |
| mailer.setBody(msg); | |
| mailer.send(); | |
| } | |
| logResult(users); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment