Skip to content

Commit 31a92f8

Browse files
author
Chris Wilson
committed
Releases SparkPost lib 0.23
1 parent aef38c6 commit 31a92f8

24 files changed

+239
-202
lines changed

apps/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>com.sparkpost</groupId>
55
<artifactId>sparkpost</artifactId>
6-
<version>0.22</version>
6+
<version>0.23</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>apps</artifactId>

apps/sparkpost-documentor-app/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.sparkpost</groupId>
66
<artifactId>apps</artifactId>
7-
<version>0.22</version>
7+
<version>0.23</version>
88
</parent>
99
<artifactId>sparkpost-documentor-app</artifactId>
1010
<name>Generates Markdown of Protocol</name>

apps/sparkpost-javamail-app/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.sparkpost</groupId>
88
<artifactId>apps</artifactId>
9-
<version>0.22</version>
9+
<version>0.23</version>
1010
</parent>
1111
<groupId>com.sparkpost.sample</groupId>
1212
<artifactId>sparkpost-javamail-app</artifactId>

apps/sparkpost-samples-app/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.sparkpost</groupId>
66
<artifactId>apps</artifactId>
7-
<version>0.22</version>
7+
<version>0.23</version>
88
</parent>
99
<artifactId>sparkpost-samples-app</artifactId>
1010
<name>Example use SparkPost library</name>

apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/MandrillBlacklistImport.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ private void runApp() throws SparkPostException, IOException {
109109
entry.setDescription("MBL: " + line);
110110
entry.setEmail(entryRow[Fields.EMAIL_COL]);
111111
// Assumes Mandrill blacklist is only for non-transactional email
112-
entry.setTransactional(false);
113-
entry.setNonTransactional(true);
112+
entry.setType(SuppressionListEntry.TypeTypes.TRANSACTIONAL_TYPE);
114113

115114
// Leave off source so it is set to "Manually Added"
116115
// entry.setSource(null);

apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/MessageEventSearchSample.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ private void doSearch() throws SparkPostException, IOException, InterruptedExcep
4444

4545
// Message events can be filtered with the Message Event Query Builder
4646
MessageEventsQueryBuilder query = null;
47-
//query = new MessageEventsQueryBuilder();
47+
query = new MessageEventsQueryBuilder();
48+
49+
// Query by date range
50+
//query.setFromDateTime("2020-09-27T00:00");
51+
//query.setToDateTime("2020-10-01T00:00");
52+
53+
// Query by Message Id
4854
//query.addMessageId("Message ID Here");
4955

5056
response = ResourceMessageEvents.searchMessageEvents(connection, 10, query);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
package com.sparkpost.samples;
3+
4+
import java.io.IOException;
5+
import java.util.ArrayList;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import org.apache.log4j.Level;
11+
import org.apache.log4j.Logger;
12+
13+
import com.sparkpost.Client;
14+
import com.sparkpost.exception.SparkPostException;
15+
import com.sparkpost.model.AddressAttributes;
16+
import com.sparkpost.model.RecipientAttributes;
17+
import com.sparkpost.model.TemplateContentAttributes;
18+
import com.sparkpost.model.TransmissionWithRecipientArray;
19+
import com.sparkpost.model.responses.Response;
20+
import com.sparkpost.resources.ResourceTransmissions;
21+
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
22+
import com.sparkpost.transport.IRestConnection;
23+
import com.sparkpost.transport.RestConnection;
24+
25+
public class SendAmpEmailSample extends SparkPostBaseApp {
26+
27+
static final Logger logger = Logger.getLogger(CreateTemplateSimple.class);
28+
29+
private Client client;
30+
31+
public static void main(String[] args) throws SparkPostException, IOException {
32+
Logger.getRootLogger().setLevel(Level.DEBUG);
33+
34+
SendAmpEmailSample sample = new SendAmpEmailSample();
35+
sample.runApp();
36+
}
37+
38+
private void runApp() throws SparkPostException, IOException {
39+
this.client = this.newConfiguredClient();
40+
41+
// Loads an email to send from the file system
42+
String fromAddress = getFromAddress();
43+
String[] recipients = getTestRecipients();
44+
45+
sendEmail(fromAddress, recipients);
46+
47+
}
48+
49+
private void sendEmail(String from, String[] recipients) throws SparkPostException {
50+
TransmissionWithRecipientArray transmission = new TransmissionWithRecipientArray();
51+
52+
// Populate Recipients
53+
List<RecipientAttributes> recipientArray = new ArrayList<RecipientAttributes>();
54+
for (String recipient : recipients) {
55+
RecipientAttributes recipientAttribs = new RecipientAttributes();
56+
recipientAttribs.setAddress(new AddressAttributes(recipient));
57+
recipientArray.add(recipientAttribs);
58+
}
59+
transmission.setRecipientArray(recipientArray);
60+
61+
// Populate Substitution Data
62+
Map<String, Object> substitutionData = new HashMap<String, Object>();
63+
substitutionData.put("yourContent", "You can add substitution data too.");
64+
transmission.setSubstitutionData(substitutionData);
65+
66+
// Populate Email Body
67+
TemplateContentAttributes contentAttributes = new TemplateContentAttributes();
68+
contentAttributes.setFrom(new AddressAttributes(from));
69+
contentAttributes.setSubject("☰ Your subject content here. {{yourContent}}");
70+
contentAttributes.setText("Your Text content here. {{yourContent}}");
71+
contentAttributes.setHtml("<p>Your <b>HTML</b> content here. {{yourContent}}</p>");
72+
contentAttributes.setAmpHtml("<p>Your <b>AMP HTML</b> content here. {{yourContent}}</p>");
73+
transmission.setContentAttributes(contentAttributes);
74+
75+
transmission.setContentAttributes(contentAttributes);
76+
77+
// Send the Email
78+
IRestConnection connection = new RestConnection(this.client, getEndPoint());
79+
Response response = ResourceTransmissions.create(connection, 0, transmission);
80+
81+
logger.debug("Transmission Response: " + response);
82+
}
83+
84+
}

libs/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.sparkpost</groupId>
66
<artifactId>sparkpost</artifactId>
7-
<version>0.22</version>
7+
<version>0.23</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>libs</artifactId>

libs/sparkpost-lib/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.sparkpost</groupId>
66
<artifactId>libs</artifactId>
7-
<version>0.22</version>
7+
<version>0.23</version>
88
</parent>
99
<!-- <version>0.10</version> -->
1010
<artifactId>sparkpost-lib</artifactId>

libs/sparkpost-lib/src/main/java/com/sparkpost/Build.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
public class Build {
55

6-
public static final String VERSION = "BUILD_VERSION_NAME";
6+
public static final String VERSION = "0.23";
77

8-
public static final String BUILD_VERSION = "BUILD_GENERATED_VERSION";
8+
public static final String BUILD_VERSION = "230";
99

10-
public static final String GIT_HASH = "BUILD_GENERATED_GIT_HASH";
10+
public static final String GIT_HASH = "aef38c687cd621e3e313c9a3be7d03c3806ce342";
1111

12-
public static final String GIT_SHORT_HASH = "BUILD_GENERATED_SHORT_GIT_HASH";
12+
public static final String GIT_SHORT_HASH = "aef38c6";
1313

14-
public static final String BUILD_DATE = "BUILD_GENERATED_DATE";
14+
public static final String BUILD_DATE = "Fri Oct 23 14:52:00 CDT 2020";
1515

1616
}

libs/sparkpost-lib/src/main/java/com/sparkpost/model/SuppressionListEntry.java

+36-5
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,47 @@ public class SuppressionListEntry extends Base {
1717
public static final class StatusTypes {
1818

1919
public static final String FBL = "FBL";
20+
public static final String SPAM_COMPLAING = "Spam Complaint";
2021
public static final String LIST_UNSUBSCRIBE = "List Unsubscribe";
2122
public static final String BOUNCE_RULE = "Bounce Rule";
2223
public static final String UNSUBSCRIBE_LINK = "Unsubscribe Link";
2324
public static final String MANUALLY_ADDED = "Manually Added";
2425
public static final String COMPLIANCE = "Compliance";
2526
}
2627

28+
public static final class TypeTypes {
29+
30+
public static final String TRANSACTIONAL_TYPE = "transactional";
31+
public static final String NON_TRANSACTIONAL_TYPE = "non_transactional";
32+
}
33+
2734
public SuppressionListEntry() {
2835

2936
}
3037

3138
public SuppressionListEntry(SuppressionListEntry entry) {
3239
this.email = entry.email;
33-
this.transactional = entry.transactional;
34-
this.nonTransactional = entry.nonTransactional;
40+
//this.transactional = entry.transactional;
41+
//this.nonTransactional = entry.nonTransactional;
42+
this.type = entry.type;
3543
this.source = entry.source;
3644
this.description = entry.description;
3745

3846
}
3947

4048
/**
41-
*
49+
*
4250
*/
4351
@Description(value = "Email Address", sample = {"[email protected]"})
4452
private String email;
4553

4654
/**
4755
* Whether the recipient requested to not receive any transactional messages
4856
* At a minimum, transactional or non_transactional is required upon creation of the entry.
57+
*
58+
* @deprecated Use Type instead
4959
*/
60+
@Deprecated
5061
@Description(
5162
value = "Whether the recipient requested to not receive any transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry.",
5263
sample = {"true"})
@@ -55,15 +66,19 @@ public SuppressionListEntry(SuppressionListEntry entry) {
5566
/**
5667
* Whether the recipient requested to not receive any non-transactional messages
5768
* At a minimum, transactional or non_transactional is required upon creation of the entry.
69+
*
70+
* @deprecated Use Type instead
5871
*/
5972
@Description(
6073
value = "Whether the recipient requested to not receive any non-transactional messages. At a minimum, transactional or non_transactional is required upon creation of the entry.",
6174
sample = {"false"})
6275
@SerializedName("non_transactional")
76+
@Deprecated
6377
private boolean nonTransactional;
6478

6579
/**
66-
* Source responsible for inserting the list entry. Valid values include: FBL, List Unsubscribe, Bounce Rule, Unsubscribe Link, Manually Added, Compliance
80+
* Source responsible for inserting the list entry. Valid values include: Spam Complaint, List Unsubscribe, Bounce Rule, Unsubscribe Link, Manually Added,
81+
* Compliance
6782
* defaults to Manually Added on create
6883
* See StatusTypes
6984
*/
@@ -75,7 +90,23 @@ public SuppressionListEntry(SuppressionListEntry entry) {
7590
/**
7691
* Short explanation of the suppression
7792
*/
78-
@Description(value = "Short explanation of the suppression", sample = {""})
93+
@Description(value = "Short explanation of the suppression", sample = {"Unsubscribed using list unsubscribe header"})
7994
private String description;
8095

96+
@Description(value = "Type of suppression record. See TypeTypes", sample = {"transactional or non_transactional"})
97+
private String type;
98+
99+
@Description(value = "Email address to be suppressed", sample = {"[email protected]"})
100+
private String recipient;
101+
102+
@Description(value = "Date suppression was created", sample = {"2017-10-01T12:00:00+00:00"})
103+
private String created;
104+
105+
@Description(value = "Last time the suppression was updated", sample = {"2017-10-01T12:00:00+00:00"})
106+
private String updated;
107+
108+
@Description(value = "Which subaccount the recipient is suppressed for. Only returned if suppressed for a specific subaccount.", sample = {"0"})
109+
@SerializedName("subaccount_id")
110+
private int subaccountId;
111+
81112
}

libs/sparkpost-lib/src/main/java/com/sparkpost/model/TemplateContentAttributes.java

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public class TemplateContentAttributes extends Base {
4040
@Description(value = "HTML Content of email", sample = {"HTML Content"})
4141
private String html = null;
4242

43+
@Description(value = "Amp HTML Content of email", sample = {"AMP HTML Content"})
44+
@SerializedName("amp_html")
45+
private String ampHtml = null;
46+
4347
@Description(value = "Text content for the email's text/plain MIME part", sample = {"Text Content"})
4448
private String text = null;
4549

libs/sparkpost-lib/src/main/java/com/sparkpost/model/TransmissionBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public final static class TransmissionStates {
7272
@Description(
7373
value = "Transmission level metadata containing key/value pairs. Metadata is available during events through the Webhooks and is provided to the substitution engine. A maximum of 1000 bytes of merged metadata (transmission level + recipient level) is available with recipient metadata taking precedence over transmission metadata when there are conflicts.",
7474
sample = {""})
75-
private Map<String, String> metadata = null;
75+
private Map<String, Object> metadata = null;
7676

7777
/**
7878
* Key/value pairs that are provided to the substitution engine

libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/MessageEventsResponse.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ public class MessageEventsResponse extends Response {
1919
@SerializedName("results")
2020
private List<Map<String, Object>> results;
2121

22-
@Description(value = "links", sample = {"{ \"href\": \"/api/v1/message-events\", \"rel\": \"message-events\", \"method\": \"GET\" }"})
22+
@Description(
23+
value = "links",
24+
sample = {
25+
"{ \"next\": \"/api/v1/events/message?events=delivery&per_page=1000&cursor=WycyMDE4LTExLTA1VDIyOjQ1OjM5LjAwMFonLCAnc3BjLTM4MTQ1MjY3MjMyNTA2NTEwJ10=\" }"})
2326
@SerializedName("links")
24-
private List<Map<String, String>> links;
27+
private Map<String, String> links;
2528

2629
@Description(value = "total_count", sample = {"{ \"total_count\": 0 }"})
2730
@SerializedName("total_count")
@@ -33,18 +36,12 @@ public boolean hasNext() {
3336
}
3437

3538
public String nextPageUrl() {
36-
if (this.links.size() == 0) {
39+
if (this.links == null || this.links.isEmpty()) {
3740
return "";
3841
}
3942

40-
for (Map<String, String> element : this.links) {
41-
String value = element.get("rel");
42-
if ("next".equalsIgnoreCase(value)) {
43-
return element.get("href");
44-
}
45-
}
46-
47-
return "";
43+
String value = this.links.get("next");
44+
return value;
4845
}
4946

5047
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
package com.sparkpost.model.responses;
3+
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import com.google.gson.annotations.SerializedName;
8+
import com.sparkpost.model.SuppressionListEntry;
9+
import com.yepher.jsondoc.annotations.Description;
10+
11+
import lombok.Data;
12+
import lombok.EqualsAndHashCode;
13+
14+
@Data
15+
@EqualsAndHashCode(callSuper = true)
16+
public class SupressionListResponse extends Response {
17+
18+
@Description(value = "Type of suppression record.", sample = {"transactional or non_transactional"})
19+
private String type;
20+
21+
@Description(value = "List of TemplateItems", sample = {""})
22+
private List<SuppressionListEntry> results;
23+
24+
@Description(value = "links", sample = {""})
25+
@SerializedName("links")
26+
private Map<String, String> links;
27+
28+
@Description(value = "total_count", sample = {"{ \"total_count\": 0 }"})
29+
@SerializedName("total_count")
30+
private int totalCount;
31+
32+
public boolean hasNext() {
33+
String next = nextPageUrl();
34+
return next != null && nextPageUrl().length() > 0;
35+
}
36+
37+
public String nextPageUrl() {
38+
if (this.links == null || this.links.isEmpty()) {
39+
return "";
40+
}
41+
42+
String value = this.links.get("next");
43+
return value;
44+
}
45+
46+
}

0 commit comments

Comments
 (0)