Skip to content

Commit

Permalink
Releases SparkPost lib 0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Wilson committed Oct 23, 2020
1 parent aef38c6 commit 31a92f8
Show file tree
Hide file tree
Showing 24 changed files with 239 additions and 202 deletions.
2 changes: 1 addition & 1 deletion apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>sparkpost</artifactId>
<version>0.22</version>
<version>0.23</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apps</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apps/sparkpost-documentor-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>apps</artifactId>
<version>0.22</version>
<version>0.23</version>
</parent>
<artifactId>sparkpost-documentor-app</artifactId>
<name>Generates Markdown of Protocol</name>
Expand Down
2 changes: 1 addition & 1 deletion apps/sparkpost-javamail-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>apps</artifactId>
<version>0.22</version>
<version>0.23</version>
</parent>
<groupId>com.sparkpost.sample</groupId>
<artifactId>sparkpost-javamail-app</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apps/sparkpost-samples-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>apps</artifactId>
<version>0.22</version>
<version>0.23</version>
</parent>
<artifactId>sparkpost-samples-app</artifactId>
<name>Example use SparkPost library</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ private void runApp() throws SparkPostException, IOException {
entry.setDescription("MBL: " + line);
entry.setEmail(entryRow[Fields.EMAIL_COL]);
// Assumes Mandrill blacklist is only for non-transactional email
entry.setTransactional(false);
entry.setNonTransactional(true);
entry.setType(SuppressionListEntry.TypeTypes.TRANSACTIONAL_TYPE);

// Leave off source so it is set to "Manually Added"
// entry.setSource(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ private void doSearch() throws SparkPostException, IOException, InterruptedExcep

// Message events can be filtered with the Message Event Query Builder
MessageEventsQueryBuilder query = null;
//query = new MessageEventsQueryBuilder();
query = new MessageEventsQueryBuilder();

// Query by date range
//query.setFromDateTime("2020-09-27T00:00");
//query.setToDateTime("2020-10-01T00:00");

// Query by Message Id
//query.addMessageId("Message ID Here");

response = ResourceMessageEvents.searchMessageEvents(connection, 10, query);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

package com.sparkpost.samples;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.sparkpost.Client;
import com.sparkpost.exception.SparkPostException;
import com.sparkpost.model.AddressAttributes;
import com.sparkpost.model.RecipientAttributes;
import com.sparkpost.model.TemplateContentAttributes;
import com.sparkpost.model.TransmissionWithRecipientArray;
import com.sparkpost.model.responses.Response;
import com.sparkpost.resources.ResourceTransmissions;
import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp;
import com.sparkpost.transport.IRestConnection;
import com.sparkpost.transport.RestConnection;

public class SendAmpEmailSample extends SparkPostBaseApp {

static final Logger logger = Logger.getLogger(CreateTemplateSimple.class);

private Client client;

public static void main(String[] args) throws SparkPostException, IOException {
Logger.getRootLogger().setLevel(Level.DEBUG);

SendAmpEmailSample sample = new SendAmpEmailSample();
sample.runApp();
}

private void runApp() throws SparkPostException, IOException {
this.client = this.newConfiguredClient();

// Loads an email to send from the file system
String fromAddress = getFromAddress();
String[] recipients = getTestRecipients();

sendEmail(fromAddress, recipients);

}

private void sendEmail(String from, String[] recipients) throws SparkPostException {
TransmissionWithRecipientArray transmission = new TransmissionWithRecipientArray();

// Populate Recipients
List<RecipientAttributes> recipientArray = new ArrayList<RecipientAttributes>();
for (String recipient : recipients) {
RecipientAttributes recipientAttribs = new RecipientAttributes();
recipientAttribs.setAddress(new AddressAttributes(recipient));
recipientArray.add(recipientAttribs);
}
transmission.setRecipientArray(recipientArray);

// Populate Substitution Data
Map<String, Object> substitutionData = new HashMap<String, Object>();
substitutionData.put("yourContent", "You can add substitution data too.");
transmission.setSubstitutionData(substitutionData);

// Populate Email Body
TemplateContentAttributes contentAttributes = new TemplateContentAttributes();
contentAttributes.setFrom(new AddressAttributes(from));
contentAttributes.setSubject("☰ Your subject content here. {{yourContent}}");
contentAttributes.setText("Your Text content here. {{yourContent}}");
contentAttributes.setHtml("<p>Your <b>HTML</b> content here. {{yourContent}}</p>");
contentAttributes.setAmpHtml("<p>Your <b>AMP HTML</b> content here. {{yourContent}}</p>");
transmission.setContentAttributes(contentAttributes);

transmission.setContentAttributes(contentAttributes);

// Send the Email
IRestConnection connection = new RestConnection(this.client, getEndPoint());
Response response = ResourceTransmissions.create(connection, 0, transmission);

logger.debug("Transmission Response: " + response);
}

}
2 changes: 1 addition & 1 deletion libs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>sparkpost</artifactId>
<version>0.22</version>
<version>0.23</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>libs</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion libs/sparkpost-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.sparkpost</groupId>
<artifactId>libs</artifactId>
<version>0.22</version>
<version>0.23</version>
</parent>
<!-- <version>0.10</version> -->
<artifactId>sparkpost-lib</artifactId>
Expand Down
10 changes: 5 additions & 5 deletions libs/sparkpost-lib/src/main/java/com/sparkpost/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

public class Build {

public static final String VERSION = "BUILD_VERSION_NAME";
public static final String VERSION = "0.23";

public static final String BUILD_VERSION = "BUILD_GENERATED_VERSION";
public static final String BUILD_VERSION = "230";

public static final String GIT_HASH = "BUILD_GENERATED_GIT_HASH";
public static final String GIT_HASH = "aef38c687cd621e3e313c9a3be7d03c3806ce342";

public static final String GIT_SHORT_HASH = "BUILD_GENERATED_SHORT_GIT_HASH";
public static final String GIT_SHORT_HASH = "aef38c6";

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,47 @@ public class SuppressionListEntry extends Base {
public static final class StatusTypes {

public static final String FBL = "FBL";
public static final String SPAM_COMPLAING = "Spam Complaint";
public static final String LIST_UNSUBSCRIBE = "List Unsubscribe";
public static final String BOUNCE_RULE = "Bounce Rule";
public static final String UNSUBSCRIBE_LINK = "Unsubscribe Link";
public static final String MANUALLY_ADDED = "Manually Added";
public static final String COMPLIANCE = "Compliance";
}

public static final class TypeTypes {

public static final String TRANSACTIONAL_TYPE = "transactional";
public static final String NON_TRANSACTIONAL_TYPE = "non_transactional";
}

public SuppressionListEntry() {

}

public SuppressionListEntry(SuppressionListEntry entry) {
this.email = entry.email;
this.transactional = entry.transactional;
this.nonTransactional = entry.nonTransactional;
//this.transactional = entry.transactional;
//this.nonTransactional = entry.nonTransactional;
this.type = entry.type;
this.source = entry.source;
this.description = entry.description;

}

/**
*
*
*/
@Description(value = "Email Address", sample = {"address@example.com"})
private String email;

/**
* Whether the recipient requested to not receive any transactional messages
* At a minimum, transactional or non_transactional is required upon creation of the entry.
*
* @deprecated Use Type instead
*/
@Deprecated
@Description(
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.",
sample = {"true"})
Expand All @@ -55,15 +66,19 @@ public SuppressionListEntry(SuppressionListEntry entry) {
/**
* 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.
*
* @deprecated Use Type instead
*/
@Description(
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.",
sample = {"false"})
@SerializedName("non_transactional")
@Deprecated
private boolean nonTransactional;

/**
* Source responsible for inserting the list entry. Valid values include: FBL, List Unsubscribe, Bounce Rule, Unsubscribe Link, Manually Added, Compliance
* Source responsible for inserting the list entry. Valid values include: Spam Complaint, List Unsubscribe, Bounce Rule, Unsubscribe Link, Manually Added,
* Compliance
* defaults to Manually Added on create
* See StatusTypes
*/
Expand All @@ -75,7 +90,23 @@ public SuppressionListEntry(SuppressionListEntry entry) {
/**
* Short explanation of the suppression
*/
@Description(value = "Short explanation of the suppression", sample = {""})
@Description(value = "Short explanation of the suppression", sample = {"Unsubscribed using list unsubscribe header"})
private String description;

@Description(value = "Type of suppression record. See TypeTypes", sample = {"transactional or non_transactional"})
private String type;

@Description(value = "Email address to be suppressed", sample = {"recip@example.com"})
private String recipient;

@Description(value = "Date suppression was created", sample = {"2017-10-01T12:00:00+00:00"})
private String created;

@Description(value = "Last time the suppression was updated", sample = {"2017-10-01T12:00:00+00:00"})
private String updated;

@Description(value = "Which subaccount the recipient is suppressed for. Only returned if suppressed for a specific subaccount.", sample = {"0"})
@SerializedName("subaccount_id")
private int subaccountId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class TemplateContentAttributes extends Base {
@Description(value = "HTML Content of email", sample = {"HTML Content"})
private String html = null;

@Description(value = "Amp HTML Content of email", sample = {"AMP HTML Content"})
@SerializedName("amp_html")
private String ampHtml = null;

@Description(value = "Text content for the email's text/plain MIME part", sample = {"Text Content"})
private String text = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public final static class TransmissionStates {
@Description(
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.",
sample = {""})
private Map<String, String> metadata = null;
private Map<String, Object> metadata = null;

/**
* Key/value pairs that are provided to the substitution engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public class MessageEventsResponse extends Response {
@SerializedName("results")
private List<Map<String, Object>> results;

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

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

public String nextPageUrl() {
if (this.links.size() == 0) {
if (this.links == null || this.links.isEmpty()) {
return "";
}

for (Map<String, String> element : this.links) {
String value = element.get("rel");
if ("next".equalsIgnoreCase(value)) {
return element.get("href");
}
}

return "";
String value = this.links.get("next");
return value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

package com.sparkpost.model.responses;

import java.util.List;
import java.util.Map;

import com.google.gson.annotations.SerializedName;
import com.sparkpost.model.SuppressionListEntry;
import com.yepher.jsondoc.annotations.Description;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class SupressionListResponse extends Response {

@Description(value = "Type of suppression record.", sample = {"transactional or non_transactional"})
private String type;

@Description(value = "List of TemplateItems", sample = {""})
private List<SuppressionListEntry> results;

@Description(value = "links", sample = {""})
@SerializedName("links")
private Map<String, String> links;

@Description(value = "total_count", sample = {"{ \"total_count\": 0 }"})
@SerializedName("total_count")
private int totalCount;

public boolean hasNext() {
String next = nextPageUrl();
return next != null && nextPageUrl().length() > 0;
}

public String nextPageUrl() {
if (this.links == null || this.links.isEmpty()) {
return "";
}

String value = this.links.get("next");
return value;
}

}
Loading

0 comments on commit 31a92f8

Please sign in to comment.