Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public static void main(String[] args) {
// [Scheduling](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
header.setSendAt(1416427645);

// [Per email scheduling](https://docs.sendgrid.com/for-developers/sending-email/scheduling-parameters)
header.addSendEachAt(1416427645);

//int sendAt = header.getSendAt();

// Get Headers
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/sendgrid/smtpapi/SMTPAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -203,7 +204,23 @@ public SMTPAPI setSendAt(int sendAt) throws JSONException {

public int getSendAt() throws JSONException {
return this.header.getInt("send_at");
}

public SMTPAPI addSendEachAt(int sendAt) throws JSONException {
if (!this.header.has("send_each_at")) {
this.header.put("send_each_at", new JSONArray());
}
this.header.accumulate("send_each_at", sendAt);
return this;
}

public List<Integer> getSendEachAt() throws JSONException {
JSONArray array = this.header.getJSONArray("send_each_at");
List<Integer> sendTimes = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
sendTimes.add(array.getInt(i));
}
return sendTimes;
}

// convert from string to code point array
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/sendgrid/smtpapi/SMTPAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.*;
import java.util.Calendar;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -151,6 +152,14 @@ public class SMTPAPITest {
Assert.assertEquals(expected, test.getSendAt());
}

@Test public void testSetSendEachAt() throws JSONException {
int expected = 12345;
test.addSendEachAt(expected);
List<Integer> output = test.getSendEachAt();
Assert.assertEquals(1, output.size());
Assert.assertEquals(expected, test.getSendEachAt().get(0), 0);
}

@Test public void testCopyrightDateRange() throws JSONException {
int expectedYear = Calendar.getInstance().get(Calendar.YEAR);
String copyRightLine = getCopyrightDateRangeLine("LICENSE");
Expand Down