-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from cal-itp/bugfix/generalize-sendgrid
resolve changes to sendgrid.java that served only graas report
- Loading branch information
Showing
1 changed file
with
11 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,13 @@ public class SendGrid { | |
private String[] tos; | ||
private String subject; | ||
private String body; | ||
private Map<String, byte[]> blobMap; | ||
private Map<String, byte[]> imageMap; | ||
|
||
public SendGrid(String[] recipients, String emailSubject, String body, Map<String, byte[]> images) { | ||
public SendGrid(String[] recipients, String emailSubject, String body, Map<String, byte[]> imageMap) { | ||
this.tos = recipients; | ||
this.subject = emailSubject; | ||
this.body = escape(body); | ||
this.blobMap = images; | ||
this.imageMap = imageMap; | ||
} | ||
|
||
private String escape(String s) { | ||
|
@@ -54,8 +54,8 @@ private String makeTos() { | |
private String makeAttachments() { | ||
StringBuffer sb = new StringBuffer(); | ||
|
||
for (String key : blobMap.keySet()) { | ||
byte[] buf = blobMap.get(key); | ||
for (String key : imageMap.keySet()) { | ||
byte[] buf = imageMap.get(key); | ||
|
||
if (sb.length() > 0) { | ||
sb.append(','); | ||
|
@@ -74,11 +74,12 @@ private String makeAttachments() { | |
|
||
public int send() { | ||
String attach = ""; | ||
|
||
if (blobMap.size() > 0) { | ||
attach = String.format(",\"attachments\": [%s]", makeAttachments()); | ||
} else{ | ||
body = "There are no files in today's GRaaS report"; | ||
if(imageMap != null){ | ||
if (imageMap.size() > 0) { | ||
attach = String.format(",\"attachments\": [%s]", makeAttachments()); | ||
} else{ | ||
body = "There are no images attached"; | ||
} | ||
} | ||
|
||
String from = "[email protected]"; | ||
|