-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Wilson
committed
Oct 23, 2020
1 parent
aef38c6
commit 31a92f8
Showing
24 changed files
with
239 additions
and
202 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
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
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
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
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
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
84 changes: 84 additions & 0 deletions
84
apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/SendAmpEmailSample.java
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 |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
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
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
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
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
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
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
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
46 changes: 46 additions & 0 deletions
46
libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/SupressionListResponse.java
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 |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
Oops, something went wrong.