├── src └── main │ └── resources │ └── empty.txt ├── apps ├── sparkpost-samples-app │ ├── README.md │ ├── .gitignore │ ├── log4j.properties │ ├── log4j2.properties │ ├── .fbExcludeFilterFile │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── sparkpost │ │ │ ├── SparkPost.java │ │ │ ├── samples │ │ │ ├── ListAllWebhooksSample.java │ │ │ ├── ListAllSendingDomains.java │ │ │ ├── ListAllTemplatesSample.java │ │ │ ├── DeleteWebhookSample.java │ │ │ ├── RetrieveAllTemplatesSample.java │ │ │ ├── CreateTemplateSimple.java │ │ │ ├── DeleteSampleTemplates.java │ │ │ ├── CreateTemplateFromFile2.java │ │ │ ├── CreateTemplateFromFile.java │ │ │ ├── SubaccountCRUDSample.java │ │ │ └── CreateRecipientListSample.java │ │ │ └── error │ │ │ └── samples │ │ │ ├── BadApiKeyErrorSample.java │ │ │ └── ForceTransportError.java │ ├── config.properties.example │ ├── samples │ │ ├── sample_sp_substitution_email.eml │ │ └── mandrillBlacklistExample.csv │ └── pom.xml ├── sparkpost-documentor-app │ ├── README.md │ ├── .gitignore │ ├── gen │ │ ├── README.md │ │ └── java │ │ │ └── com │ │ │ └── sparkpost │ │ │ └── model │ │ │ └── webhook │ │ │ └── event │ │ │ ├── ABTestCancellationEvent.java │ │ │ ├── ABTestCompletionEvent.java │ │ │ ├── IngestEventSuccessEvent.java │ │ │ └── IngestEventErrorEvent.java │ ├── log4j.properties │ ├── log4j2.properties │ ├── .fbExcludeFilterFile │ ├── config.properties.example │ └── pom.xml ├── sparkpost-javamail-app │ ├── .gitignore │ ├── java_SparkPost_background.pdf │ ├── src │ │ ├── main │ │ │ └── resources │ │ │ │ └── java_SparkPost_background.pdf │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── sparkpost │ │ │ └── sample │ │ │ └── AppTest.java │ ├── log4j2.properties │ ├── log4j.xml │ ├── .fbExcludeFilterFile │ ├── config.properties.example │ └── pom.xml └── pom.xml ├── .travis.yml ├── libs ├── sparkpost-lib │ ├── .gitignore │ ├── .settings │ │ └── org.eclipse.m2e.core.prefs │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── sparkpost │ │ │ │ ├── model │ │ │ │ ├── webhook │ │ │ │ │ └── event │ │ │ │ │ │ ├── AbstractWebhookEvent.java │ │ │ │ │ │ ├── ABTestCancellationEvent.java │ │ │ │ │ │ ├── ABTestCompletionEvent.java │ │ │ │ │ │ ├── IngestEventSuccessEvent.java │ │ │ │ │ │ └── IngestEventErrorEvent.java │ │ │ │ ├── AttachmentAttributes.java │ │ │ │ ├── InlineImageAttributes.java │ │ │ │ ├── MetricsDeliveriesFields.java │ │ │ │ ├── WebhookIdResponseEntry.java │ │ │ │ ├── responses │ │ │ │ │ ├── TemplateRetrieveResponse.java │ │ │ │ │ ├── TransmissionCreateResponse.java │ │ │ │ │ ├── RecipientListRetrieveResponse.java │ │ │ │ │ ├── TransmissionRetrieveResults.java │ │ │ │ │ ├── ServerErrorResponses.java │ │ │ │ │ ├── TransmissionRetrieveResponseContainer.java │ │ │ │ │ ├── WebhookIdContainerResponse.java │ │ │ │ │ ├── WebhookListAllResponse.java │ │ │ │ │ ├── TemplateListResponse.java │ │ │ │ │ ├── RecipientListsListAllResponse.java │ │ │ │ │ ├── TransmissionListResponse.java │ │ │ │ │ ├── WebhookDescribeResponse.java │ │ │ │ │ ├── DomainListResponse.java │ │ │ │ │ ├── CampaignListResponse.java │ │ │ │ │ ├── ServerErrorResponse.java │ │ │ │ │ ├── TemplateCreateResponse.java │ │ │ │ │ ├── MetricLinkResponse.java │ │ │ │ │ ├── TransmissionCreateItem.java │ │ │ │ │ ├── DeliverabiltyMetricsResponse.java │ │ │ │ │ ├── TemplatePreviewResponse.java │ │ │ │ │ ├── ListAllSendingDomiansResponse.java │ │ │ │ │ ├── SupressionListResponse.java │ │ │ │ │ ├── SubaccountCreateResponse.java │ │ │ │ │ ├── MessageEventsResponse.java │ │ │ │ │ ├── TemplateItemResponse.java │ │ │ │ │ ├── Response.java │ │ │ │ │ └── TransmissionResponseInfo.java │ │ │ │ ├── MetricsDelayReasonFields.java │ │ │ │ ├── DKIMResults.java │ │ │ │ ├── MetricsEngagementFields.java │ │ │ │ ├── Match.java │ │ │ │ ├── MetricsRejectFields.java │ │ │ │ ├── VerifyResponse.java │ │ │ │ ├── TemplateSubstitutionData.java │ │ │ │ ├── StoredRecipientList.java │ │ │ │ ├── VerifyAttributes.java │ │ │ │ ├── AuthCredentials.java │ │ │ │ ├── TemplateItem.java │ │ │ │ ├── AuthRequestDetails.java │ │ │ │ ├── TransmissionWithRecipientList.java │ │ │ │ ├── Webhook.java │ │ │ │ ├── TransmissionWithRecipientArray.java │ │ │ │ ├── StoredTemplate.java │ │ │ │ ├── FileAttributes.java │ │ │ │ ├── DNSAttributes.java │ │ │ │ ├── MetricsBounceFields.java │ │ │ │ ├── AddressAttributes.java │ │ │ │ ├── Base.java │ │ │ │ ├── WebhookDescription.java │ │ │ │ ├── DKIM.java │ │ │ │ ├── SuppressionList.java │ │ │ │ ├── SendingDomain.java │ │ │ │ ├── StatusAttributes.java │ │ │ │ ├── TemplateAttributes.java │ │ │ │ ├── RecipientAttributes.java │ │ │ │ └── RecipientList.java │ │ │ │ ├── Build.java │ │ │ │ ├── exception │ │ │ │ ├── SparkPostIllegalServerResponseException.java │ │ │ │ ├── SparkPostErrorServerResponseException.java │ │ │ │ ├── SparkPostAuthorizationFailedException.java │ │ │ │ ├── SparkPostAccessForbiddenException.java │ │ │ │ └── SparkPostException.java │ │ │ │ ├── resources │ │ │ │ ├── ResourceSubAccountCrud.java │ │ │ │ ├── ResourceSendingDomains.java │ │ │ │ ├── Endpoint.java │ │ │ │ ├── ResourceRecipientLists.java │ │ │ │ └── ResourceMessageEvents.java │ │ │ │ └── transport │ │ │ │ └── IRestConnection.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── sparkpost │ │ │ ├── resources │ │ │ └── BaseResourceTest.java │ │ │ ├── transport │ │ │ └── RestConnectionTest.java │ │ │ ├── model │ │ │ ├── SendingDomainTest.java │ │ │ ├── StoredRecipientListTest.java │ │ │ ├── StoredTemplateTest.java │ │ │ ├── DNSAttributesTest.java │ │ │ ├── SuppressionListTest.java │ │ │ ├── SuppressionListEntryTest.java │ │ │ ├── OptionsAttributesTest.java │ │ │ ├── StatusAttributesTest.java │ │ │ └── AddressAttributesTests.java │ │ │ └── testhelpers │ │ │ └── StubRestConnection.java │ ├── .fbExcludeFilterFile │ └── pom.xml └── pom.xml ├── tools └── bin │ ├── setupLombok.sh │ ├── buildBundles.sh │ ├── doRelease.sh │ ├── checkSignatures.sh │ └── collectJars.sh ├── LICENSE.txt ├── findbugs-exclude.xml ├── DesignDecisions.md └── .gitignore /src/main/resources/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/.gitignore: -------------------------------------------------------------------------------- 1 | config.properties 2 | 3 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/.gitignore: -------------------------------------------------------------------------------- 1 | config.properties 2 | 3 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/.gitignore: -------------------------------------------------------------------------------- 1 | src/main/java/com/sparkpost/Build.java 2 | 3 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/gen/README.md: -------------------------------------------------------------------------------- 1 | Rendered code goes in the `gen` directory. -------------------------------------------------------------------------------- /libs/sparkpost-lib/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/java_SparkPost_background.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SparkPost/java-sparkpost/HEAD/apps/sparkpost-javamail-app/java_SparkPost_background.pdf -------------------------------------------------------------------------------- /tools/bin/setupLombok.sh: -------------------------------------------------------------------------------- 1 | # 2 | # This requires that you have built the project with Maven at least onece 3 | # 4 | 5 | java -jar ~/.m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar 6 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/src/main/resources/java_SparkPost_background.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SparkPost/java-sparkpost/HEAD/apps/sparkpost-javamail-app/src/main/resources/java_SparkPost_background.pdf -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/webhook/event/AbstractWebhookEvent.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.webhook.event; 3 | 4 | public abstract class AbstractWebhookEvent { 5 | 6 | public abstract String getType(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/AttachmentAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | /** 8 | * DTO for a transmission of attachments. 9 | */ 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class AttachmentAttributes extends FileAttributes { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/InlineImageAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | /** 8 | * DTO for a transmission of inline images. 9 | */ 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class InlineImageAttributes extends FileAttributes { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/MetricsDeliveriesFields.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | public class MetricsDeliveriesFields { 5 | 6 | public static final String[] ALL_FIELDS_ARRAY = new String[] {"attempt", "count_delivered"}; 7 | 8 | public static final String ATTEMPT = "attempt"; 9 | public static final String COUNT_DELIVERED = "count_delivered"; 10 | } 11 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=DEBUG, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | 11 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=DEBUG, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | 11 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/WebhookIdResponseEntry.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model; 2 | 3 | import com.yepher.jsondoc.annotations.Description; 4 | 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | 8 | @Data 9 | @EqualsAndHashCode(callSuper = true) 10 | public class WebhookIdResponseEntry extends Base { 11 | 12 | @Description(value = "Created or updated webhook id.") 13 | private String id; 14 | } 15 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TemplateRetrieveResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class TemplateRetrieveResponse extends Response { 12 | 13 | @Description(value = "", sample = {""}) 14 | private TemplateItemResponse results; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/MetricsDelayReasonFields.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | public class MetricsDelayReasonFields { 5 | 6 | public static final String[] ALL_FIELDS_ARRAY = new String[] {"count_delayed", "count_delayed_first", "reason"}; 7 | 8 | public static final String COUNT_DELAYED = "count_delayed"; 9 | public static final String COUNT_DELAYED_FIRST = "count_delayed_first"; 10 | public static final String REASON = "reason"; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TransmissionCreateResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class TransmissionCreateResponse extends Response { 12 | 13 | @Description(value = "Result of transmission", sample = {""}) 14 | private TransmissionCreateItem results; 15 | } 16 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/RecipientListRetrieveResponse.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.responses; 2 | 3 | import com.sparkpost.model.RecipientList; 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class RecipientListRetrieveResponse extends Response { 12 | 13 | @Description(value = "", sample = {""}) 14 | private RecipientList results; 15 | } 16 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/Build.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost; 3 | 4 | public class Build { 5 | 6 | public static final String VERSION = "BUILD_VERSION_NAME"; 7 | 8 | public static final String BUILD_VERSION = "BUILD_GENERATED_VERSION"; 9 | 10 | public static final String GIT_HASH = "BUILD_GENERATED_GIT_HASH"; 11 | 12 | public static final String GIT_SHORT_HASH = "BUILD_GENERATED_SHORT_GIT_HASH"; 13 | 14 | public static final String BUILD_DATE = "BUILD_GENERATED_DATE"; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TransmissionRetrieveResults.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class TransmissionRetrieveResults extends Response { 12 | 13 | @Description(value = "The transmission result", sample = {""}) 14 | private TransmissionRetrieveResponseContainer results; 15 | } 16 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/ServerErrorResponses.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.util.List; 5 | 6 | import com.yepher.jsondoc.annotations.Description; 7 | 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | @Data 12 | @EqualsAndHashCode(callSuper = true) 13 | public class ServerErrorResponses extends Response { 14 | 15 | @Description(value = "An array errors from the server.", sample = {""}) 16 | List errors; 17 | } 18 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/DKIMResults.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class DKIMResults extends Base { 12 | 13 | @Description(value = "DKIM status result.", sample = {""}) 14 | private StatusAttributes status; 15 | 16 | @Description(value = "DKIM data", sample = {""}) 17 | private DKIM dkim; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TransmissionRetrieveResponseContainer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class TransmissionRetrieveResponseContainer extends Response { 12 | 13 | @Description(value = "The transmission information", sample = {""}) 14 | private TransmissionResponseInfo transmission; 15 | } 16 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/log4j2.properties: -------------------------------------------------------------------------------- 1 | status = error 2 | name = PropertiesConfig 3 | 4 | filters = threshold 5 | 6 | filter.threshold.type = ThresholdFilter 7 | filter.threshold.level = debug 8 | 9 | appenders = console 10 | 11 | appender.console.type = Console 12 | appender.console.name = STDOUT 13 | appender.console.layout.type = PatternLayout 14 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 15 | 16 | rootLogger.level = debug 17 | rootLogger.appenderRefs = stdout 18 | rootLogger.appenderRef.stdout.ref = STDOUT 19 | 20 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/log4j2.properties: -------------------------------------------------------------------------------- 1 | status = error 2 | name = PropertiesConfig 3 | 4 | filters = threshold 5 | 6 | filter.threshold.type = ThresholdFilter 7 | filter.threshold.level = debug 8 | 9 | appenders = console 10 | 11 | appender.console.type = Console 12 | appender.console.name = STDOUT 13 | appender.console.layout.type = PatternLayout 14 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 15 | 16 | rootLogger.level = debug 17 | rootLogger.appenderRefs = stdout 18 | rootLogger.appenderRef.stdout.ref = STDOUT 19 | 20 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/log4j2.properties: -------------------------------------------------------------------------------- 1 | status = error 2 | name = PropertiesConfig 3 | 4 | filters = threshold 5 | 6 | filter.threshold.type = ThresholdFilter 7 | filter.threshold.level = debug 8 | 9 | appenders = console 10 | 11 | appender.console.type = Console 12 | appender.console.name = STDOUT 13 | appender.console.layout.type = PatternLayout 14 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 15 | 16 | rootLogger.level = debug 17 | rootLogger.appenderRefs = stdout 18 | rootLogger.appenderRef.stdout.ref = STDOUT 19 | 20 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/WebhookIdContainerResponse.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.responses; 2 | 3 | import com.sparkpost.model.WebhookIdResponseEntry; 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class WebhookIdContainerResponse extends Response { 12 | 13 | 14 | @Description(value = "Created or updated webhook id description") 15 | WebhookIdResponseEntry results; 16 | } 17 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/WebhookListAllResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.util.List; 5 | 6 | import com.sparkpost.model.Webhook; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = true) 14 | public class WebhookListAllResponse extends Response { 15 | 16 | @Description(value = "An array of Webhook data", sample = {""}) 17 | List results; 18 | } 19 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TemplateListResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.util.List; 5 | 6 | import com.sparkpost.model.TemplateItem; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = true) 14 | public class TemplateListResponse extends Response { 15 | 16 | @Description(value = "List of TemplateItems", sample = {""}) 17 | private List results; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/MetricsEngagementFields.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | public class MetricsEngagementFields { 5 | 6 | public static final String ALL_FIELDS = "count_clicked,count_raw_clicked"; 7 | 8 | public static final String[] ALL_FIELDS_ARRAY = new String[] {"link_name", "count_clicked", "count_raw_clicked"}; 9 | 10 | public static final String LINK_NAME = "link_name"; 11 | public static final String COUNT_CLICKED = "count_clicked"; 12 | public static final String COUNT_ROW_CLICKED = "count_raw_clicked"; 13 | } 14 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/RecipientListsListAllResponse.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.responses; 2 | 3 | import java.util.List; 4 | 5 | import com.sparkpost.model.RecipientList; 6 | import com.yepher.jsondoc.annotations.Description; 7 | 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | @Data 12 | @EqualsAndHashCode(callSuper = true) 13 | public class RecipientListsListAllResponse extends Response { 14 | 15 | @Description(value = "List of RecipientList", sample = {""}) 16 | private List results; 17 | } 18 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TransmissionListResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.util.List; 5 | 6 | import com.sparkpost.model.TransmissionBase; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = true) 14 | public class TransmissionListResponse extends Response { 15 | 16 | @Description(value = "List of TransmissionsBase items", sample = {""}) 17 | private List results; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/Match.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class Match extends Base { 12 | 13 | @Description(value = "Inbound messaging protocol associated with this webhook", sample = {"SMTP"}) 14 | private String protocol; 15 | 16 | @Description(value = "Inbound domain associated with this webhook", sample = {"example.com"}) 17 | private String domain; 18 | } 19 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/WebhookDescribeResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.sparkpost.model.Webhook; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class WebhookDescribeResponse extends Response { 13 | 14 | @Description(value = "Describes status of the webhook") 15 | private Boolean active; 16 | 17 | @Description(value = "", sample = "") 18 | private Webhook results; 19 | } 20 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/MetricsRejectFields.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | public class MetricsRejectFields { 5 | 6 | public static final String[] ALL_FIELDS_ARRAY = new String[] {"count_rejected", "rejection_category_name", "rejection_category_id", "reason"}; 7 | 8 | public static final String COUNT_REJECTED = "count_rejected"; 9 | public static final String REJECTION_CATEGORY_NAME = "rejection_category_name"; 10 | public static final String REJECTION_CATEGORY_ID = "rejection_category_id"; 11 | public static final String REASON = "reason"; 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2014 Message Systems, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"). 4 | You may not use this software except in compliance with the License. 5 | 6 | A copy of the License is located at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0.html 9 | 10 | or in the "license" file accompanying this software. This file is 11 | distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 12 | ANY KIND, either express or implied. See the License for the specific 13 | language governing permissions and limitations under the License. 14 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /libs/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | com.sparkpost 6 | sparkpost 7 | 0.27 8 | 9 | 4.0.0 10 | libs 11 | pom 12 | SparkPost Library 13 | /libs/ 14 | 15 | sparkpost-lib 16 | 17 | 18 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/DomainListResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | @Data 12 | @EqualsAndHashCode(callSuper = true) 13 | public class DomainListResponse extends Response { 14 | 15 | Map> results; 16 | 17 | public List getDomainList() { 18 | if (this.results == null) { 19 | return new ArrayList(); 20 | } 21 | return this.results.get("domains"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/CampaignListResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | @Data 12 | @EqualsAndHashCode(callSuper = true) 13 | public class CampaignListResponse extends Response { 14 | 15 | Map> results; 16 | 17 | public List getCampaignList() { 18 | if (this.results == null) { 19 | return new ArrayList(); 20 | } 21 | return this.results.get("campaigns"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /findbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/.fbExcludeFilterFile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/.fbExcludeFilterFile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/.fbExcludeFilterFile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tools/bin/buildBundles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BIN_DIR=`dirname "$0"` 4 | cd $BIN_DIR/../.. 5 | 6 | BASE_DIR=`pwd` 7 | 8 | echo "Base Dir: " $BASE_DIR 9 | 10 | # Bundle SparkPost Lib 11 | 12 | cd $BASE_DIR/libs/sparkpost-lib/target 13 | gpg --verify sparkpost-*.pom.asc sparkpost-*.pom 14 | 15 | jar -cvf bundle.jar sparkpost-lib-*-javadoc.jar sparkpost-lib-*-javadoc.jar.asc sparkpost-lib-*-sources.jar sparkpost-lib-*-sources.jar.asc sparkpost-lib-*.jar sparkpost-lib-*.jar.asc sparkpost-lib-*.pom sparkpost-lib-*.pom.asc 16 | 17 | # Bundle base libs 18 | cd $BASE_DIR/libs/target 19 | jar -cvf bundle.jar * 20 | 21 | 22 | # Bundle target 23 | cd $BASE_DIR/target 24 | jar -cvf bundle.jar * 25 | 26 | 27 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/.fbExcludeFilterFile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/ServerErrorResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.sparkpost.model.Base; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class ServerErrorResponse extends Base { 13 | 14 | @Description(value = "Error message from server", sample = {""}) 15 | private String message; 16 | 17 | @Description(value = "Error descrption from server", sample = {""}) 18 | private String description; 19 | 20 | @Description(value = "Error code from server", sample = {""}) 21 | private String code; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TemplateCreateResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class TemplateCreateResponse extends Response { 12 | 13 | @Data 14 | @EqualsAndHashCode 15 | public static final class CreateResult { 16 | 17 | @Description(value = "The id of the template that was created", sample = {"some-template-id"}) 18 | private String id; 19 | } 20 | 21 | @Description(value = "A Create template result", sample = {""}) 22 | private CreateResult results; 23 | } 24 | -------------------------------------------------------------------------------- /apps/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.sparkpost 5 | sparkpost 6 | 0.27 7 | 8 | 4.0.0 9 | apps 10 | pom 11 | SparkPost Examples 12 | /apps/ 13 | 14 | sparkpost-samples-app 15 | sparkpost-documentor-app 16 | sparkpost-javamail-app 17 | 18 | 19 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostIllegalServerResponseException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.exception; 3 | 4 | public class SparkPostIllegalServerResponseException extends SparkPostException { 5 | 6 | private static final long serialVersionUID = -1392320013310556792L; 7 | 8 | public SparkPostIllegalServerResponseException() { 9 | } 10 | 11 | public SparkPostIllegalServerResponseException(String message) { 12 | super(message); 13 | } 14 | 15 | public SparkPostIllegalServerResponseException(Throwable cause) { 16 | super(cause); 17 | } 18 | 19 | public SparkPostIllegalServerResponseException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/MetricLinkResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * child endpoints that contain aggregate data, which can be used as "group by" qualifiers. 11 | */ 12 | @Data 13 | @EqualsAndHashCode 14 | public class MetricLinkResponse { 15 | 16 | @Description(value = "endpoint reference", sample = {"/api/v1/metrics/deliverability"}) 17 | private String href; 18 | 19 | @Description(value = "", sample = {"deliverability"}) 20 | private String rel; 21 | 22 | @Description(value = "", sample = {"GET, POST, PUT, DELETE"}) 23 | private String method; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/VerifyResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * The verify resource validates the specified verification field types. 11 | * Including the fields "dkim_verify" and "spf_verify" in the request initiates 12 | * a check against the associated DNS record type for the specified sending 13 | * domain. The domain's "status" object is returned on success. 14 | */ 15 | @Data 16 | @EqualsAndHashCode(callSuper = true) 17 | public class VerifyResponse extends Base { 18 | 19 | @Description(value = "DKIM results", sample = {"DKIMResult Dictionary"}) 20 | private DKIMResults results; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/TemplateSubstitutionData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | import com.yepher.jsondoc.annotations.Description; 9 | 10 | import lombok.Data; 11 | import lombok.EqualsAndHashCode; 12 | 13 | /** 14 | * DTO for storing substitution data (list of key=value). 15 | */ 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class TemplateSubstitutionData extends Base { 19 | 20 | @Description(value = "Data the will be substituted into the template", sample = {"Dictionary of substitution data"}) 21 | @SerializedName("substitution_data") 22 | private Map substitutionData = new HashMap(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/SparkPost.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost; 3 | 4 | import com.sparkpost.exception.SparkPostException; 5 | import com.sparkpost.transport.IRestConnection; 6 | 7 | public class SparkPost { 8 | 9 | public static void main(String[] args) throws SparkPostException { 10 | String API_KEY = "YOUR API KEY HERE!!!"; 11 | 12 | // To use the SparkPost EU use IRestConnection.SPC_EU_ENDPOINT instead of the SPC_US_ENDPOINT 13 | Client client = new Client(API_KEY, IRestConnection.SPC_EU_ENDPOINT); 14 | 15 | client.sendMessage( 16 | "you@yourdomain.com", 17 | "to@sparkpost.com", 18 | "The subject of the message", 19 | "The text part of the email", 20 | "The HTML part of the email"); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/src/test/java/com/sparkpost/sample/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.sample; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TransmissionCreateItem.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class TransmissionCreateItem extends Response { 13 | 14 | @Description(value = "Number of recipients that were rejected", sample = {""}) 15 | @SerializedName("total_rejected_recipients") 16 | private int totalRejectedRecipients; 17 | 18 | @Description(value = "Number of recipients accepted", sample = {""}) 19 | @SerializedName("total_accepted_recipients") 20 | private int totalAcceptedRecipients; 21 | 22 | @Description(value = "Unique ID of transmission", sample = {""}) 23 | private String id; 24 | } 25 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/DeliverabiltyMetricsResponse.java: -------------------------------------------------------------------------------- 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.yepher.jsondoc.annotations.Description; 9 | 10 | import lombok.Data; 11 | import lombok.EqualsAndHashCode; 12 | 13 | @Data 14 | @EqualsAndHashCode(callSuper = true) 15 | public class DeliverabiltyMetricsResponse extends Response { 16 | 17 | @Description(value = "results", sample = {"\"results\": [ {\"count_injected\": 633,...}]"}) 18 | @SerializedName("results") 19 | private List> results; 20 | 21 | @Description(value = "links", sample = {"{ \"href\": \"/api/v1/metrics/deliverability\", \"rel\": \"deliverability\", \"method\": \"GET\" }"}) 22 | @SerializedName("links") 23 | private List links; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/config.properties.example: -------------------------------------------------------------------------------- 1 | ## 2 | # The URL to use for the SparkPost API If empty default will be used 3 | ## 4 | #SPARKPOST_BASE_URL=https://api.sparkpost.com/api/v1/ 5 | 6 | 7 | ## 8 | # This your API key for SparkPost 9 | ## 10 | SPARKPOST_API_KEY=YOUR SPARKPOST API KEY 11 | 12 | 13 | ## 14 | # Username and password for SparkPost API 15 | # You should use API Key instead if possible 16 | ## 17 | #USERNAME= 18 | #PASSWORD= 19 | 20 | 21 | ## 22 | # The subject that will be put into templates 23 | # When messages are sent 24 | ## 25 | SPARKPOST_SUBJECT=This is a sample subject 26 | 27 | 28 | ## 29 | # 30 | ## 31 | SPARKPOST_SENDER_EMAIL=noreply@example.com 32 | 33 | 34 | ## 35 | # 36 | ## 37 | SPARKPOST_FROM=source@example.com 38 | 39 | 40 | ## 41 | # 42 | # SPARKPOST_RECIPIENTS 43 | # A comma delimited list of email addresses to send to 44 | # 45 | ## 46 | SPARKPOST_RECIPIENTS=test1@yepher.com, test2@ypeher.com 47 | 48 | 49 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/StoredRecipientList.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | * This is used when specifying a stored recipient list in the transmission. 12 | * Note that this attribute should not be present when specifying recipients 13 | * inline. 14 | */ 15 | @Data 16 | @EqualsAndHashCode(callSuper = true) 17 | public class StoredRecipientList extends Base { 18 | 19 | /** 20 | * Identifier of the stored recipient list to use 21 | * Specify this field when using a stored recipient list. 22 | */ 23 | @Description(value = "Identifier of the stored recipient list to use. Specify this field when using a stored recipient list.", sample = {"AbC123"}) 24 | @SerializedName("list_id") 25 | private String listId = null; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TemplatePreviewResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.sparkpost.model.AddressAttributes; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class TemplatePreviewResponse extends Response { 13 | 14 | @Data 15 | public static final class TemplatePreviewData { 16 | 17 | @Description(value = "", sample = {""}) 18 | private String subject; 19 | 20 | @Description(value = "", sample = {""}) 21 | private AddressAttributes from; 22 | 23 | @Description(value = "", sample = {""}) 24 | private String html; 25 | 26 | @Description(value = "", sample = {""}) 27 | private String text; 28 | } 29 | 30 | @Description(value = "", sample = {""}) 31 | private TemplatePreviewData results; 32 | } 33 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/VerifyAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | * DTO for storing a Sending Domain verification request. 12 | * 13 | * @author grava 14 | */ 15 | @Data 16 | @EqualsAndHashCode(callSuper = true) 17 | public class VerifyAttributes extends Base { 18 | 19 | /** 20 | * Request verification of DKIM record 21 | */ 22 | @Description(value = "Request verification of DKIM record", sample = {"true"}) 23 | @SerializedName("dkim_verify") 24 | private Boolean dkimVerify = null; 25 | 26 | /** 27 | * Request verification of SPF record 28 | */ 29 | @Description(value = "Request verification of SPF record", sample = {"true"}) 30 | @SerializedName("spf_verify") 31 | private Boolean spfVerify = null; 32 | } 33 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostErrorServerResponseException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.exception; 3 | 4 | import com.sparkpost.model.responses.ServerErrorResponses; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Getter; 8 | 9 | public class SparkPostErrorServerResponseException extends SparkPostException { 10 | 11 | private static final long serialVersionUID = -7196264905004169555L; 12 | 13 | @Getter 14 | @Description(value = "HTTP Response Code generated by request", sample = {"426"}) 15 | private int responseCode = -1; 16 | 17 | public SparkPostErrorServerResponseException(String message, int responseCode) { 18 | super(message); 19 | this.responseCode = responseCode; 20 | } 21 | 22 | public SparkPostErrorServerResponseException(String message, int responseCode, ServerErrorResponses errorResponses) { 23 | super(message, errorResponses); 24 | this.responseCode = responseCode; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/config.properties.example: -------------------------------------------------------------------------------- 1 | ## 2 | # The URL to use for the SparkPost API If empty default will be used 3 | ## 4 | #SPARKPOST_BASE_URL=https://api.sparkpost.com/api/v1/ 5 | 6 | 7 | ## 8 | # This your API key for SparkPost 9 | ## 10 | SPARKPOST_API_KEY=YOUR SPARKPOST API KEY 11 | 12 | 13 | ## 14 | # Username and password for SparkPost API 15 | # You should use API Key instead if possible 16 | ## 17 | #USERNAME= 18 | #PASSWORD= 19 | 20 | 21 | ## 22 | # The subject that will be put into templates 23 | # When messages are sent 24 | ## 25 | SPARKPOST_SUBJECT=This is a sample subject 26 | 27 | 28 | ## 29 | # 30 | ## 31 | SPARKPOST_SENDER_EMAIL=noreply@example.com 32 | 33 | 34 | ## 35 | # 36 | ## 37 | SPARKPOST_FROM=from_address@example.com 38 | 39 | 40 | ## 41 | # 42 | # SPARKPOST_RECIPIENTS 43 | # A comma delimited list of email addresses to send to 44 | # 45 | # Example: recipient_one@example.com, recipient_two@example.com 46 | ## 47 | SPARKPOST_RECIPIENTS=recipient_one@example.com, recipient_two@example.com 48 | 49 | 50 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/ListAllSendingDomiansResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.util.List; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = true) 14 | public class ListAllSendingDomiansResponse extends Response { 15 | 16 | @Data 17 | @EqualsAndHashCode 18 | public static final class Domain { 19 | 20 | @Description(value = "Name of the sending domain", sample = {"example.com"}) 21 | String domain; 22 | 23 | @Description(value = "Associated tracking domain", sample = {"click.example.com"}) 24 | @SerializedName("tracking_domain") 25 | String trackingDomain; 26 | } 27 | 28 | @Description(value = "List of Sending Domains", sample = {"Array of sending domains"}) 29 | @SerializedName("results") 30 | List domains; 31 | } 32 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/AuthCredentials.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class AuthCredentials extends Base { 12 | 13 | @Description(value = "Basic Auth Username. Used for 'basic' authorization flow.") 14 | private String username; 15 | 16 | @Description(value = "Basic Auth Password. Used for 'basic' authorization flow.") 17 | private String password; 18 | 19 | @Description(value = "OAuth2 access token generated by SparkPost. Returned in case of 'oauth2' authorization flow.") 20 | @SerializedName("access_token") 21 | private String accessToken; 22 | 23 | @Description(value = "The lifetime of the access_token in seconds. Returned in case of 'oauth2' authorization flow.") 24 | @SerializedName("expires_in") 25 | private Integer expiresIn; 26 | } 27 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/TemplateItem.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class TemplateItem extends Base { 13 | 14 | @Description(value = "The name of the template", sample = {"Template Name"}) 15 | private String name; 16 | 17 | @Description(value = "The ID of the template", sample = {"AbC123"}) 18 | private String id; 19 | 20 | @Description(value = "Format YYYY-MM-DDTHH:MM:SS+-HH:MM or \"now\"..", sample = {"2015-02-11T08:00:00-04:00"}) 21 | @SerializedName("last_update_time") 22 | private String lastUpdateTime; 23 | 24 | @Description(value = "Template Description", sample = {""}) 25 | private String description; 26 | 27 | @Description(value = "true if template is published otherwise it is a draft", sample = {"true"}) 28 | private Boolean published; 29 | } 30 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/AuthRequestDetails.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class AuthRequestDetails extends Base { 12 | 13 | @Description(value = "This is the URL SparkPost will request tokens from.", sample = {"https://oauth.myurl.com/tokens"}) 14 | private String url; 15 | 16 | @Description(value = "OAuth 2.0 parameters that your target URL uses") 17 | private AuthRequestClientDetails body; 18 | 19 | 20 | @Data 21 | @EqualsAndHashCode(callSuper = true) 22 | public static class AuthRequestClientDetails extends Base { 23 | 24 | @Description(value = "OAuth 2.0 Client ID") 25 | @SerializedName("client_id") 26 | private String clientId; 27 | 28 | @Description(value = "OAuth 2.0 Client Secret") 29 | @SerializedName("client_secret") 30 | private String clientSecret; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostAuthorizationFailedException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.exception; 3 | 4 | import com.sparkpost.model.responses.ServerErrorResponses; 5 | 6 | public class SparkPostAuthorizationFailedException extends SparkPostException { 7 | 8 | private static final long serialVersionUID = 3695537080454452130L; 9 | 10 | private static final String MESSAGE = "Authorization failed. Check your API key."; 11 | 12 | private final String serverMessage; 13 | 14 | public SparkPostAuthorizationFailedException() { 15 | super(MESSAGE); 16 | this.serverMessage = MESSAGE; 17 | } 18 | 19 | public SparkPostAuthorizationFailedException(String serverMessage) { 20 | super(MESSAGE); 21 | this.serverMessage = serverMessage; 22 | } 23 | 24 | public SparkPostAuthorizationFailedException(String serverMessage, ServerErrorResponses errorResponses) { 25 | super(MESSAGE, errorResponses); 26 | this.serverMessage = serverMessage; 27 | } 28 | 29 | public String getServerMessage() { 30 | return this.serverMessage; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostAccessForbiddenException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.exception; 3 | 4 | import com.sparkpost.model.responses.ServerErrorResponses; 5 | 6 | public class SparkPostAccessForbiddenException extends SparkPostException { 7 | 8 | private static final long serialVersionUID = 4127644290615861545L; 9 | 10 | private static final String MESSAGE = "API key does not have the required permission to perform this action."; 11 | 12 | private final String serverMessage; 13 | 14 | public SparkPostAccessForbiddenException() { 15 | super(MESSAGE); 16 | this.serverMessage = MESSAGE; 17 | } 18 | 19 | public SparkPostAccessForbiddenException(String serverMessage) { 20 | super(MESSAGE); 21 | this.serverMessage = serverMessage; 22 | } 23 | 24 | public SparkPostAccessForbiddenException(String serverMessage, ServerErrorResponses errorResponses) { 25 | super(MESSAGE, errorResponses); 26 | this.serverMessage = serverMessage; 27 | } 28 | 29 | public String getServerMessage() { 30 | return this.serverMessage; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/TransmissionWithRecipientList.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | * DTO for a transmission using a recipient list id (a recipient list stored at 12 | * the server) 13 | * 14 | * @author grava 15 | */ 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class TransmissionWithRecipientList extends TransmissionBase { 19 | 20 | /** 21 | * Specify a stored recipient list or specify recipients inline. When using 22 | * a stored recipient list, specify the "list_id" as described in Using a 23 | * Stored Recipient List. Otherwise, provide the recipients inline using the 24 | * fields described in the Recipient List API documentation for Recipient 25 | * Attributes. 26 | */ 27 | @Description(value = "Transmission using a recipient list id (a recipient list stored at the server)", sample = {""}) 28 | @SerializedName("recipients") 29 | private StoredRecipientList recipientList = null; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/Webhook.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = true) 11 | public class Webhook extends WebhookDescription { 12 | 13 | @Description(value = "Webhook id") 14 | private String id; 15 | 16 | @Description(value = "Type of authentication to be used during POST requests to target.", sample = {"none", "basic", "oauth2"}) 17 | @SerializedName("auth_type") 18 | private String authType; 19 | 20 | @Description(value = "When using auth_type == 'oauth2', auth_request_details must be set by the user. " 21 | + "Additionally, auth_credentials is set by the system and cannot be configured by the user") 22 | @SerializedName("auth_request_details") 23 | private AuthRequestDetails authRequestDetails; 24 | 25 | @Description(value = "When using auth_type == 'basic', auth_credentials must be set by the user") 26 | @SerializedName("auth_credentials") 27 | private AuthCredentials authCredentials; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/config.properties.example: -------------------------------------------------------------------------------- 1 | ## 2 | # The URL to use for the SparkPost API If empty default will be used 3 | ## 4 | #SPARKPOST_BASE_URL=https://api.sparkpost.com/api/v1/ 5 | 6 | 7 | ## 8 | # This your API key for SparkPost 9 | ## 10 | SPARKPOST_API_KEY=YOUR SPARKPOST API KEY 11 | 12 | 13 | ## 14 | # Username and password for SparkPost API 15 | # You should use API Key instead if possible 16 | ## 17 | #USERNAME= 18 | #PASSWORD= 19 | 20 | 21 | ## 22 | # The subject that will be put into templates 23 | # When messages are sent 24 | ## 25 | SPARKPOST_SUBJECT=This is a sample subject 26 | 27 | 28 | ## 29 | # 30 | ## 31 | SPARKPOST_SENDER_EMAIL=noreply@example.com 32 | 33 | 34 | ## 35 | # 36 | ## 37 | SPARKPOST_FROM=from_address@example.com 38 | 39 | 40 | ## 41 | # 42 | # SPARKPOST_RECIPIENTS 43 | # A comma delimited list of email addresses to send to 44 | # 45 | # Example: recipient_one@example.com, recipient_two@example.com 46 | ## 47 | SPARKPOST_RECIPIENTS=recipient_one@example.com, recipient_two@example.com 48 | 49 | SPARKPOST_CC_RECIPIENTS=cc_recipient_one@example.com, cc_recipient_two@example.com 50 | 51 | SPARKPOST_BCC_RECIPIENTS=bcc_recipient_one@example.com, bcc_recipient_two@example.com 52 | 53 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/TransmissionWithRecipientArray.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import java.util.List; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | /** 13 | * DTO for a transmission using an array of recipients. 14 | * 15 | * @author grava 16 | */ 17 | @Data 18 | @EqualsAndHashCode(callSuper = true) 19 | public class TransmissionWithRecipientArray extends TransmissionBase { 20 | 21 | /** 22 | * Inline recipient objects or object containing stored recipient list ID 23 | * Specify a stored recipient list or specify recipients inline. When using 24 | * a stored recipient list, specify the "list_id" as described in Using a 25 | * Stored Recipient List. Otherwise, provide the recipients inline using the 26 | * fields described in the Recipient List API documentation for Recipient 27 | * Attributes. 28 | */ 29 | @Description(value = "Inline recipient objects or object containing stored recipient list ID", sample = {""}) 30 | @SerializedName("recipients") 31 | private List recipientArray = null; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/resources/BaseResourceTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.resources; 3 | 4 | import org.junit.Assert; 5 | 6 | import com.sparkpost.testhelpers.StubRestConnection; 7 | 8 | public class BaseResourceTest { 9 | 10 | protected void verifyWasGet(StubRestConnection conn) { 11 | Assert.assertTrue(conn.wasGet()); 12 | Assert.assertFalse(conn.wasDelete()); 13 | Assert.assertFalse(conn.wasPut()); 14 | Assert.assertFalse(conn.wasPost()); 15 | } 16 | 17 | protected void verifyWasPut(StubRestConnection conn) { 18 | Assert.assertFalse(conn.wasGet()); 19 | Assert.assertFalse(conn.wasDelete()); 20 | Assert.assertTrue(conn.wasPut()); 21 | Assert.assertFalse(conn.wasPost()); 22 | } 23 | 24 | protected void verifyWasPost(StubRestConnection conn) { 25 | Assert.assertFalse(conn.wasGet()); 26 | Assert.assertFalse(conn.wasDelete()); 27 | Assert.assertFalse(conn.wasPut()); 28 | Assert.assertTrue(conn.wasPost()); 29 | } 30 | 31 | protected void verifyWasDelete(StubRestConnection conn) { 32 | Assert.assertFalse(conn.wasGet()); 33 | Assert.assertTrue(conn.wasDelete()); 34 | Assert.assertFalse(conn.wasPut()); 35 | Assert.assertFalse(conn.wasPost()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/StoredTemplate.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | * DTO for storing a stored template. 12 | */ 13 | @Data 14 | @EqualsAndHashCode(callSuper = true) 15 | public class StoredTemplate extends Base { 16 | 17 | /** 18 | * ID of the stored template to use 19 | * Specify this field when using a stored template. Maximum length -- 64 20 | * bytes 21 | */ 22 | @Description(value = "ID of the stored template to use. Specify this field when using a stored template. Maximum length -- 64 bytes", sample = {"AbC123"}) 23 | @SerializedName("template_id") 24 | private String templateId; 25 | 26 | /** 27 | * Whether or not to use a draft template 28 | * If this field is set to true and no draft template exists, the 29 | * transmission will fail. 30 | */ 31 | @Description( 32 | value = "Whether or not to use a draft template. If this field is set to true and no draft template exists, the transmission will fail.", 33 | sample = {"false"}) 34 | @SerializedName("use_draft_template") 35 | private Boolean useDraftTemplate; 36 | } 37 | -------------------------------------------------------------------------------- /DesignDecisions.md: -------------------------------------------------------------------------------- 1 | # Design Decisions 2 | 3 | This is a place to track some design decisions that maybe of interest to those in the community and may not be readily apparent at first glance. 4 | 5 | ## Why Lombok 6 | 7 | [Lombok](https://projectlombok.org/) makes your code much easier to read and maintain. It is really easy to get started and the resulting library does not have a dependency on Lombok. 8 | 9 | An important question by those in the "know" wonder why Lombok instead of [AutoValue](https://github.com/google/auto). AutoValue is nice and they have a good (albeit biases) [comparison of alternative solutions](https://docs.google.com/presentation/d/14u_h-lMn7f1rXE1nDiLX0azS3IkgjGl5uxp5jGJ75RE/edit). Both Lombok and AutoValue accomplish similar goals. In my opinion AutoValues is non-starter because if you rearrange member variables of your class the interface is broken. Yes, this would get caught in unit testing but the fact your have to refactor all your usages of that class just because you want to rearrange member variable is bad. You want to encourage and reduce friction to refactoring code. The whole purpose for Lombok and AutoValue is to make the developers life much easier and reduce programming errors. AutoValue breaks at least one of those goals. Since this project is focused on a library breaking the interface just by rearranging member variable is a problem that we can not absorb into this project. -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/FileAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * DTO for attachments and inline images 11 | */ 12 | @Data 13 | @EqualsAndHashCode(callSuper = true) 14 | public class FileAttributes extends Base { 15 | 16 | public FileAttributes() { 17 | 18 | } 19 | 20 | /** 21 | * Valid email address 22 | */ 23 | @Description( 24 | value = "The MIME type of the file. The value will apply \"as-is\" to the \"Content-Type\" header of the generated MIME part for the file.", 25 | sample = {"image/jpeg"}) 26 | private String type; 27 | 28 | /** 29 | * User-friendly name for the email address 30 | */ 31 | @Description(value = "The name of the file.", sample = {"rainbow.jpg"}) 32 | private String name; 33 | 34 | /** 35 | * Email address to display in the "To" header instead of address.email (for BCC) 36 | */ 37 | @Description( 38 | value = "he content of the file as a Base64 encoded string. The string should not contain \\r\\n line breaks. The SparkPost systems will add line breaks as necessary to ensure the Base64 encoded lines contain no more than 76 characters each.", 39 | sample = {""}) 40 | private String data; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/transport/RestConnectionTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.transport; 3 | 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class RestConnectionTest { 8 | 9 | @Test 10 | public void constructWithNullBaseURL() throws Exception { 11 | RestConnection restConnection = new RestConnection(null, null); 12 | Assert.assertEquals(IRestConnection.defaultApiEndpoint, restConnection.getBaseUrl()); 13 | } 14 | 15 | @Test 16 | public void constructWithEmptyBaseURL() throws Exception { 17 | RestConnection restConnection = new RestConnection(null, ""); 18 | Assert.assertEquals(IRestConnection.defaultApiEndpoint, restConnection.getBaseUrl()); 19 | } 20 | 21 | @Test(expected = IllegalStateException.class) 22 | public void constructWithInvalidBaseURL() throws Exception { 23 | RestConnection restConnection = new RestConnection(null, "/"); 24 | Assert.assertEquals(IRestConnection.defaultApiEndpoint, restConnection.getBaseUrl()); 25 | } 26 | 27 | @Test 28 | public void constructWithValidBaseURL() throws Exception { 29 | RestConnection restConnection = new RestConnection(null, "http://foo/bar"); 30 | Assert.assertNotEquals(IRestConnection.defaultApiEndpoint, restConnection.getBaseUrl()); 31 | Assert.assertEquals("http://foo/bar", restConnection.getBaseUrl()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /apps/sparkpost-javamail-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.sparkpost 8 | apps 9 | 0.27 10 | 11 | com.sparkpost.sample 12 | sparkpost-javamail-app 13 | 1.0-SNAPSHOT 14 | sparkpost-javamail-app 15 | http://maven.apache.org 16 | 17 | 18 | com.sparkpost 19 | sparkpost-lib 20 | 21 | 22 | javax.mail 23 | javax.mail-api 24 | 1.5.5 25 | 26 | 27 | com.sun.mail 28 | javax.mail 29 | 1.5.3 30 | 31 | 32 | commons-io 33 | commons-io 34 | 35 | 36 | 37 | 38 | junit 39 | junit 40 | test 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/DNSAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class DNSAttributes extends Base { 13 | 14 | /** 15 | * DNS DKIM record for the registered Sending Domain 16 | */ 17 | @Description(value = "DNS DKIM record for the registered Sending Domain", sample = {""}) 18 | @SerializedName("dkim_record") 19 | private String dkimRecord; 20 | 21 | /** 22 | * DNS SPF record for the registered Sending Domain 23 | */ 24 | @Description(value = "DNS SPF record for the registered Sending Domain", sample = {""}) 25 | @SerializedName("spf_record") 26 | private String spfRecord; 27 | 28 | /** 29 | * Error message describing reason for DKIM verification failure 30 | */ 31 | @Description(value = "Error message describing reason for DKIM verification failure", sample = {""}) 32 | @SerializedName("dkim_error") 33 | private String dkimError; 34 | 35 | /** 36 | * Error message describing reason for SPF verification failure 37 | */ 38 | @Description(value = "Error message describing reason for SPF verification failure", sample = {""}) 39 | @SerializedName("spf_error") 40 | private String spfError; 41 | } 42 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/SupressionListResponse.java: -------------------------------------------------------------------------------- 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 results; 23 | 24 | @Description(value = "links", sample = {""}) 25 | @SerializedName("links") 26 | private Map 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 | } 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Application 3 | 4 | config.properties 5 | output.eml 6 | src/main/resources/sparkpostsdk.properties 7 | apps/sparkpost-documentor-app/protocol.md 8 | 9 | 10 | # Java 11 | 12 | *.class 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.ear 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # Maven 26 | 27 | target/ 28 | pom.xml.tag 29 | pom.xml.releaseBackup 30 | pom.xml.versionsBackup 31 | pom.xml.next 32 | release.properties 33 | dependency-reduced-pom.xml 34 | buildNumber.properties 35 | .mvn/timing.properties 36 | 37 | # Eclipse 38 | 39 | *.pydevproject 40 | .metadata 41 | .gradle 42 | bin/ 43 | !tools/bin 44 | tmp/ 45 | *.tmp 46 | *.bak 47 | *.swp 48 | *~.nib 49 | local.properties 50 | .loadpath 51 | 52 | # Eclipse Core 53 | .project 54 | 55 | # External tool builders 56 | .externalToolBuilders/ 57 | 58 | # Locally stored "Eclipse launch configurations" 59 | *.launch 60 | 61 | # CDT-specific 62 | .cproject 63 | 64 | # JDT-specific (Eclipse Java Development Tools) 65 | .classpath 66 | 67 | # Java annotation processor (APT) 68 | .factorypath 69 | 70 | # PDT-specific 71 | .buildpath 72 | 73 | # sbteclipse plugin 74 | .target 75 | 76 | # TeXlipse plugin 77 | .texlipse 78 | 79 | 80 | # SVN 81 | 82 | .svn 83 | 84 | 85 | # Keep Code Style Settings 86 | .settings/ 87 | !.settings/org.eclipse.jdt.ui.prefs 88 | !.settings/org.eclipse.jdt.core.prefs 89 | 90 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/MetricsBounceFields.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | public class MetricsBounceFields { 5 | 6 | /** 7 | * These are all the fields that can be used in a request 8 | */ 9 | public static final String ALL_FIELDS = "count_bounce,count_inband_bounce,count_outofband_bounce"; 10 | 11 | /** 12 | * This is all the fields available in a response 13 | */ 14 | public static final String[] ALL_FIELDS_ARRAY = new String[] { 15 | "bounce_class_name", 16 | "bounce_class_description", 17 | "bounce_category_name", 18 | "classification_id", 19 | "count_bounce", 20 | "count_inband_bounce", 21 | "count_outofband_bounce", 22 | "domain", 23 | "reason"}; 24 | 25 | public static final String BOUNCE_CLASS_NAME = "bounce_class_name"; 26 | public static final String BOUNCE_CLASS_DESCRIPTION = "bounce_class_description"; 27 | public static final String BOUNCE_CATEGORY_NAME = "bounce_category_name"; 28 | public static final String CLASSIFICATION_ID = "classification_id"; 29 | public static final String COUNT_BOUNCE = "count_bounce"; 30 | public static final String COUNT_INBAND_BOUNCE = "count_inband_bounce"; 31 | public static final String COUNT_OUTOFBAND_BOUNCE = "count_outofband_bounce"; 32 | 33 | public static final String REASON = "reason"; 34 | 35 | public static final String DOMAIN = "domain"; 36 | } 37 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/AddressAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | * DTO for storing an address (email, name, header_to) 12 | */ 13 | @Data 14 | @EqualsAndHashCode(callSuper = true) 15 | public class AddressAttributes extends Base { 16 | 17 | public AddressAttributes() { 18 | 19 | } 20 | 21 | public AddressAttributes(String email) { 22 | this.email = email; 23 | } 24 | 25 | public AddressAttributes(String email, String name, String headerTo) { 26 | this.email = email; 27 | this.name = name; 28 | this.headerTo = headerTo; 29 | } 30 | 31 | /** 32 | * Valid email address 33 | */ 34 | @Description(value = "Valid email address", sample = {"someone@example.com"}) 35 | private String email; 36 | 37 | /** 38 | * User-friendly name for the email address 39 | */ 40 | @Description(value = "User-friendly name for the email address", sample = {"John Doe"}) 41 | private String name; 42 | 43 | /** 44 | * Email address to display in the "To" header instead of address.email (for BCC) 45 | */ 46 | @Description(value = "Email address to display in the \"To\" header instead of address.email (for BCC)", sample = {"someone@example.com"}) 47 | @SerializedName("header_to") 48 | private String headerTo; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/SubaccountCreateResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class SubaccountCreateResponse extends Response { 13 | 14 | @Data 15 | @EqualsAndHashCode 16 | public static final class CreateResult { 17 | 18 | private String name; 19 | 20 | private String status; 21 | 22 | @SerializedName("compliance_status") 23 | private String complianceStatus; 24 | 25 | @SerializedName("ip_pool") 26 | private String ipPool; 27 | 28 | @Description(value = "The id of the subaccount that was created", sample = {"123"}) 29 | @SerializedName("subaccount_id") 30 | private Integer id; 31 | 32 | private String key; 33 | 34 | private String label; 35 | 36 | @SerializedName("short_key") 37 | private String shortKey; 38 | 39 | } 40 | 41 | @Description(value = "A Create subaccount result", sample = {""}) 42 | private CreateResult results; 43 | 44 | /* 45 | * { 46 | * "results": { 47 | * "subaccount_id": 888, 48 | * "key": "cf806c8c472562ab98ad5acac1d1b06cbd1fb438", 49 | * "label": "API Key for Sparkle Ponies Subaccount", 50 | * "short_key": "cf80" 51 | * } 52 | * } 53 | */ 54 | 55 | } 56 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/Base.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.Gson; 5 | import com.google.gson.GsonBuilder; 6 | 7 | /** 8 | * Base class for all DTOs. DO NOT USE DIRECTLY. This base class takes care of 9 | * the JSON serialization. 10 | */ 11 | public class Base { 12 | 13 | private static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; 14 | private static final GsonBuilder GSON_BUILDER = new GsonBuilder().setDateFormat(DATE_TIME_FORMAT); 15 | 16 | /** 17 | * Generate JSON for this request 18 | * 19 | * @return json of object 20 | */ 21 | public String toJson() { 22 | return toJson(true); 23 | } 24 | 25 | /** 26 | * @param prettyPrint 27 | * true to render json pretty printed 28 | * @return json of object 29 | */ 30 | public String toJson(boolean prettyPrint) { 31 | Gson gson; 32 | if (prettyPrint) { 33 | gson = GSON_BUILDER.setPrettyPrinting().create(); 34 | } else { 35 | gson = GSON_BUILDER.create(); 36 | } 37 | 38 | return gson.toJson(this); 39 | } 40 | 41 | /** 42 | * Generate JSON from this object for required type. 43 | * 44 | * @param tClass 45 | * - target Class. 46 | * @return json of object. 47 | */ 48 | @SuppressWarnings("rawtypes") 49 | public String toJson(Class tClass) { 50 | return GSON_BUILDER.setPrettyPrinting().create().toJson(this, tClass); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/WebhookDescription.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import java.util.List; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | /** 13 | * DTO for storing info about a webhook. 14 | * 15 | * @author grava 16 | */ 17 | @Data 18 | @EqualsAndHashCode(callSuper = true) 19 | public class WebhookDescription extends Base { 20 | 21 | @Description(value = "User-friendly name", sample = {"Inbound Customer Replies"}) 22 | private String name; 23 | 24 | @Description(value = "URL of the target to which to POST relay batches", sample = {"https://webhooks.customer.example/replies"}) 25 | private String target; 26 | 27 | @Deprecated 28 | @Description( 29 | value = "Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target", 30 | sample = {"5ebe2294ecd0e0f08eab7690d2a6ee69"}) 31 | @SerializedName("auth_token") 32 | private String authToken; 33 | 34 | @Description(value = "Array of events", sample = {""}) 35 | private List events; 36 | 37 | @Description( 38 | value = "Restrict which inbound messages will be relayed to the target", 39 | sample = {"\"match\": { \"protocol\": \"SMTP\", \"domain\": \"replies.customer.example\" }"}) 40 | private Match match; 41 | 42 | @Description(value = "Describes status of the webhook") 43 | private Boolean active; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.exception; 3 | 4 | import com.sparkpost.model.responses.ServerErrorResponses; 5 | 6 | public class SparkPostException extends Exception { 7 | 8 | private static final long serialVersionUID = 4017633480414265142L; 9 | 10 | private final ServerErrorResponses errorResponses; 11 | 12 | public SparkPostException() { 13 | this.errorResponses = null; 14 | } 15 | 16 | public SparkPostException(String message) { 17 | super(message); 18 | this.errorResponses = null; 19 | } 20 | 21 | public SparkPostException(String message, ServerErrorResponses errorResponses) { 22 | super(message); 23 | this.errorResponses = errorResponses; 24 | } 25 | 26 | public SparkPostException(Throwable cause) { 27 | super(cause); 28 | this.errorResponses = null; 29 | } 30 | 31 | public SparkPostException(Throwable cause, ServerErrorResponses errorResponses) { 32 | super(cause); 33 | this.errorResponses = errorResponses; 34 | } 35 | 36 | public SparkPostException(String message, Throwable cause) { 37 | super(message, cause); 38 | this.errorResponses = null; 39 | } 40 | 41 | public SparkPostException(String message, Throwable cause, ServerErrorResponses errorResponses) { 42 | super(message, cause); 43 | this.errorResponses = errorResponses; 44 | } 45 | 46 | public ServerErrorResponses getServerErrorResponses() { 47 | return this.errorResponses; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/MessageEventsResponse.java: -------------------------------------------------------------------------------- 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.yepher.jsondoc.annotations.Description; 9 | 10 | import lombok.Data; 11 | import lombok.EqualsAndHashCode; 12 | 13 | @Data 14 | @EqualsAndHashCode(callSuper = true) 15 | public class MessageEventsResponse extends Response { 16 | 17 | // {"results":[],"total_count":0,"links":[]} 18 | @Description(value = "results", sample = {"\"results\": [ {\"count_injected\": 633,...}]"}) 19 | @SerializedName("results") 20 | private List> results; 21 | 22 | @Description( 23 | value = "links", 24 | sample = { 25 | "{ \"next\": \"/api/v1/events/message?events=delivery&per_page=1000&cursor=WycyMDE4LTExLTA1VDIyOjQ1OjM5LjAwMFonLCAnc3BjLTM4MTQ1MjY3MjMyNTA2NTEwJ10=\" }"}) 26 | @SerializedName("links") 27 | private Map links; 28 | 29 | @Description(value = "total_count", sample = {"{ \"total_count\": 0 }"}) 30 | @SerializedName("total_count") 31 | private int totalCount; 32 | 33 | public boolean hasNext() { 34 | String next = nextPageUrl(); 35 | return next != null && nextPageUrl().length() > 0; 36 | } 37 | 38 | public String nextPageUrl() { 39 | if (this.links == null || this.links.isEmpty()) { 40 | return ""; 41 | } 42 | 43 | String value = this.links.get("next"); 44 | return value; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/ListAllWebhooksSample.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostException; 13 | import com.sparkpost.model.responses.WebhookListAllResponse; 14 | import com.sparkpost.resources.ResourceWebhooks; 15 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 16 | import com.sparkpost.transport.IRestConnection; 17 | import com.sparkpost.transport.RestConnection; 18 | 19 | /** 20 | * List all Webhooks stored in a SparkPost account 21 | */ 22 | public class ListAllWebhooksSample extends SparkPostBaseApp { 23 | 24 | static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 25 | 26 | private Client client; 27 | 28 | public static void main(String[] args) throws SparkPostException, IOException { 29 | Configurator.setRootLevel(Level.DEBUG); 30 | 31 | ListAllWebhooksSample sample = new ListAllWebhooksSample(); 32 | sample.runApp(); 33 | } 34 | 35 | private void runApp() throws SparkPostException, IOException { 36 | client = this.newConfiguredClient(); 37 | IRestConnection connection = new RestConnection(client, getEndPoint()); 38 | WebhookListAllResponse response = ResourceWebhooks.listAll(connection, "America/Chicago"); 39 | System.out.println("Webhooks: " + response); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/DKIM.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | * DKIM uses a pair of public and private keys to authenticate your emails. 12 | */ 13 | @Data 14 | @EqualsAndHashCode(callSuper = true) 15 | public class DKIM extends Base { 16 | 17 | /** 18 | * DKIM private key 19 | * The private key will be used to create the DKIM Signature. 20 | */ 21 | @Description(value = "The private key will be used to create the DKIM Signature.", sample = {""}) 22 | @SerializedName("private") 23 | private String privateKey; 24 | 25 | /** 26 | * DKIM public key 27 | * The public key will be retrieved from DNS of the sending domain. 28 | */ 29 | @Description(value = "The public key will be retrieved from DNS of the sending domain.", sample = {""}) 30 | @SerializedName("public") 31 | private String publicKey; 32 | 33 | /** 34 | * DomainKey selector 35 | * The DomainKey selector will be used to indicate the DKIM public key location. 36 | */ 37 | @Description(value = "The DomainKey selector will be used to indicate the DKIM public key location.", sample = {""}) 38 | private String selector; 39 | 40 | /** 41 | * Header fields to be included in the DKIM signature 42 | * Header fields are separated by a colon. Example: "from:to:subject:date" 43 | */ 44 | @Description(value = "Header fields are separated by a colon.", sample = {"from:to:subject:date"}) 45 | private String headers; 46 | } 47 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/SendingDomainTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class SendingDomainTest { 16 | 17 | private String SENDING_DOMAIN_JSON = "{\n" + " \"domain\": \"domain.com\",\n" + " \"status\": { },\n" + " \"dkim\": { }\n" + "}"; 18 | 19 | @BeforeClass 20 | public static void setUpClass() { 21 | Configurator.setRootLevel(Level.DEBUG); 22 | } 23 | 24 | @AfterClass 25 | public static void tearDownClass() { 26 | } 27 | 28 | @Before 29 | public void setUp() { 30 | } 31 | 32 | @After 33 | public void tearDown() { 34 | } 35 | 36 | /** 37 | * 38 | */ 39 | @Test 40 | public void testDecodeRecipientAttributes() { 41 | Gson gson = new Gson(); 42 | SendingDomain sendingDomain = gson.fromJson(this.SENDING_DOMAIN_JSON, SendingDomain.class); 43 | Assert.assertNotNull(sendingDomain); 44 | 45 | Assert.assertEquals(sendingDomain.getDomain(), "domain.com"); 46 | 47 | StatusAttributes status = sendingDomain.getStatus(); 48 | // Internal decoding of this data is tested in it's own tests 49 | Assert.assertNotNull(status); 50 | 51 | DKIM dkim = sendingDomain.getDkim(); 52 | // Internal decoding of this data is tested in it's own tests 53 | Assert.assertNotNull(dkim); 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/SuppressionList.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import java.util.List; 5 | 6 | import com.yepher.jsondoc.annotations.Description; 7 | 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | * A suppression list - or exclusion list, as it is sometimes called - stores a 13 | * recipient's opt-out preferences. It is a list of recipient email addresses to 14 | * which you do NOT want to send email. The Suppression List API is used to 15 | * manage your customer-specific exclusion list entries. An entry indicates 16 | * whether the recipient requested to receive one of the following: 17 | * - Transactional and non-transactional messages from a given customer 18 | * - Transactional messages only from a given customer 19 | * - Non-transactional messages only from a given customer 20 | * - No messages from a given customer 21 | * Transactional messages are single recipient messages that are used operationally, 22 | * e.g. to reset a password or confirm a purchase; while non-transactional messages 23 | * are used to run email campaigns where a list of recipients are targeted, e.g. advertising 24 | * a sales event. 25 | * In addition to the customer-specific exclusion list, Message Systems maintains a global 26 | * suppression list across all customers. 27 | */ 28 | @Data 29 | @EqualsAndHashCode(callSuper = true) 30 | public class SuppressionList extends Base { 31 | 32 | @Description( 33 | value = "A suppression list - or exclusion list, as it is sometimes called - stores a recipient's opt-out preferences.", 34 | sample = {"Array of SuppressionListEntrys"}) 35 | private List recipients = null; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/SendingDomain.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * Note: The Sending Domains API is available for SparkPost only. 11 | * A sending domain is a domain that is used to indicate who an email is from via the 12 | * "From:" header. Using a custom sending domain enables you to control what 13 | * recipients see as the From value in their email clients. DNS records can be 14 | * configured for a sending domain, which allows recipient mail servers to 15 | * authenticate your messages. The Sending Domains API provides the means to 16 | * create, list, retrieve, update, and verify a custom sending domain. 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = true) 20 | public class SendingDomain extends Base { 21 | 22 | /** 23 | * Name of the sending domain 24 | * The domain name will be used as the "From:" header address in the email. 25 | */ 26 | @Description( 27 | value = "Name of the sending domain. The domain name will be used as the \"From:\" header address in the email.", 28 | sample = {"from_address@example.com"}) 29 | private String domain; 30 | 31 | /** 32 | * Status details, including whether this domain's ownership has been verified 33 | */ 34 | @Description(value = "Status details, including whether this domain's ownership has been verified", sample = {""}) 35 | private StatusAttributes status; 36 | 37 | /** 38 | * DKIM key configuration 39 | * For a full description, see the DKIM Attributes. 40 | */ 41 | @Description(value = "DKIM key configuration. For a full description, see the DKIM Attributes.", sample = {""}) 42 | private DKIM dkim; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/StatusAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | @Data 11 | @EqualsAndHashCode(callSuper = true) 12 | public class StatusAttributes extends Base { 13 | 14 | /** 15 | * 16 | */ 17 | @Description(value = "True if ownership is verified", sample = {"true"}) 18 | @SerializedName("ownership_verified") 19 | private Boolean ownershipVerified; 20 | 21 | /** 22 | * 23 | */ 24 | @Description(value = "Current SPF Status. Valid values are \"unverified\", \"pending\", \"invalid\" or \"valid\".", sample = {"valid"}) 25 | @SerializedName("spf_status") 26 | private String spfStatus; 27 | 28 | /** 29 | * 30 | */ 31 | @Description(value = "DKIM Compliance status. Valid values are \"pending\", \"valid\", or \"blocked\".", sample = {"valid"}) 32 | @SerializedName("compliance_status") 33 | private String complianceStatus; 34 | 35 | /** 36 | * 37 | */ 38 | @Description(value = "DKIM status. Valid values are \"unverified\", \"pending\", \"invalid\" or \"valid\".", sample = {"valid"}) 39 | @SerializedName("dkim_status") 40 | private String dkimStatus; 41 | 42 | /** 43 | * 44 | */ 45 | @Description(value = "Abuse status. Valid values are \"unverified\", \"pending\", \"invalid\" or \"valid\".", sample = {"valid"}) 46 | @SerializedName("abuse_at_status") 47 | private String abuseAtStatus; 48 | 49 | /** 50 | * 51 | */ 52 | @Description(value = "Postmaster status. Valid values are \"unverified\", \"pending\", \"invalid\" or \"valid\".", sample = {"valid"}) 53 | @SerializedName("postmaster_at_status") 54 | private String postmasterAtStatus; 55 | } 56 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/error/samples/BadApiKeyErrorSample.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.error.samples; 3 | 4 | import java.io.IOException; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostAccessForbiddenException; 13 | import com.sparkpost.exception.SparkPostException; 14 | import com.sparkpost.resources.ResourceSendingDomains; 15 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 16 | import com.sparkpost.transport.IRestConnection; 17 | import com.sparkpost.transport.RestConnection; 18 | 19 | /** 20 | * Lists all Sending Domains 21 | */ 22 | public class BadApiKeyErrorSample extends SparkPostBaseApp { 23 | 24 | static final Logger logger = LogManager.getLogger(BadApiKeyErrorSample.class); 25 | 26 | private Client client; 27 | 28 | public static void main(String[] args) throws SparkPostException, IOException { 29 | Configurator.setRootLevel(Level.DEBUG); 30 | 31 | BadApiKeyErrorSample sample = new BadApiKeyErrorSample(); 32 | sample.runApp(); 33 | } 34 | 35 | private void runApp() throws SparkPostException, IOException { 36 | this.client = this.newConfiguredClient(); 37 | this.client.setAuthKey("This_is_a_bad_api_key"); 38 | IRestConnection connection = new RestConnection(this.client, getEndPoint()); 39 | try { 40 | ResourceSendingDomains.list(connection); 41 | 42 | throw new IllegalStateException("Error: Expected SparkPostAccessForbiddenException"); 43 | } catch (SparkPostAccessForbiddenException e) { 44 | System.out.println("GOOD: Sucecssfuly got a SparkPostAccessForbiddenException"); 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/ListAllSendingDomains.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostException; 13 | import com.sparkpost.model.responses.Response; 14 | import com.sparkpost.resources.ResourceSendingDomains; 15 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 16 | import com.sparkpost.transport.IRestConnection; 17 | import com.sparkpost.transport.RestConnection; 18 | 19 | /** 20 | * Lists all Sending Domains 21 | */ 22 | public class ListAllSendingDomains extends SparkPostBaseApp { 23 | 24 | static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 25 | 26 | private Client client; 27 | 28 | public static void main(String[] args) throws SparkPostException, IOException { 29 | Configurator.setRootLevel(Level.DEBUG); 30 | 31 | ListAllSendingDomains sample = new ListAllSendingDomains(); 32 | sample.runApp(); 33 | } 34 | 35 | private void runApp() throws SparkPostException, IOException { 36 | client = this.newConfiguredClient(); 37 | IRestConnection connection = new RestConnection(client, getEndPoint()); 38 | Response list = ResourceSendingDomains.list(connection); 39 | System.out.println("Sending Domains: " + list); 40 | 41 | // List results = listResponse.getResults(); 42 | // 43 | // // Print out the templates 44 | // System.out.println("Found " + results.size() + " tempaltes"); 45 | // for (TemplateItem item : results) { 46 | // System.out.println("\tName \"" + item.getName() + "\" updated " + item.getLastUpdateTime()); 47 | // } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/webhook/event/ABTestCancellationEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import java.util.Map; 4 | 5 | import com.google.gson.annotations.SerializedName; 6 | import com.sparkpost.model.Base; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | 13 | /** 14 | Details of a canceled A/B test 15 | */ 16 | 17 | @Data 18 | @EqualsAndHashCode(callSuper = true) 19 | public class ABTestCancellationEvent extends Base { 20 | 21 | @SerializedName("event_id") 22 | @Description( 23 | value = "Unique event identifier", 24 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 25 | private String eventId; 26 | 27 | @SerializedName("ab_test") 28 | @Description( 29 | value = "Metadata describing an A/B test", 30 | sample = "{\"engagement_metric\":\"count_unique_clicked\",\"test_mode\":\"bayesian\",\"name\":\"Password Reset\",\"default_template\":{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-1234\",\"engagement_rate\":0.2},\"id\":\"password-reset\",\"variants\":[{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-5678\",\"engagement_rate\":0.2}],\"version\":1}") 31 | private Map abTest; 32 | 33 | @SerializedName("subaccount_id") 34 | @Description( 35 | value = "Unique subaccount identifier.", 36 | sample = "101") 37 | private String subaccountId; 38 | 39 | @Description( 40 | value = "Type of event this record describes", 41 | sample = "ab_test_cancelled") 42 | private String type; 43 | 44 | @SerializedName("customer_id") 45 | @Description( 46 | value = "SparkPost-customer identifier through which this message was sent", 47 | sample = "1") 48 | private String customerId; 49 | 50 | @Description( 51 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 52 | sample = "1460989507") 53 | private String timestamp; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/StoredRecipientListTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class StoredRecipientListTest { 16 | 17 | private String STORED_RECIPIENT_LIST_JSON = "{ \"list_id\":\"123412341234\" }"; 18 | 19 | @BeforeClass 20 | public static void setUpClass() { 21 | Configurator.setRootLevel(Level.DEBUG); 22 | } 23 | 24 | @AfterClass 25 | public static void tearDownClass() { 26 | } 27 | 28 | @Before 29 | public void setUp() { 30 | } 31 | 32 | @After 33 | public void tearDown() { 34 | } 35 | 36 | /** 37 | * 38 | */ 39 | @Test 40 | public void testDecodeStoredRecipientList() { 41 | Gson gson = new Gson(); 42 | StoredRecipientList storedRecipientList = gson.fromJson(this.STORED_RECIPIENT_LIST_JSON, StoredRecipientList.class); 43 | Assert.assertNotNull(storedRecipientList); 44 | 45 | Assert.assertEquals(storedRecipientList.getListId(), "123412341234"); 46 | } 47 | 48 | /** 49 | * 50 | */ 51 | @Test 52 | public void testStoredRecipientListRoundtrip() { 53 | Gson gson = new Gson(); 54 | StoredRecipientList storedRecipientList = gson.fromJson(this.STORED_RECIPIENT_LIST_JSON, StoredRecipientList.class); 55 | Assert.assertNotNull(storedRecipientList); 56 | 57 | String storedReciplist_json = storedRecipientList.toJson(); 58 | StoredRecipientList storedRecipientList2 = gson.fromJson(storedReciplist_json, StoredRecipientList.class); 59 | 60 | Assert.assertEquals(storedRecipientList.getListId(), storedRecipientList2.getListId()); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/ListAllTemplatesSample.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | import java.util.List; 6 | 7 | import org.apache.logging.log4j.Level; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.apache.logging.log4j.core.config.Configurator; 11 | 12 | import com.sparkpost.Client; 13 | import com.sparkpost.exception.SparkPostException; 14 | import com.sparkpost.model.TemplateItem; 15 | import com.sparkpost.model.responses.TemplateListResponse; 16 | import com.sparkpost.resources.ResourceTemplates; 17 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 18 | import com.sparkpost.transport.IRestConnection; 19 | import com.sparkpost.transport.RestConnection; 20 | 21 | /** 22 | * List all templates stored in a SparkPost account 23 | */ 24 | public class ListAllTemplatesSample extends SparkPostBaseApp { 25 | 26 | static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 27 | 28 | private Client client; 29 | 30 | public static void main(String[] args) throws SparkPostException, IOException { 31 | Configurator.setRootLevel(Level.DEBUG); 32 | 33 | ListAllTemplatesSample sample = new ListAllTemplatesSample(); 34 | sample.runApp(); 35 | } 36 | 37 | private void runApp() throws SparkPostException, IOException { 38 | client = this.newConfiguredClient(); 39 | IRestConnection connection = new RestConnection(client, getEndPoint()); 40 | TemplateListResponse listResponse = ResourceTemplates.listAll(connection); 41 | 42 | List results = listResponse.getResults(); 43 | 44 | // Print out the templates 45 | System.out.println("Found " + results.size() + " tempaltes"); 46 | for (TemplateItem item : results) { 47 | System.out.println("\tName \"" + item.getName() + "\" updated " + item.getLastUpdateTime()); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/gen/java/com/sparkpost/model/webhook/event/ABTestCancellationEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import com.yepher.jsondoc.annotations.Description; 6 | import com.google.gson.annotations.SerializedName; 7 | import com.sparkpost.model.Base; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | 12 | /** 13 | Details of a canceled A/B test 14 | */ 15 | 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class ABTestCancellationEvent extends Base { 19 | 20 | @SerializedName("event_id") 21 | @Description( 22 | value = "Unique event identifier", 23 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 24 | private String eventId; 25 | 26 | @SerializedName("ab_test") 27 | @Description( 28 | value = "Metadata describing an A/B test", 29 | sample = "{\"engagement_metric\":\"count_unique_clicked\",\"test_mode\":\"bayesian\",\"name\":\"Password Reset\",\"default_template\":{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-1234\",\"engagement_rate\":0.2},\"id\":\"password-reset\",\"variants\":[{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-5678\",\"engagement_rate\":0.2}],\"version\":1}") 30 | private Map abTest; 31 | 32 | @SerializedName("subaccount_id") 33 | @Description( 34 | value = "Unique subaccount identifier.", 35 | sample = "101") 36 | private String subaccountId; 37 | 38 | @Description( 39 | value = "Type of event this record describes", 40 | sample = "ab_test_cancelled") 41 | private String type; 42 | 43 | @SerializedName("customer_id") 44 | @Description( 45 | value = "SparkPost-customer identifier through which this message was sent", 46 | sample = "1") 47 | private String customerId; 48 | 49 | @Description( 50 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 51 | sample = "1460989507") 52 | private String timestamp; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/webhook/event/ABTestCompletionEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import java.util.Map; 4 | 5 | import com.google.gson.annotations.SerializedName; 6 | import com.sparkpost.model.Base; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | 13 | /** 14 | Results of an A/B test 15 | */ 16 | 17 | @Data 18 | @EqualsAndHashCode(callSuper = true) 19 | public class ABTestCompletionEvent extends Base { 20 | 21 | @SerializedName("event_id") 22 | @Description( 23 | value = "Unique event identifier", 24 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 25 | private String eventId; 26 | 27 | @SerializedName("ab_test") 28 | @Description( 29 | value = "Metadata describing an A/B test", 30 | sample = "{\"engagement_metric\":\"count_unique_clicked\",\"test_mode\":\"bayesian\",\"name\":\"Password Reset\",\"default_template\":{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-1234\",\"engagement_rate\":0.2},\"id\":\"password-reset\",\"variants\":[{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-5678\",\"engagement_rate\":0.2}],\"winning_template_id\":\"templ-1234\",\"version\":1}") 31 | private Map abTest; 32 | 33 | @SerializedName("subaccount_id") 34 | @Description( 35 | value = "Unique subaccount identifier.", 36 | sample = "101") 37 | private String subaccountId; 38 | 39 | @Description( 40 | value = "Type of event this record describes", 41 | sample = "ab_test_completed") 42 | private String type; 43 | 44 | @SerializedName("customer_id") 45 | @Description( 46 | value = "SparkPost-customer identifier through which this message was sent", 47 | sample = "1") 48 | private String customerId; 49 | 50 | @Description( 51 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 52 | sample = "1460989507") 53 | private String timestamp; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/gen/java/com/sparkpost/model/webhook/event/ABTestCompletionEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import com.yepher.jsondoc.annotations.Description; 6 | import com.google.gson.annotations.SerializedName; 7 | import com.sparkpost.model.Base; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | 12 | /** 13 | Results of an A/B test 14 | */ 15 | 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class ABTestCompletionEvent extends Base { 19 | 20 | @SerializedName("event_id") 21 | @Description( 22 | value = "Unique event identifier", 23 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 24 | private String eventId; 25 | 26 | @SerializedName("ab_test") 27 | @Description( 28 | value = "Metadata describing an A/B test", 29 | sample = "{\"engagement_metric\":\"count_unique_clicked\",\"test_mode\":\"bayesian\",\"name\":\"Password Reset\",\"default_template\":{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-1234\",\"engagement_rate\":0.2},\"id\":\"password-reset\",\"variants\":[{\"count_unique_clicked\":10,\"count_accepted\":50,\"template_id\":\"templ-5678\",\"engagement_rate\":0.2}],\"winning_template_id\":\"templ-1234\",\"version\":1}") 30 | private Map abTest; 31 | 32 | @SerializedName("subaccount_id") 33 | @Description( 34 | value = "Unique subaccount identifier.", 35 | sample = "101") 36 | private String subaccountId; 37 | 38 | @Description( 39 | value = "Type of event this record describes", 40 | sample = "ab_test_completed") 41 | private String type; 42 | 43 | @SerializedName("customer_id") 44 | @Description( 45 | value = "SparkPost-customer identifier through which this message was sent", 46 | sample = "1") 47 | private String customerId; 48 | 49 | @Description( 50 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 51 | sample = "1460989507") 52 | private String timestamp; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceSubAccountCrud.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.resources; 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import com.sparkpost.exception.SparkPostException; 8 | import com.sparkpost.model.SubaccountInfo; 9 | import com.sparkpost.model.responses.Response; 10 | import com.sparkpost.model.responses.SubaccountCreateResponse; 11 | import com.sparkpost.transport.IRestConnection; 12 | 13 | /** 14 | *
15 | *
16 | * See Subaccounts API 17 | */ 18 | public class ResourceSubAccountCrud { 19 | 20 | public static SubaccountCreateResponse create(IRestConnection conn, SubaccountInfo subaccountInfo) throws SparkPostException { 21 | 22 | String json = subaccountInfo.toJson(); 23 | Endpoint ep = new Endpoint("subaccounts"); 24 | Response response = conn.post(ep, json); 25 | SubaccountCreateResponse createResponse = SubaccountCreateResponse.decode(response, SubaccountCreateResponse.class); 26 | return createResponse; 27 | } 28 | 29 | public static SubaccountCreateResponse get(IRestConnection conn, int subaccountId) throws SparkPostException { 30 | 31 | Endpoint ep = new Endpoint("subaccounts/" + subaccountId); 32 | Response response = conn.get(ep); 33 | SubaccountCreateResponse createResponse = SubaccountCreateResponse.decode(response, SubaccountCreateResponse.class); 34 | return createResponse; 35 | } 36 | 37 | public static List list(IRestConnection conn) throws SparkPostException { 38 | Endpoint ep = new Endpoint("subaccounts"); 39 | Response response = conn.get(ep); 40 | SubaccountCreateResponse createResponse = SubaccountCreateResponse.decode(response, SubaccountCreateResponse.class); 41 | List responseList = new ArrayList(); 42 | responseList.add(createResponse); 43 | return responseList; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/DeleteWebhookSample.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostException; 13 | import com.sparkpost.model.Webhook; 14 | import com.sparkpost.model.responses.WebhookListAllResponse; 15 | import com.sparkpost.resources.ResourceWebhooks; 16 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 17 | import com.sparkpost.transport.IRestConnection; 18 | import com.sparkpost.transport.RestConnection; 19 | 20 | /** 21 | * Delete all webhooks with "deleteme" in their name 22 | */ 23 | public class DeleteWebhookSample extends SparkPostBaseApp { 24 | 25 | static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 26 | 27 | private Client client; 28 | 29 | public static void main(String[] args) throws SparkPostException, IOException { 30 | Configurator.setRootLevel(Level.DEBUG); 31 | 32 | DeleteWebhookSample sample = new DeleteWebhookSample(); 33 | sample.runApp(); 34 | } 35 | 36 | private void runApp() throws SparkPostException, IOException { 37 | this.client = this.newConfiguredClient(); 38 | IRestConnection connection = new RestConnection(this.client, getEndPoint()); 39 | WebhookListAllResponse response = ResourceWebhooks.listAll(connection, "America/Chicago"); 40 | 41 | int deletedCount = 0; 42 | for (Webhook webhook : response.getResults()) { 43 | if (webhook.getName().toLowerCase().contains("deleteme")) { 44 | System.out.println("Will delete: " + webhook.getName() + " (" + webhook.getId() + ")"); 45 | ResourceWebhooks.delete(connection, webhook.getId()); 46 | deletedCount++; 47 | } 48 | } 49 | 50 | System.out.println("Deleted " + deletedCount + " webhooks."); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/webhook/event/IngestEventSuccessEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.sparkpost.model.Base; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | 11 | /** 12 | Details of an Ingest API processing success 13 | */ 14 | 15 | @Data 16 | @EqualsAndHashCode(callSuper = true) 17 | public class IngestEventSuccessEvent extends Base { 18 | 19 | @SerializedName("number_succeeded") 20 | @Description( 21 | value = "How many events succeeded processing", 22 | sample = "500") 23 | private int numberSucceeded; 24 | 25 | @SerializedName("event_id") 26 | @Description( 27 | value = "Unique event identifier", 28 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 29 | private String eventId; 30 | 31 | @SerializedName("batch_id") 32 | @Description( 33 | value = "Universally unique identifier", 34 | sample = "96500f4d-d4f4-4f1b-8080-02f4682184bb") 35 | private String batchId; 36 | 37 | @SerializedName("expiration_timestamp") 38 | @Description( 39 | value = "The time at which an ingest batch is no longer retrievable", 40 | sample = "2019-06-16T19:02:09.373Z") 41 | private String expirationTimestamp; 42 | 43 | @SerializedName("subaccount_id") 44 | @Description( 45 | value = "Unique subaccount identifier.", 46 | sample = "101") 47 | private String subaccountId; 48 | 49 | @Description( 50 | value = "Type of event this record describes", 51 | sample = "success") 52 | private String type; 53 | 54 | @SerializedName("customer_id") 55 | @Description( 56 | value = "SparkPost-customer identifier through which this message was sent", 57 | sample = "1") 58 | private String customerId; 59 | 60 | @SerializedName("number_duplicates") 61 | @Description( 62 | value = "How many events were already processed in a previous batch", 63 | sample = "350") 64 | private int numberDuplicates; 65 | 66 | @Description( 67 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 68 | sample = "1460989507") 69 | private String timestamp; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceSendingDomains.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.resources; 3 | 4 | import com.sparkpost.exception.SparkPostException; 5 | import com.sparkpost.model.SendingDomain; 6 | import com.sparkpost.model.VerifyAttributes; 7 | import com.sparkpost.model.responses.Response; 8 | import com.sparkpost.transport.IRestConnection; 9 | 10 | /** 11 | * Resource collection that is a 1-to-1 match to the Sending Domains SparkPost 12 | * API.
13 | *
14 | * See 15 | * Sending 16 | * Domains API 17 | * 18 | * @author grava 19 | */ 20 | public class ResourceSendingDomains { 21 | 22 | public static Response create(IRestConnection conn, SendingDomain domain) throws SparkPostException { 23 | 24 | String json = domain.toJson(); 25 | Endpoint ep = new Endpoint("sending-domains"); 26 | Response response = conn.post(ep, json); 27 | return response; 28 | } 29 | 30 | public static Response retrieve(IRestConnection conn, String domainName) throws SparkPostException { 31 | 32 | Endpoint ep = new Endpoint("sending-domains/" + domainName); 33 | Response response = conn.get(ep); 34 | return response; 35 | } 36 | 37 | public static Response list(IRestConnection conn) throws SparkPostException { 38 | Endpoint ep = new Endpoint("sending-domains/"); 39 | Response response = conn.get(ep); 40 | return response; 41 | } 42 | 43 | public static Response update(IRestConnection conn, String domainName, SendingDomain domain) throws SparkPostException { 44 | 45 | String json = domain.toJson(); 46 | Endpoint ep = new Endpoint("sending-domains/" + domainName); 47 | Response response = conn.put(ep, json); 48 | return response; 49 | } 50 | 51 | public static Response verify(IRestConnection conn, String domainName, VerifyAttributes verify) throws SparkPostException { 52 | 53 | String json = verify.toJson(); 54 | Endpoint ep = new Endpoint("sending-domains/" + domainName + "/verify"); 55 | Response response = conn.post(ep, json); 56 | return response; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TemplateItemResponse.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.sparkpost.model.TemplateContentAttributes; 6 | import com.yepher.jsondoc.annotations.Description; 7 | 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | @Data 12 | @EqualsAndHashCode(callSuper = true) 13 | public class TemplateItemResponse extends Response { 14 | 15 | @Data 16 | public static final class TemplateOptionsData { 17 | 18 | @Description(value = "Enable or disable open tracking", sample = {""}) 19 | @SerializedName("open_tracking") 20 | private Boolean openTracking; 21 | 22 | @Description(value = "Enable or disable click tracking", sample = {""}) 23 | @SerializedName("click_tracking") 24 | private Boolean clickTracking; 25 | 26 | @Description(value = "Distinguish between transactional and non-transactional messages for unsubscribe and suppression purposes", sample = {""}) 27 | private Boolean transactional; 28 | } 29 | 30 | @Description(value = "Short, unique, alphanumeric ID used to reference the template", sample = {""}) 31 | private String id; 32 | 33 | @Description(value = "Whether the template is published or is a draft version", sample = {""}) 34 | private Boolean published; 35 | 36 | @Description(value = "Editable display name", sample = {""}) 37 | private String name; 38 | 39 | @Description(value = "Detailed description of the template", sample = {""}) 40 | private String description; 41 | 42 | @Description(value = "Content for a template", sample = {""}) 43 | @SerializedName("content") 44 | private TemplateContentAttributes content; 45 | 46 | @Description(value = "object in which template options are defined", sample = {""}) 47 | private TemplateOptionsData options; 48 | 49 | /** 50 | * Whether or not to perform CSS inlining in HTML content 51 | * Defaults to false 52 | */ 53 | @Description(value = "Whether or not to perform CSS inlining in HTML content.", sample = {""}) 54 | @SerializedName("inline_css") 55 | private Boolean inlineCss; 56 | } 57 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/resources/Endpoint.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.resources; 3 | 4 | import org.apache.http.client.utils.URIBuilder; 5 | 6 | /** 7 | * Used internally to the SparkPost Library to write URL queries. 8 | */ 9 | public class Endpoint { 10 | 11 | private URIBuilder uriBuilder; 12 | 13 | public Endpoint(String endpoint) { 14 | this.uriBuilder = new URIBuilder(); 15 | this.uriBuilder.setPath(endpoint); 16 | } 17 | 18 | private void addString(String name, String value) { 19 | this.uriBuilder.addParameter(name, value); 20 | } 21 | 22 | public Endpoint addCommonParams( 23 | String from, 24 | String to, 25 | String domains, 26 | String campaigns, 27 | String templates, 28 | String metrics, 29 | String timezone, 30 | String limit, 31 | String orderBy) { 32 | 33 | addParam("from", from); 34 | addParam("to", to); 35 | addParam("domains", domains); 36 | addParam("campaigns", campaigns); 37 | addParam("templates", templates); 38 | addParam("metrics", metrics); 39 | addParam("timezone", timezone); 40 | addParam("limit", limit); 41 | addParam("order_by", orderBy); 42 | return this; 43 | } 44 | 45 | public Endpoint addParam(String name, String val) { 46 | if (val != null) { 47 | addString(name, val); 48 | } 49 | return this; 50 | } 51 | 52 | public Endpoint addParam(String name, Integer value) { 53 | if (value == null) { 54 | return this; 55 | } 56 | this.uriBuilder.addParameter(name, value.toString()); 57 | return this; 58 | } 59 | 60 | public Endpoint addParam(String name, Boolean value) { 61 | this.uriBuilder.addParameter(name, value.toString()); 62 | return this; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | String result = this.uriBuilder.toString(); 68 | 69 | if (result.startsWith("/")) { 70 | return result; 71 | } else { 72 | 73 | return "/" + result; 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/gen/java/com/sparkpost/model/webhook/event/IngestEventSuccessEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import com.yepher.jsondoc.annotations.Description; 6 | import com.google.gson.annotations.SerializedName; 7 | import com.sparkpost.model.Base; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | 12 | /** 13 | Details of an Ingest API processing success 14 | */ 15 | 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class IngestEventSuccessEvent extends Base { 19 | 20 | @SerializedName("number_succeeded") 21 | @Description( 22 | value = "How many events succeeded processing", 23 | sample = "500") 24 | private int numberSucceeded; 25 | 26 | @SerializedName("event_id") 27 | @Description( 28 | value = "Unique event identifier", 29 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 30 | private String eventId; 31 | 32 | @SerializedName("batch_id") 33 | @Description( 34 | value = "Universally unique identifier", 35 | sample = "96500f4d-d4f4-4f1b-8080-02f4682184bb") 36 | private String batchId; 37 | 38 | @SerializedName("expiration_timestamp") 39 | @Description( 40 | value = "The time at which an ingest batch is no longer retrievable", 41 | sample = "2019-06-16T19:02:09.373Z") 42 | private String expirationTimestamp; 43 | 44 | @SerializedName("subaccount_id") 45 | @Description( 46 | value = "Unique subaccount identifier.", 47 | sample = "101") 48 | private String subaccountId; 49 | 50 | @Description( 51 | value = "Type of event this record describes", 52 | sample = "success") 53 | private String type; 54 | 55 | @SerializedName("customer_id") 56 | @Description( 57 | value = "SparkPost-customer identifier through which this message was sent", 58 | sample = "1") 59 | private String customerId; 60 | 61 | @SerializedName("number_duplicates") 62 | @Description( 63 | value = "How many events were already processed in a previous batch", 64 | sample = "350") 65 | private int numberDuplicates; 66 | 67 | @Description( 68 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 69 | sample = "1460989507") 70 | private String timestamp; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/StoredTemplateTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class StoredTemplateTest { 16 | 17 | private String STORED_TEMPLATE_JSON = "{\n" 18 | + " \"template_id\": \"christmas_offer\",\n" 19 | + " \"use_draft_template\": true\n" 20 | + " }"; 21 | 22 | @BeforeClass 23 | public static void setUpClass() { 24 | Configurator.setRootLevel(Level.DEBUG); 25 | } 26 | 27 | @AfterClass 28 | public static void tearDownClass() { 29 | } 30 | 31 | @Before 32 | public void setUp() { 33 | } 34 | 35 | @After 36 | public void tearDown() { 37 | } 38 | 39 | /** 40 | * 41 | */ 42 | @Test 43 | public void testDecodeStoredTemplate() { 44 | Gson gson = new Gson(); 45 | StoredTemplate storedTemplate = gson.fromJson(this.STORED_TEMPLATE_JSON, StoredTemplate.class); 46 | Assert.assertNotNull(storedTemplate); 47 | 48 | Assert.assertEquals(storedTemplate.getTemplateId(), "christmas_offer"); 49 | Assert.assertTrue(storedTemplate.getUseDraftTemplate()); 50 | 51 | } 52 | 53 | /** 54 | * 55 | */ 56 | @Test 57 | public void testStoredTemplateRoundtrip() { 58 | Gson gson = new Gson(); 59 | StoredTemplate storedTemplate = gson.fromJson(this.STORED_TEMPLATE_JSON, StoredTemplate.class); 60 | Assert.assertNotNull(storedTemplate); 61 | 62 | String storedTemplate_json = storedTemplate.toJson(); 63 | StoredTemplate storedTemplate2 = gson.fromJson(storedTemplate_json, StoredTemplate.class); 64 | Assert.assertNotNull(storedTemplate2); 65 | 66 | Assert.assertEquals(storedTemplate.getTemplateId(), storedTemplate2.getTemplateId()); 67 | Assert.assertEquals(storedTemplate.getUseDraftTemplate(), storedTemplate2.getUseDraftTemplate()); 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/samples/sample_sp_substitution_email.eml: -------------------------------------------------------------------------------- 1 | MIME-Version: 1.0 2 | Subject: {{subject}} 3 | To: {{address.email}} 4 | From: {{from}} 5 | Content-Type: multipart/alternative; boundary=001a113ed0b2fce06c052ecfc06d 6 | 7 | --001a113ed0b2fce06c052ecfc06d 8 | Content-Type: text/plain; charset=UTF-8 9 | 10 | Sample Email with Array Content 11 | 12 | Name,\tValue 13 | {{each row_array}} 14 | {{loop_var.row}},\t {{loop_var.value}} 15 | {{end}} 16 | 17 | 18 | 19 | End of array data 20 | 21 | --001a113ed0b2fce06c052ecfc06d 22 | Content-Type: text/html; charset=UTF-8 23 | Content-Transfer-Encoding: quoted-printable 24 | 25 |
26 |
27 |
28 |
29 |
30 |

Sample Email with Array Content

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | {{each row_array}} 40 | 41 | 42 | 43 | 44 | {{end}} 45 | 46 |
NameValue
{{loop_var.row}}{{loop_var.value}}
47 |

End of array data

48 |
49 |
50 |
51 |
52 |
53 | 54 | --001a113ed0b2fce06c052ecfc06d-- -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/RetrieveAllTemplatesSample.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | import java.util.List; 6 | 7 | import org.apache.logging.log4j.Level; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.apache.logging.log4j.core.config.Configurator; 11 | 12 | import com.sparkpost.Client; 13 | import com.sparkpost.exception.SparkPostException; 14 | import com.sparkpost.model.TemplateItem; 15 | import com.sparkpost.model.responses.TemplateListResponse; 16 | import com.sparkpost.model.responses.TemplateRetrieveResponse; 17 | import com.sparkpost.resources.ResourceTemplates; 18 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 19 | import com.sparkpost.transport.IRestConnection; 20 | import com.sparkpost.transport.RestConnection; 21 | 22 | /** 23 | * List all templates stored in a SparkPost account 24 | */ 25 | public class RetrieveAllTemplatesSample extends SparkPostBaseApp { 26 | 27 | static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 28 | 29 | private Client client; 30 | 31 | public static void main(String[] args) throws SparkPostException, IOException { 32 | Configurator.setRootLevel(Level.DEBUG); 33 | 34 | RetrieveAllTemplatesSample sample = new RetrieveAllTemplatesSample(); 35 | sample.runApp(); 36 | } 37 | 38 | private void runApp() throws SparkPostException, IOException { 39 | this.client = this.newConfiguredClient(); 40 | IRestConnection connection = new RestConnection(this.client, getEndPoint()); 41 | TemplateListResponse listResponse = ResourceTemplates.listAll(connection); 42 | 43 | List results = listResponse.getResults(); 44 | 45 | // Print out the templates 46 | System.out.println("Found " + results.size() + " tempaltes"); 47 | for (TemplateItem item : results) { 48 | System.out.println("\tName \"" + item.getName() + "\" updated " + item.getLastUpdateTime()); 49 | TemplateRetrieveResponse templateResponse = ResourceTemplates.retrieve(connection, item.getId(), !item.getPublished()); 50 | System.out.println("Content: " + templateResponse.getResponseBody()); 51 | 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/error/samples/ForceTransportError.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.error.samples; 3 | 4 | import java.io.IOException; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostErrorServerResponseException; 13 | import com.sparkpost.exception.SparkPostException; 14 | import com.sparkpost.model.Webhook; 15 | import com.sparkpost.resources.ResourceWebhooks; 16 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 17 | import com.sparkpost.transport.IRestConnection; 18 | import com.sparkpost.transport.RestConnection; 19 | 20 | public class ForceTransportError extends SparkPostBaseApp { 21 | 22 | static final Logger logger = LogManager.getLogger(ForceTransportError.class); 23 | 24 | private Client client; 25 | 26 | public static void main(String[] args) throws SparkPostException, IOException { 27 | Configurator.setRootLevel(Level.DEBUG); 28 | 29 | ForceTransportError app = new ForceTransportError(); 30 | app.runApp(); 31 | } 32 | 33 | private void runApp() throws SparkPostException, IOException { 34 | try { 35 | foceFourHundredError(); 36 | } catch (SparkPostException e) { 37 | e.printStackTrace(); 38 | } catch (Exception e1) { 39 | e1.printStackTrace(); 40 | } 41 | } 42 | 43 | // Test https://github.com/SparkPost/java-sparkpost/issues/44#issuecomment-215549742 44 | private void foceFourHundredError() throws SparkPostException, IOException { 45 | this.client = this.newConfiguredClient(); 46 | 47 | IRestConnection restConnection = new RestConnection(this.client); 48 | Webhook webhook = new Webhook(); 49 | webhook.setName("name with spaces"); 50 | try { 51 | ResourceWebhooks.update(restConnection, webhook.getName(), webhook); 52 | throw new IllegalStateException("Error: Expected SparkPostErrorServerResponseException"); 53 | } catch (SparkPostErrorServerResponseException e) { 54 | System.out.println("GOOD: Sucecssfuly got a SparkPostErrorServerResponseException"); 55 | 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceRecipientLists.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.resources; 3 | 4 | import com.sparkpost.exception.SparkPostException; 5 | import com.sparkpost.model.RecipientList; 6 | import com.sparkpost.model.responses.RecipientListRetrieveResponse; 7 | import com.sparkpost.model.responses.RecipientListsListAllResponse; 8 | import com.sparkpost.model.responses.Response; 9 | import com.sparkpost.transport.IRestConnection; 10 | 11 | /** 12 | * Resource collection that is a 1-to-1 match to the Recipient Lists SparkPost 13 | * API.
14 | *
15 | * See 16 | * Recipient 17 | * Lists API 18 | * 19 | * @author grava 20 | */ 21 | public class ResourceRecipientLists { 22 | 23 | public static Response create(IRestConnection conn, Integer maxNumberOfRecipientErrors, RecipientList recipientList) throws SparkPostException { 24 | String json = recipientList.toJson(); 25 | Endpoint ep = new Endpoint("recipient-lists"); 26 | ep.addParam("num_rcpt_errors", maxNumberOfRecipientErrors); 27 | Response response = conn.post(ep, json); 28 | return response; 29 | } 30 | 31 | public static RecipientListRetrieveResponse retrieve(IRestConnection conn, String recipientListId, Boolean showRecipients) throws SparkPostException { 32 | Endpoint ep = new Endpoint("recipient-lists/" + recipientListId); 33 | ep.addParam("show_recipients", showRecipients); 34 | Response response = conn.get(ep); 35 | 36 | RecipientListRetrieveResponse retrieveResponse = RecipientListRetrieveResponse.decode(response, RecipientListRetrieveResponse.class); 37 | return retrieveResponse; 38 | } 39 | 40 | public static RecipientListsListAllResponse listAll(IRestConnection conn) throws SparkPostException { 41 | Endpoint ep = new Endpoint("recipient-lists"); 42 | Response response = conn.get(ep); 43 | RecipientListsListAllResponse listResponse = RecipientListsListAllResponse.decode(response, RecipientListsListAllResponse.class); 44 | return listResponse; 45 | } 46 | 47 | public static Response delete(IRestConnection conn, String recipientListId) throws SparkPostException { 48 | Endpoint ep = new Endpoint("recipient-lists/" + recipientListId); 49 | Response response = conn.delete(ep); 50 | return response; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/Response.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import java.lang.reflect.Type; 5 | 6 | import com.google.gson.Gson; 7 | import com.google.gson.annotations.SerializedName; 8 | import com.sparkpost.model.Base; 9 | import com.yepher.jsondoc.annotations.Description; 10 | 11 | import lombok.Data; 12 | import lombok.EqualsAndHashCode; 13 | 14 | /** 15 | * The response for the SparkPost server, as returned by @a RestConnection 16 | */ 17 | @Data 18 | @EqualsAndHashCode(callSuper = true) 19 | public class Response extends Base { 20 | 21 | private static final Gson GSON = new Gson(); 22 | 23 | @Description(value = "The URI of the request", sample = {""}) 24 | private String request = null; 25 | 26 | @Description(value = "Request Identifier", sample = {""}) 27 | private String requestId = null; 28 | 29 | @Description(value = "HTTP Response Code generated by request", sample = {"200"}) 30 | private int responseCode = -1; 31 | 32 | @Description(value = "The 'Content-Type' returne by the server", sample = {"application/json"}) 33 | private String contentType = null; 34 | 35 | @Description(value = "The HTTP Message generated by request", sample = {"OK"}) 36 | private String responseMessage = null; 37 | 38 | @Description(value = "The json of the response", sample = {""}) 39 | @SerializedName("json") 40 | private String responseBody = null; 41 | 42 | public static T decode(Response response, Type typeOfT) { 43 | T newResponse = null; 44 | 45 | // Make sure this is a JSON response before we try and decode with GSON 46 | if (response.getContentType() != null && response.getContentType().toLowerCase().startsWith("application/json")) { 47 | newResponse = GSON.fromJson(response.getResponseBody(), typeOfT); 48 | } else { 49 | newResponse = GSON.fromJson("{}", typeOfT); 50 | } 51 | 52 | if (newResponse != null) { 53 | newResponse.setRequest(response.request); 54 | newResponse.setRequestId(response.requestId); 55 | newResponse.setResponseCode(response.responseCode); 56 | newResponse.setContentType(response.contentType); 57 | newResponse.setResponseBody(response.responseBody); 58 | newResponse.setResponseMessage(response.responseMessage); 59 | } 60 | 61 | return newResponse; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.sparkpost 6 | libs 7 | 0.27 8 | 9 | 10 | sparkpost-lib 11 | SparkPost Library 12 | /libs/sparkpost-lib/ 13 | 14 | 15 | 16 | org.apache.logging.log4j 17 | log4j-core 18 | 19 | 20 | 21 | com.google.code.gson 22 | gson 23 | 2.3.1 24 | 25 | 26 | org.apache.httpcomponents 27 | httpclient 28 | 4.5.13 29 | 30 | 31 | 34 | 35 | org.jmock 36 | jmock-junit4 37 | test 38 | 39 | 40 | junit 41 | junit 42 | test 43 | 44 | 45 | org.apache.commons 46 | commons-lang3 47 | 48 | 49 | commons-codec 50 | commons-codec 51 | 52 | 53 | org.projectlombok 54 | lombok 55 | provided 56 | 57 | 58 | com.yepher.jsondoc 59 | annotations 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-source-plugin 68 | 69 | 70 | attach-sources 71 | 72 | jar 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/samples/mandrillBlacklistExample.csv: -------------------------------------------------------------------------------- 1 | email,reason,detail,created_at,expires_at,last_event_at,expires_at,subaccount 2 | 00000000@EXAMPLE.com,soft-bounce,,"2015-11-03 10:22:19.9567","2015-11-04 10:22:19","2015-11-03 10:22:19.95665","2015-11-04 10:22:19", 3 | 01904758111@example.COM,hard-bounce,"SMTP; 550 5.4.1 [01904758111@EXAMPLE.COM]: Recipient address rejected: Access denied","2016-01-14 19:08:17.51258","2016-01-21 19:08:17","2016-01-14 19:08:17.51253","2016-01-21 19:08:17", 4 | 01906204000@EXANPLE.COM,hard-bounce,"smtp;550 5.1.10 RESOLVER.ADR.RecipientNotFound; Recipient not found by SMTP address lookup","2015-12-18 17:49:49.74724","2016-01-28 19:44:39","2016-01-14 19:44:39.83638","2016-01-28 19:44:39", 5 | 01906823929@EXAMPLE.COM,hard-bounce,"SMTP; 550 5.4.1 [01906823929@EXAMPLE.COM]: Recipient address rejected: Access denied","2016-02-11 21:13:03.00523","2016-02-18 21:13:03","2016-02-11 21:13:03.00518","2016-02-18 21:13:03", 6 | 0uojuc1q5p@gmail.com,hard-bounce,"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/answer/6596 c188si8742007ywf.98 - gsmtp","2016-03-29 16:37:24.59657","2016-04-05 16:37:24","2016-03-29 16:37:24.59654","2016-04-05 16:37:24", 7 | 10687603@example.com.ar,soft-bounce,,"2015-06-05 19:50:18.09675","2015-06-11 21:04:00","2015-06-10 21:04:00.63428","2015-06-11 21:04:00", 8 | 10742937@example.com.ar,soft-bounce,,"2015-06-09 18:17:29.87352","2015-06-10 18:17:29","2015-06-09 18:17:29.87349","2015-06-10 18:17:29", 9 | 10803057@example.com.ar,soft-bounce,,"2015-05-19 20:50:11.78634","2015-06-09 19:28:15","2015-06-05 19:28:15.04113","2015-06-09 19:28:15", 10 | 10835434@example.com.ar,soft-bounce,,"2015-05-15 18:27:48.64675","2015-05-16 18:27:48","2015-05-15 18:27:48.6467","2015-05-16 18:27:48", 11 | 10835594@example.com.ar,soft-bounce,,"2015-06-09 14:10:20.86574","2015-06-11 14:21:03","2015-06-10 14:21:03.89673","2015-06-11 14:21:03", 12 | 10835805@example.com.ar,soft-bounce,,"2015-05-19 21:42:09.13229","2015-05-28 18:55:13","2015-05-27 18:55:13.1885","2015-05-28 18:55:13", 13 | 10835886@example.com.ar,soft-bounce,,"2015-05-19 14:16:12.35937","2015-05-23 13:26:26","2015-05-22 13:26:26.0547","2015-05-23 13:26:26", 14 | 10847089@example.com.ar,soft-bounce,,"2015-06-09 19:04:32.1635","2015-06-10 19:04:32","2015-06-09 19:04:32.16347","2015-06-10 19:04:32", 15 | 10849915@example.com.ar,soft-bounce,,"2015-06-09 22:37:12.14275","2015-06-10 22:37:12","2015-06-09 22:37:12.1427","2015-06-10 22:37:12", 16 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/CreateTemplateSimple.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.samples; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostException; 13 | import com.sparkpost.model.AddressAttributes; 14 | import com.sparkpost.model.TemplateAttributes; 15 | import com.sparkpost.model.TemplateContentAttributes; 16 | import com.sparkpost.model.responses.Response; 17 | import com.sparkpost.resources.ResourceTemplates; 18 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 19 | import com.sparkpost.transport.IRestConnection; 20 | import com.sparkpost.transport.RestConnection; 21 | 22 | public class CreateTemplateSimple extends SparkPostBaseApp { 23 | 24 | private static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 25 | 26 | private Client client; 27 | 28 | public static void main(String[] args) throws SparkPostException, IOException { 29 | Configurator.setRootLevel(Level.DEBUG); 30 | 31 | CreateTemplateSimple sample = new CreateTemplateSimple(); 32 | sample.runApp(); 33 | 34 | } 35 | 36 | private void runApp() throws SparkPostException, IOException { 37 | client = this.newConfiguredClient(); 38 | createTemplate(); 39 | } 40 | 41 | /** 42 | * Demonstrates how to store an email template in SparkPost 43 | * 44 | * @throws SparkPostException 45 | */ 46 | public void createTemplate() throws SparkPostException { 47 | if (logger.isDebugEnabled()) { 48 | logger.debug("createTemplate()"); 49 | } 50 | TemplateAttributes tpl = new TemplateAttributes(); 51 | 52 | tpl.setName(SAMPLE_TEMPLATE_NAME); 53 | tpl.setContent(new TemplateContentAttributes()); 54 | tpl.getContent().setFrom(new AddressAttributes(client.getFromEmail(), "me", null)); 55 | tpl.getContent().setHtml("Hello!"); 56 | tpl.getContent().setSubject("Template Test"); 57 | IRestConnection connection = new RestConnection(client, getEndPoint()); 58 | Response response = ResourceTemplates.create(connection, tpl); 59 | 60 | if (logger.isDebugEnabled()) { 61 | logger.debug("Create Template Response: " + response); 62 | } 63 | } 64 | 65 | public void sendEmail(String templateName, List recipients) { 66 | if (logger.isDebugEnabled()) { 67 | logger.debug("sendEmail(...)"); 68 | } 69 | 70 | } 71 | 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/DeleteSampleTemplates.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | import java.util.List; 6 | 7 | import org.apache.logging.log4j.Level; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.apache.logging.log4j.core.config.Configurator; 11 | 12 | import com.sparkpost.Client; 13 | import com.sparkpost.exception.SparkPostException; 14 | import com.sparkpost.model.TemplateItem; 15 | import com.sparkpost.model.responses.Response; 16 | import com.sparkpost.model.responses.TemplateListResponse; 17 | import com.sparkpost.resources.ResourceTemplates; 18 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 19 | import com.sparkpost.transport.IRestConnection; 20 | import com.sparkpost.transport.RestConnection; 21 | 22 | /** 23 | * Delete all test templates created by the sample code 24 | */ 25 | public class DeleteSampleTemplates extends SparkPostBaseApp { 26 | 27 | static final Logger logger = LogManager.getLogger(DeleteSampleTemplates.class); 28 | 29 | private Client client; 30 | 31 | public static void main(String[] args) throws SparkPostException, IOException { 32 | Configurator.setRootLevel(Level.DEBUG); 33 | 34 | DeleteSampleTemplates sample = new DeleteSampleTemplates(); 35 | sample.runApp(); 36 | } 37 | 38 | private void runApp() throws SparkPostException, IOException { 39 | client = this.newConfiguredClient(); 40 | IRestConnection connection = new RestConnection(client, getEndPoint()); 41 | 42 | // Get All Templates 43 | TemplateListResponse listResponse = ResourceTemplates.listAll(connection); 44 | List results = listResponse.getResults(); 45 | 46 | for (TemplateItem item : results) { 47 | 48 | // Delete any template with the name "_TMP_TEMPLATE_TEST" 49 | if (item.getName().equals(SAMPLE_TEMPLATE_NAME)) { 50 | deleteTemplate(connection, item.getId()); 51 | } 52 | } 53 | } 54 | 55 | private void deleteTemplate(IRestConnection connection, String templateId) throws SparkPostException { 56 | Response deleteResponse = ResourceTemplates.delete(connection, templateId); 57 | if (deleteResponse.getResponseCode() == 200) { 58 | System.out.println("\tdeleted: " + templateId); 59 | } else { 60 | System.out.println("\tError: Failed to delete: " + templateId + ") because " + deleteResponse.getResponseMessage()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tools/bin/doRelease.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # web-client/tools/bin 4 | bin=`dirname "$0"` 5 | 6 | # web-client 7 | bin=`cd $bin/../..; pwd` 8 | echo "project base directory: $bin" 9 | 10 | echo "Checking project..." 11 | 12 | version=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | egrep -v '^\[|Downloading:' | tr -d ' \n' | sed -E 's/\[.*\]//g') 13 | echo "Current project version: $version" 14 | 15 | if [ $# == 0 ] 16 | then 17 | echo "------------------------------------------------ " 18 | 19 | echo "Usage Error: you must specify two arguments..." 20 | echo "Usage: doRelease [FROM_VERSION] [TO_VERSION]" 21 | echo " " 22 | echo " Example: doRelease $version 0.0.1" 23 | echo " " 24 | echo "------------------------------------------------ " 25 | echo " " 26 | exit -1 27 | fi 28 | 29 | toVersion='0.0.1' 30 | # Single argument 31 | if [ $# == 1 ] 32 | then 33 | echo "doing single argument path ($1)" 34 | toVersion = $1 35 | fi 36 | 37 | 38 | # Single argument 39 | if [ $# == 2 ] 40 | then 41 | echo "doing two argument path ($1,$2)" 42 | version=$1 43 | toVersion=$2 44 | fi 45 | 46 | 47 | echo "Will change project from $version to $toVersion" 48 | 49 | echo reset Build.java 50 | git checkout ./libs/sparkpost-lib/src/main/java/com/sparkpost/Build.java 51 | 52 | # Update pom files with new version 53 | mvn versions:set -DoldVersion=$version -DnewVersion=$toVersion 54 | 55 | 56 | GIT_LOG_LINES=`git log --oneline | wc -l | sed -e 's/^[[:space:]]*//'` 57 | TGT_BUILD_FILE="./libs/sparkpost-lib/src/main/java/com/sparkpost/Build.java " 58 | SHORT_HASH=`git log -1 --pretty=format:%h` 59 | LONG_HASH=`git log -1 --pretty=format:%H` 60 | CURRENT_DATE=`date` 61 | JOB_NAME="SparkPost Library" 62 | 63 | echo "log lines: $GIT_LOG_LINES" 64 | 65 | echo "[PRE_BUILD_SCRIPT] ${TGT_BUILD_FILE} BEFORE adding build specifics" 66 | echo "`grep = ${TGT_BUILD_FILE}`" 67 | perl -p -i -e "s/BUILD_VERSION_NAME/${toVersion}/" ${TGT_BUILD_FILE} 68 | perl -p -i -e "s/BUILD_GENERATED_NAME/${JOB_NAME}/" ${TGT_BUILD_FILE} 69 | perl -p -i -e "s/BUILD_GENERATED_VERSION/${GIT_LOG_LINES}/" ${TGT_BUILD_FILE} 70 | perl -p -i -e "s/BUILD_GENERATED_SHORT_GIT_HASH/${SHORT_HASH:0:7}/" ${TGT_BUILD_FILE} 71 | perl -p -i -e "s/BUILD_GENERATED_GIT_HASH/${LONG_HASH}/" ${TGT_BUILD_FILE} 72 | perl -p -i -e "s/BUILD_GENERATED_DATE/${CURRENT_DATE}/" ${TGT_BUILD_FILE} 73 | echo "[PRE_BUILD_SCRIPT] ${TGT_BUILD_FILE} AFTER adding build specifics" 74 | echo "`grep = ${TGT_BUILD_FILE}`" 75 | 76 | 77 | 78 | 79 | # Done 80 | echo " " 81 | echo "*** You SHOULD do a 'git diff' to make sure everything looks correct before pushing to master." 82 | echo " " 83 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/DNSAttributesTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class DNSAttributesTest { 16 | 17 | private static final String DNS_ATTRIBUTE_JSON = "{\n" 18 | + " \"dkim_record\": \"some dkim record\",\n" 19 | + " \"spf_record\": \"some spf record\",\n" 20 | + " \"dkim_error\": \"some dkim error\",\n" 21 | + " \"spf_error\": \"some spf error\"\n" 22 | + "}"; 23 | 24 | @BeforeClass 25 | public static void setUpClass() { 26 | Configurator.setRootLevel(Level.DEBUG); 27 | } 28 | 29 | @AfterClass 30 | public static void tearDownClass() { 31 | } 32 | 33 | @Before 34 | public void setUp() { 35 | } 36 | 37 | @After 38 | public void tearDown() { 39 | } 40 | 41 | /** 42 | * 43 | */ 44 | @Test 45 | public void testDecodeDKIM() { 46 | Gson gson = new Gson(); 47 | DNSAttributes dnsAttributes = gson.fromJson(DNS_ATTRIBUTE_JSON, DNSAttributes.class); 48 | 49 | Assert.assertNotNull(dnsAttributes); 50 | 51 | Assert.assertEquals(dnsAttributes.getDkimRecord(), "some dkim record"); 52 | Assert.assertEquals(dnsAttributes.getSpfRecord(), "some spf record"); 53 | Assert.assertEquals(dnsAttributes.getDkimError(), "some dkim error"); 54 | Assert.assertEquals(dnsAttributes.getSpfError(), "some spf error"); 55 | } 56 | 57 | /** 58 | * 59 | */ 60 | @Test 61 | public void testDKIMRoundTrip() { 62 | Gson gson = new Gson(); 63 | DNSAttributes dnsAttributes = gson.fromJson(DNS_ATTRIBUTE_JSON, DNSAttributes.class); 64 | Assert.assertNotNull(dnsAttributes); 65 | 66 | String dnsAttributes_json = dnsAttributes.toJson(); 67 | DNSAttributes dnsAttributes2 = gson.fromJson(dnsAttributes_json, DNSAttributes.class); 68 | Assert.assertNotNull(dnsAttributes2); 69 | 70 | Assert.assertEquals(dnsAttributes.getDkimRecord(), dnsAttributes2.getDkimRecord()); 71 | Assert.assertEquals(dnsAttributes.getSpfRecord(), dnsAttributes2.getSpfRecord()); 72 | Assert.assertEquals(dnsAttributes.getDkimError(), dnsAttributes2.getDkimError()); 73 | Assert.assertEquals(dnsAttributes.getSpfError(), dnsAttributes2.getSpfError()); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /tools/bin/checkSignatures.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Do everything relative to the tools/bin directory 4 | cd "$(dirname $0)" 5 | 6 | cd ../.. 7 | 8 | echo "checking parent poms" 9 | 10 | echo "" 11 | echo "./target/sparkpost-*.pom" 12 | gpg --verify ./target/sparkpost-*.pom.asc ./target/sparkpost-*.pom 13 | 14 | echo "" 15 | echo "./target/libs-*.pom" 16 | gpg --verify ./libs/target/libs-*.pom.asc ./libs/target/libs-*.pom 17 | 18 | echo "" 19 | echo "checking build artifacts" 20 | 21 | echo "" 22 | echo "./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*-javadoc.jar" 23 | gpg --verify ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*-javadoc.jar.asc ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*-javadoc.jar 24 | 25 | echo "" 26 | echo "./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*-sources.jar" 27 | gpg --verify ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*-sources.jar.asc ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*-sources.jar 28 | 29 | echo "" 30 | echo "./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*.jar" 31 | gpg --verify ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*.jar.asc ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-*.jar 32 | 33 | echo "" 34 | echo "./apps/sparkpost-samples-app/target/sparkpost-samples-app-*-javadoc.jar" 35 | gpg --verify ./apps/sparkpost-samples-app/target/sparkpost-samples-app-*-javadoc.jar.asc ./apps/sparkpost-samples-app/target/sparkpost-samples-app-*-javadoc.jar 36 | 37 | echo "" 38 | echo "./apps/sparkpost-samples-app/target/sparkpost-samples-app-*-sources.jar" 39 | gpg --verify ./apps/sparkpost-samples-app/target/sparkpost-samples-app-*-sources.jar.asc ./apps/sparkpost-samples-app/target/sparkpost-samples-app-*-sources.jar 40 | 41 | echo "" 42 | echo "./apps/sparkpost-samples-app/target/sparkpost-samples-app-*.jar" 43 | gpg --verify ./apps/sparkpost-samples-app/target/sparkpost-samples-app-*.jar.asc ./apps/sparkpost-samples-app/target/sparkpost-samples-app-*.jar 44 | 45 | echo "" 46 | echo "./libs/sparkpost-lib/target/sparkpost-lib-*-javadoc.jar" 47 | gpg --verify ./libs/sparkpost-lib/target/sparkpost-lib-*-javadoc.jar.asc ./libs/sparkpost-lib/target/sparkpost-lib-*-javadoc.jar 48 | 49 | echo "" 50 | echo "./libs/sparkpost-lib/target/sparkpost-lib-*-sources.jar" 51 | gpg --verify ./libs/sparkpost-lib/target/sparkpost-lib-*-sources.jar.asc ./libs/sparkpost-lib/target/sparkpost-lib-*-sources.jar 52 | 53 | echo "" 54 | echo "./libs/sparkpost-lib/target/sparkpost-lib-*.jar" 55 | gpg --verify ./libs/sparkpost-lib/target/sparkpost-lib-*.jar.asc ./libs/sparkpost-lib/target/sparkpost-lib-*.jar 56 | 57 | echo "" 58 | echo "" 59 | echo "Done" 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/TemplateAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import com.yepher.jsondoc.annotations.Description; 5 | 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * DTO for storing a template. 11 | */ 12 | @Data 13 | @EqualsAndHashCode(callSuper = true) 14 | public class TemplateAttributes extends Base { 15 | 16 | public TemplateAttributes() { 17 | 18 | } 19 | 20 | /** 21 | * Short, unique, alphanumeric ID used to reference the template 22 | * After a template has been created, this property cannot be changed. Maximum length - 64 bytes 23 | */ 24 | @Description( 25 | value = "Short, unique, alphanumeric ID used to reference the template. After a template has been created, this property cannot be changed. Maximum length - 64 bytes", 26 | sample = {"AbC123"}) 27 | private String id; 28 | 29 | /** 30 | * Content that will be used to construct a message 31 | * For a full description, see the Content Attributes. Maximum length - 15 MBs 32 | */ 33 | @Description( 34 | value = "Content that will be used to construct a message. For a full description, see the Content Attributes. Maximum length - 15 MBs", 35 | sample = {"TemplateContentAttributes Dictionary"}) 36 | private TemplateContentAttributes content; 37 | 38 | /** 39 | * Whether the template is published or is a draft version 40 | * A template cannot be changed from published to draft. 41 | */ 42 | @Description(value = "Whether the template is published or is a draft version. A template cannot be changed from published to draft.", sample = {"true"}) 43 | private Boolean published; 44 | 45 | /** 46 | * Editable display name 47 | * The name does not have to be unique. Maximum length - 1024 bytes 48 | */ 49 | @Description(value = "Editable display name. The name does not have to be unique. Maximum length - 1024 bytes", sample = {"Template Name"}) 50 | private String name; 51 | 52 | /** 53 | * Detailed description of the template 54 | * Maximum length - 1024 bytes 55 | */ 56 | @Description(value = "Detailed description of the template. Maximum length - 1024 bytes.", sample = {"Template Description"}) 57 | private String description; 58 | 59 | /** 60 | * TemplateOptions in which template options are defined 61 | * For a full description, see the Options Attributes. 62 | */ 63 | @Description( 64 | value = "TemplateOptions in which template options are defined. For a full description, see the Options Attributes.", 65 | sample = {"TemplateOptions Dictionary"}) 66 | private OptionsAttributes options; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/responses/TransmissionResponseInfo.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model.responses; 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | import com.sparkpost.model.OptionsAttributes; 6 | import com.sparkpost.model.TemplateContentAttributes; 7 | import com.yepher.jsondoc.annotations.Description; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = true) 14 | public class TransmissionResponseInfo extends Response { 15 | 16 | @Description(value = "Maximum length - 1024 bytes", sample = {""}) 17 | private String description; 18 | 19 | @Description(value = "When the generation ended", sample = {""}) 20 | @SerializedName("generation_end_time") 21 | private String generationEndTime; 22 | 23 | @Description(value = "", sample = {""}) 24 | @SerializedName("rcpt_list_total_chunks") 25 | private int rcptListTotalChunks; 26 | 27 | @Description(value = "The size to use for recipient lists", sample = {""}) 28 | @SerializedName("rcpt_list_chunk_size") 29 | private int rcptListChunkSize; 30 | 31 | @Description(value = "Number of recipients in transmission", sample = {""}) 32 | @SerializedName("num_rcpts") 33 | private int numRecipients; 34 | 35 | @Description(value = "Number of emails generated", sample = {""}) 36 | @SerializedName("num_generated") 37 | private int numGenerated; 38 | 39 | @Description(value = "Transmission options", sample = {""}) 40 | private OptionsAttributes options; 41 | 42 | @Description(value = "Transmission id", sample = {""}) 43 | private String id; 44 | 45 | @Description(value = "Transmission return path", sample = {""}) 46 | @SerializedName("return_path") 47 | private String returnPath; 48 | 49 | @Description(value = "The start time for the generation", sample = {""}) 50 | @SerializedName("generation_start_time") 51 | private String generationStartTime; 52 | 53 | @Description(value = "Transmission metadata", sample = {""}) 54 | private String metadata; 55 | 56 | @Description(value = "Transmission names", sample = {""}) 57 | private String name; 58 | 59 | @Description(value = "Number of message that failed to generate", sample = {""}) 60 | @SerializedName("num_failed_gen") 61 | private int numFailedGen; 62 | 63 | @Description(value = "The recipient list id for this transmission", sample = {""}) 64 | @SerializedName("rcpt_list_id") 65 | private String rcptListId; 66 | 67 | @Description(value = "Transmission campaign id", sample = {""}) 68 | @SerializedName("campaign_id") 69 | private String campaignId; 70 | 71 | @Description(value = "Template contents", sample = {""}) 72 | private TemplateContentAttributes content; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/RecipientAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | import com.yepher.jsondoc.annotations.Description; 9 | 10 | import lombok.Data; 11 | import lombok.EqualsAndHashCode; 12 | 13 | /** 14 | * DTO for storing a recipient. 15 | */ 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class RecipientAttributes extends Base { 19 | 20 | /** 21 | * Address information for a recipient 22 | */ 23 | @Description(value = "Address information for a recipient", sample = {"recipient@example.com"}) 24 | private AddressAttributes address = null; 25 | 26 | /** 27 | * Email to use for envelope FROM ( Note: SparkPost Elite only ) 28 | * To support Variable Envelope Return Path (VERP), this field provides a 29 | * specific recipient a unique envelope MAIL FROM. 30 | */ 31 | @Description(value = "Email to use for envelope FROM ( Note: SparkPost Elite only )", sample = {""}) 32 | @SerializedName("return_path") 33 | private String returnPath = null; 34 | 35 | /** 36 | * Array of text labels associated with a recipient 37 | * Tags are available in Webhook events. Maximum number of tags - 10 per 38 | * recipient, 100 system wide. Any tags over the limits are ignored. 39 | */ 40 | @Description( 41 | value = "Array of text labels associated with a recipient Tags are available in Webhook events. Maximum number of tags - 10 per recipient, 100 system wide. Any tags over the limits are ignored.", 42 | sample = {""}) 43 | private List tags = null; 44 | 45 | /** 46 | * Key/value pairs associated with a recipient 47 | * Metadata is available during events through the Webhooks and is provided 48 | * to the substitution engine. A maximum of 200 bytes of merged metadata 49 | * (transmission level + recipient level) is available with recipient 50 | * metadata taking precedence over transmission metadata when there are 51 | * conflicts. 52 | */ 53 | @Description(value = "Key/value pairs associated with a recipient,sample={\"\"}") 54 | private Map metadata = null; 55 | 56 | /** 57 | * Key/value pairs associated with a recipient that are provided to the 58 | * substitution engine 59 | * Recipient substitution data takes precedence over transmission 60 | * substitution data. Unlike metadata, substitution data is not included in 61 | * Webhook events. 62 | */ 63 | @Description(value = "Key/value pairs associated with a recipient that are provided to the substitution engine", sample = {""}) 64 | @SerializedName("substitution_data") 65 | private Map substitutionData = null; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /tools/bin/collectJars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Do everything relative to the tools/bin directory 4 | cd "$(dirname $0)" 5 | 6 | VERSION=0.25 7 | 8 | cd ../.. 9 | 10 | mkdir target/files 11 | 12 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION-javadoc.jar ./target/files/ 13 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION-javadoc.jar.asc ./target/files/ 14 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION-sources.jar ./target/files/ 15 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION-sources.jar.asc ./target/files/ 16 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION.jar ./target/files/ 17 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION.jar.asc ./target/files/ 18 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION-javadoc.jar ./target/files/ 19 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION-javadoc.jar.asc ./target/files/ 20 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION-sources.jar ./target/files/ 21 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION-sources.jar.asc ./target/files/ 22 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION.jar ./target/files/ 23 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION.jar.asc ./target/files/ 24 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION-javadoc.jar ./target/files/ 25 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION-javadoc.jar.asc ./target/files/ 26 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION-sources.jar ./target/files/ 27 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION-sources.jar.asc ./target/files/ 28 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION.jar ./target/files/ 29 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION.jar.asc ./target/files/ 30 | 31 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION.pom ./target/files/ 32 | cp ./apps/sparkpost-documentor-app/target/sparkpost-documentor-app-$VERSION.pom.asc ./target/files/ 33 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION.pom ./target/files/ 34 | cp ./apps/sparkpost-samples-app/target/sparkpost-samples-app-$VERSION.pom.asc ./target/files/ 35 | cp ./apps/target/apps-$VERSION.pom ./target/files/ 36 | cp ./apps/target/apps-$VERSION.pom.asc ./target/files/ 37 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION.pom ./target/files/ 38 | cp ./libs/sparkpost-lib/target/sparkpost-lib-$VERSION.pom.asc ./target/files/ 39 | cp ./libs/target/libs-$VERSION.pom ./target/files/ 40 | cp ./libs/target/libs-$VERSION.pom.asc ./target/files/ 41 | cp ./target/sparkpost-$VERSION.pom ./target/files/ 42 | cp ./target/sparkpost-$VERSION.pom.asc ./target/files/ 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/webhook/event/IngestEventErrorEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import com.sparkpost.model.Base; 5 | import com.yepher.jsondoc.annotations.Description; 6 | 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | 11 | /** 12 | Details of an Ingest API processing error 13 | */ 14 | 15 | @Data 16 | @EqualsAndHashCode(callSuper = true) 17 | public class IngestEventErrorEvent extends Base { 18 | 19 | @Description( 20 | value = "Indicates if an error retryable", 21 | sample = "false") 22 | private int retryable; 23 | 24 | @SerializedName("batch_id") 25 | @Description( 26 | value = "Universally unique identifier", 27 | sample = "96500f4d-d4f4-4f1b-8080-02f4682184bb") 28 | private String batchId; 29 | 30 | @SerializedName("expiration_timestamp") 31 | @Description( 32 | value = "The time at which an ingest batch is no longer retrievable", 33 | sample = "2019-06-16T19:02:09.373Z") 34 | private String expirationTimestamp; 35 | 36 | @Description( 37 | value = "Type of event this record describes", 38 | sample = "error") 39 | private String type; 40 | 41 | @SerializedName("number_duplicates") 42 | @Description( 43 | value = "How many events were already processed in a previous batch", 44 | sample = "350") 45 | private int numberDuplicates; 46 | 47 | @SerializedName("number_succeeded") 48 | @Description( 49 | value = "How many events succeeded processing", 50 | sample = "500") 51 | private int numberSucceeded; 52 | 53 | @SerializedName("event_id") 54 | @Description( 55 | value = "Unique event identifier", 56 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 57 | private String eventId; 58 | 59 | @SerializedName("number_failed") 60 | @Description( 61 | value = "How many events failed processing", 62 | sample = "50") 63 | private int numberFailed; 64 | 65 | @SerializedName("error_type") 66 | @Description( 67 | value = "Category of error that was encountered in processing", 68 | sample = "validation") 69 | private String errorType; 70 | 71 | @SerializedName("subaccount_id") 72 | @Description( 73 | value = "Unique subaccount identifier.", 74 | sample = "101") 75 | private String subaccountId; 76 | 77 | @Description( 78 | value = "A reference to a failed batch", 79 | sample = "https://api.sparkpost.com/api/v1/ingest/events/failures/fbd59e4c-1629-4736-803d-201ff9fa8dd6") 80 | private String href; 81 | 82 | @SerializedName("customer_id") 83 | @Description( 84 | value = "SparkPost-customer identifier through which this message was sent", 85 | sample = "1") 86 | private String customerId; 87 | 88 | @Description( 89 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 90 | sample = "1460989507") 91 | private String timestamp; 92 | 93 | } 94 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/SuppressionListTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import java.util.List; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.core.config.Configurator; 8 | import org.junit.After; 9 | import org.junit.AfterClass; 10 | import org.junit.Assert; 11 | import org.junit.Before; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test; 14 | 15 | import com.google.gson.Gson; 16 | 17 | public class SuppressionListTest { 18 | 19 | private String SUPPRESSION_LIST_JSON = "{\n" 20 | + " \"recipients\": [\n" 21 | + " {\n" 22 | + " \"email\": \"rcpt_1@example.com\",\n" 23 | + " \"transactional\": true,\n" 24 | + " \"description\": \"User requested to not receive any transactional emails.\"\n" 25 | + " },\n" 26 | + " {\n" 27 | + " \"email\": \"rcpt_2@example.com\",\n" 28 | + " \"non_transactional\": true\n" 29 | + " }\n" 30 | + " ]\n" 31 | + "}"; 32 | 33 | @BeforeClass 34 | public static void setUpClass() { 35 | Configurator.setRootLevel(Level.DEBUG); 36 | } 37 | 38 | @AfterClass 39 | public static void tearDownClass() { 40 | } 41 | 42 | @Before 43 | public void setUp() { 44 | } 45 | 46 | @After 47 | public void tearDown() { 48 | } 49 | 50 | /** 51 | * 52 | */ 53 | @Test 54 | public void testDecodeSuppressionList() { 55 | Gson gson = new Gson(); 56 | SuppressionList suppressionList = gson.fromJson(this.SUPPRESSION_LIST_JSON, SuppressionList.class); 57 | Assert.assertNotNull(suppressionList); 58 | 59 | List recipients = suppressionList.getRecipients(); 60 | // Internal state will be tested in SuppressionListEntry unit tests 61 | Assert.assertNotNull(suppressionList); 62 | Assert.assertEquals(recipients.size(), 2); 63 | } 64 | 65 | /** 66 | * 67 | */ 68 | @Test 69 | public void testSuppressionListRoundTrip() { 70 | Gson gson = new Gson(); 71 | SuppressionList suppressionList = gson.fromJson(this.SUPPRESSION_LIST_JSON, SuppressionList.class); 72 | Assert.assertNotNull(suppressionList); 73 | 74 | String suppressionList_json = suppressionList.toJson(); 75 | SuppressionList suppressionList2 = gson.fromJson(suppressionList_json, SuppressionList.class); 76 | Assert.assertNotNull(suppressionList2); 77 | 78 | List recipients = suppressionList2.getRecipients(); 79 | // Internal state will be tested in SuppressionListEntry unit tests 80 | Assert.assertNotNull(suppressionList2); 81 | Assert.assertEquals(recipients.size(), 2); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/gen/java/com/sparkpost/model/webhook/event/IngestEventErrorEvent.java: -------------------------------------------------------------------------------- 1 | package com.sparkpost.model.webhook.event; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import com.yepher.jsondoc.annotations.Description; 6 | import com.google.gson.annotations.SerializedName; 7 | import com.sparkpost.model.Base; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | 12 | /** 13 | Details of an Ingest API processing error 14 | */ 15 | 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class IngestEventErrorEvent extends Base { 19 | 20 | @Description( 21 | value = "Indicates if an error retryable", 22 | sample = "false") 23 | private int retryable; 24 | 25 | @SerializedName("batch_id") 26 | @Description( 27 | value = "Universally unique identifier", 28 | sample = "96500f4d-d4f4-4f1b-8080-02f4682184bb") 29 | private String batchId; 30 | 31 | @SerializedName("expiration_timestamp") 32 | @Description( 33 | value = "The time at which an ingest batch is no longer retrievable", 34 | sample = "2019-06-16T19:02:09.373Z") 35 | private String expirationTimestamp; 36 | 37 | @Description( 38 | value = "Type of event this record describes", 39 | sample = "error") 40 | private String type; 41 | 42 | @SerializedName("number_duplicates") 43 | @Description( 44 | value = "How many events were already processed in a previous batch", 45 | sample = "350") 46 | private int numberDuplicates; 47 | 48 | @SerializedName("number_succeeded") 49 | @Description( 50 | value = "How many events succeeded processing", 51 | sample = "500") 52 | private int numberSucceeded; 53 | 54 | @SerializedName("event_id") 55 | @Description( 56 | value = "Unique event identifier", 57 | sample = "0e5cf1fc-cb36-4c39-b695-3651b6ea6563") 58 | private String eventId; 59 | 60 | @SerializedName("number_failed") 61 | @Description( 62 | value = "How many events failed processing", 63 | sample = "50") 64 | private int numberFailed; 65 | 66 | @SerializedName("error_type") 67 | @Description( 68 | value = "Category of error that was encountered in processing", 69 | sample = "validation") 70 | private String errorType; 71 | 72 | @SerializedName("subaccount_id") 73 | @Description( 74 | value = "Unique subaccount identifier.", 75 | sample = "101") 76 | private String subaccountId; 77 | 78 | @Description( 79 | value = "A reference to a failed batch", 80 | sample = "https://api.sparkpost.com/api/v1/ingest/events/failures/fbd59e4c-1629-4736-803d-201ff9fa8dd6") 81 | private String href; 82 | 83 | @SerializedName("customer_id") 84 | @Description( 85 | value = "SparkPost-customer identifier through which this message was sent", 86 | sample = "1") 87 | private String customerId; 88 | 89 | @Description( 90 | value = "Event date and time, in Unix timestamp format (integer seconds since 00:00:00 GMT 1970-01-01)", 91 | sample = "1460989507") 92 | private String timestamp; 93 | 94 | } 95 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/CreateTemplateFromFile2.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostException; 13 | import com.sparkpost.model.AddressAttributes; 14 | import com.sparkpost.model.TemplateAttributes; 15 | import com.sparkpost.model.TemplateContentAttributes; 16 | import com.sparkpost.model.responses.Response; 17 | import com.sparkpost.resources.ResourceTemplates; 18 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 19 | import com.sparkpost.transport.IRestConnection; 20 | import com.sparkpost.transport.RestConnection; 21 | 22 | /** 23 | * This class demonstrates how to store an HTML template in SparkPost 24 | */ 25 | public class CreateTemplateFromFile2 extends SparkPostBaseApp { 26 | 27 | private static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 28 | 29 | private Client client; 30 | 31 | public static void main(String[] args) throws SparkPostException, IOException { 32 | Configurator.setRootLevel(Level.DEBUG); 33 | 34 | CreateTemplateFromFile2 sample = new CreateTemplateFromFile2(); 35 | sample.runApp(); 36 | 37 | } 38 | 39 | private void runApp() throws SparkPostException, IOException { 40 | client = this.newConfiguredClient(); 41 | String template = this.getTemplate("richContent.html"); 42 | createTemplate(template, SAMPLE_TEMPLATE_NAME); 43 | } 44 | 45 | /** 46 | * Demonstrates how to store an email template in SparkPost 47 | * 48 | * @throws SparkPostException 49 | */ 50 | public void createTemplate(String html, String name) throws SparkPostException { 51 | if (logger.isDebugEnabled()) { 52 | logger.debug("createTemplate()"); 53 | } 54 | TemplateAttributes template = new TemplateAttributes(); 55 | template.setName(name); 56 | 57 | TemplateContentAttributes content = new TemplateContentAttributes(); 58 | 59 | content.setSubject("Template Test"); 60 | content.setFrom(new AddressAttributes(client.getFromEmail(), "me", null)); 61 | content.setHtml(html); 62 | template.setContent(content); 63 | 64 | IRestConnection connection = new RestConnection(client, getEndPoint()); 65 | try { 66 | Response response = ResourceTemplates.create(connection, template); 67 | if (logger.isDebugEnabled()) { 68 | logger.debug("Create Template Response: " + response); 69 | } 70 | } catch (SparkPostException e) { 71 | logger.debug("Create Template Failed: "); 72 | throw e; 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /apps/sparkpost-documentor-app/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.sparkpost 6 | apps 7 | 0.27 8 | 9 | sparkpost-documentor-app 10 | Generates Markdown of Protocol 11 | /apps/sparkpost-documentor-app/ 12 | 13 | 14 | 15 | com.sparkpost 16 | sparkpost-lib 17 | 18 | 19 | 20 | org.apache.logging.log4j 21 | log4j-core 22 | 23 | 24 | com.google.code.gson 25 | gson 26 | 2.3.1 27 | 28 | 29 | org.apache.httpcomponents 30 | httpclient 31 | 4.5.13 32 | 33 | 36 | 37 | org.jmock 38 | jmock-junit4 39 | test 40 | 41 | 42 | junit 43 | junit 44 | test 45 | 46 | 47 | org.projectlombok 48 | lombok 49 | provided 50 | 51 | 52 | com.yepher.jsondoc 53 | annotations 54 | 55 | 56 | com.yepher.jsondoc 57 | documentor 58 | 59 | 60 | org.reflections 61 | reflections 62 | 0.9.10 63 | 64 | 65 | commons-io 66 | commons-io 67 | 68 | 69 | 70 | org.json 71 | json 72 | 20160810 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | org.apache.maven.plugins 81 | maven-source-plugin 82 | 83 | 84 | attach-sources 85 | 86 | jar 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/CreateTemplateFromFile.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | 6 | import org.apache.logging.log4j.Level; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.apache.logging.log4j.core.config.Configurator; 10 | 11 | import com.sparkpost.Client; 12 | import com.sparkpost.exception.SparkPostException; 13 | import com.sparkpost.model.TemplateAttributes; 14 | import com.sparkpost.model.TemplateContentAttributes; 15 | import com.sparkpost.model.responses.Response; 16 | import com.sparkpost.resources.ResourceTemplates; 17 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 18 | import com.sparkpost.transport.IRestConnection; 19 | import com.sparkpost.transport.RestConnection; 20 | 21 | /** 22 | * This class demonstrates how to store and RFC822 template in SparkPost 23 | * Warning: RFC822 templates are only manageable via API and not from website directly. 24 | */ 25 | public class CreateTemplateFromFile extends SparkPostBaseApp { 26 | 27 | private static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 28 | 29 | private Client client; 30 | 31 | public static void main(String[] args) throws SparkPostException, IOException { 32 | Configurator.setRootLevel(Level.DEBUG); 33 | 34 | CreateTemplateFromFile sample = new CreateTemplateFromFile(); 35 | sample.runApp(); 36 | 37 | } 38 | 39 | private void runApp() throws SparkPostException, IOException { 40 | this.client = this.newConfiguredClient(); 41 | String template = this.getTemplate("sample_email.txt"); 42 | createTemplate(template, SAMPLE_TEMPLATE_NAME); 43 | } 44 | 45 | /** 46 | * Demonstrates how to store an email template in SparkPost 47 | * 48 | * @throws SparkPostException 49 | */ 50 | public void createTemplate(String rfc822Content, String name) throws SparkPostException { 51 | if (logger.isDebugEnabled()) { 52 | logger.debug("createTemplate()"); 53 | } 54 | TemplateAttributes template = new TemplateAttributes(); 55 | template.setName(name); 56 | 57 | TemplateContentAttributes content = new TemplateContentAttributes(); 58 | 59 | //content.setFrom(new AddressAttributes(client.getFromEmail(), "me", null)); 60 | content.setEmailRFC822(rfc822Content); 61 | template.setContent(content); 62 | 63 | IRestConnection connection = new RestConnection(this.client, getEndPoint()); 64 | try { 65 | Response response = ResourceTemplates.create(connection, template); 66 | if (logger.isDebugEnabled()) { 67 | logger.debug("Create Template Response: " + response); 68 | } 69 | } catch (SparkPostException e) { 70 | logger.debug("Create Template Failed: "); 71 | throw e; 72 | } 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/transport/IRestConnection.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.transport; 3 | 4 | import com.sparkpost.exception.SparkPostException; 5 | import com.sparkpost.model.responses.Response; 6 | import com.sparkpost.resources.Endpoint; 7 | 8 | public interface IRestConnection { 9 | 10 | String SPC_EU_ENDPOINT = "https://api.eu.sparkpost.com/api/v1"; 11 | 12 | String SPC_US_ENDPOINT = "https://api.sparkpost.com/api/v1"; 13 | 14 | String SUBACCOUNT_HEADER = "X-MSYS-SUBACCOUNT"; 15 | 16 | /** 17 | * Default endpoint to use for connections : 18 | * https://api.sparkpost.com/api/v1 19 | */ 20 | String defaultApiEndpoint = SPC_US_ENDPOINT; 21 | 22 | /** 23 | * @param key 24 | * The HTTP header key 25 | * @param value 26 | * The HTTP header value 27 | */ 28 | void addHeader(String key, String value); 29 | 30 | /** 31 | * Perform an HTTP GET request. This method throws an exception if the 32 | * server returns anything else than a 200. 33 | * 34 | * @param endpoint 35 | * API endpoint to send the request to. 36 | * @return Server response to the request. 37 | * @throws SparkPostException 38 | * if something goes wrong 39 | */ 40 | Response get(Endpoint endpoint) throws SparkPostException; 41 | 42 | /** 43 | * Perform an HTTP POST request. This method throws an exception if the 44 | * server returns anything else than a 200. 45 | * 46 | * @param endpoint 47 | * API endpoint to send the request to. 48 | * @param json 49 | * POST data block to send with the request. May be null. 50 | * @return Server response to the request 51 | * @throws SparkPostException 52 | * if something goes wrong 53 | */ 54 | Response post(Endpoint endpoint, String json) throws SparkPostException; 55 | 56 | /** 57 | * Perform an HTTP PUT request. This method throws an exception if the 58 | * server returns anything else than a 200. 59 | * 60 | * @param endpoint 61 | * API endpoint to send the request to. 62 | * @param json 63 | * PUT data block to send with the request. May be null. 64 | * @return Server response to the request. 65 | * @throws SparkPostException 66 | * if something goes wrong 67 | */ 68 | Response put(Endpoint endpoint, String json) throws SparkPostException; 69 | 70 | /** 71 | * Perform an HTTP DELETE request. This method throws an exception if the 72 | * server returns anything else than a 200. 73 | * 74 | * @param endpoint 75 | * API endpoint to send the request to. 76 | * @return Server response to the request. 77 | * @throws SparkPostException 78 | * if something goes wrong 79 | */ 80 | Response delete(Endpoint endpoint) throws SparkPostException; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/SuppressionListEntryTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class SuppressionListEntryTest { 16 | 17 | private String SUPPRESSION_LIST_JSON = "{\n" 18 | + " \"email\": \"rcpt_1@example.com\",\n" 19 | + " \"transactional\": true,\n" 20 | + " \"source\": \"some source\",\n" 21 | + " \"description\": \"User requested to not receive any transactional emails.\"\n" 22 | + " }"; 23 | 24 | @BeforeClass 25 | public static void setUpClass() { 26 | Configurator.setRootLevel(Level.DEBUG); 27 | } 28 | 29 | @AfterClass 30 | public static void tearDownClass() { 31 | } 32 | 33 | @Before 34 | public void setUp() { 35 | } 36 | 37 | @After 38 | public void tearDown() { 39 | } 40 | 41 | /** 42 | * 43 | */ 44 | @Test 45 | public void testDecodeSuppressionListEntry() { 46 | Gson gson = new Gson(); 47 | SuppressionListEntry suppressionListEntry = gson.fromJson(this.SUPPRESSION_LIST_JSON, SuppressionListEntry.class); 48 | Assert.assertNotNull(suppressionListEntry); 49 | 50 | Assert.assertEquals(suppressionListEntry.getEmail(), "rcpt_1@example.com"); 51 | Assert.assertTrue(suppressionListEntry.isTransactional()); 52 | Assert.assertFalse(suppressionListEntry.isNonTransactional()); 53 | Assert.assertEquals(suppressionListEntry.getDescription(), "User requested to not receive any transactional emails."); 54 | Assert.assertEquals(suppressionListEntry.getSource(), "some source"); 55 | 56 | } 57 | 58 | /** 59 | * 60 | */ 61 | @Test 62 | public void testSuppressionListEntryRoundtrip() { 63 | Gson gson = new Gson(); 64 | SuppressionListEntry suppressionListEntry = gson.fromJson(this.SUPPRESSION_LIST_JSON, SuppressionListEntry.class); 65 | Assert.assertNotNull(suppressionListEntry); 66 | 67 | String suppressionListEntry_json = suppressionListEntry.toJson(); 68 | SuppressionListEntry suppressionListEntry2 = gson.fromJson(suppressionListEntry_json, SuppressionListEntry.class); 69 | Assert.assertNotNull(suppressionListEntry2); 70 | 71 | Assert.assertEquals(suppressionListEntry.getEmail(), suppressionListEntry2.getEmail()); 72 | Assert.assertEquals(suppressionListEntry.isTransactional(), suppressionListEntry2.isTransactional()); 73 | Assert.assertEquals(suppressionListEntry.isNonTransactional(), suppressionListEntry2.isNonTransactional()); 74 | Assert.assertEquals(suppressionListEntry.getDescription(), suppressionListEntry2.getDescription()); 75 | Assert.assertEquals(suppressionListEntry.getSource(), suppressionListEntry2.getSource()); 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/SubaccountCRUDSample.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | import java.util.List; 6 | 7 | import org.apache.logging.log4j.Level; 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.apache.logging.log4j.core.config.Configurator; 11 | 12 | import com.sparkpost.Client; 13 | import com.sparkpost.exception.SparkPostException; 14 | import com.sparkpost.model.SubaccountInfo; 15 | import com.sparkpost.model.responses.SubaccountCreateResponse; 16 | import com.sparkpost.resources.ResourceSubAccountCrud; 17 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 18 | import com.sparkpost.transport.IRestConnection; 19 | import com.sparkpost.transport.RestConnection; 20 | 21 | public class SubaccountCRUDSample extends SparkPostBaseApp { 22 | 23 | private static final Logger logger = LogManager.getLogger(SubaccountCRUDSample.class); 24 | 25 | private Client client; 26 | 27 | public static void main(String[] args) throws SparkPostException, IOException { 28 | Configurator.setRootLevel(Level.DEBUG); 29 | 30 | SubaccountCRUDSample sample = new SubaccountCRUDSample(); 31 | sample.runApp(); 32 | 33 | } 34 | 35 | private void runApp() throws SparkPostException, IOException { 36 | this.client = this.newConfiguredClient(); 37 | Integer subaccountId = creatSubAccount(); 38 | 39 | } 40 | 41 | /** 42 | * Demonstrates how create subaccounts in SparkPost 43 | * 44 | * @throws SparkPostException 45 | */ 46 | public Integer creatSubAccount() throws SparkPostException { 47 | if (logger.isDebugEnabled()) { 48 | logger.debug("creatSubAccount()"); 49 | } 50 | SubaccountInfo subaccountInfo = new SubaccountInfo(); 51 | 52 | subaccountInfo.setName("Test"); 53 | subaccountInfo.setSetupApiKey(true); 54 | subaccountInfo.addKeyGrant(SubaccountInfo.SMTP_INJECTION_GRANT); 55 | 56 | IRestConnection connection = new RestConnection(this.client, getEndPoint()); 57 | SubaccountCreateResponse response = ResourceSubAccountCrud.create(connection, subaccountInfo); 58 | 59 | if (logger.isDebugEnabled()) { 60 | logger.debug("Create Subaccount Response: " + response); 61 | } 62 | 63 | return response.getResults().getId(); 64 | 65 | } 66 | 67 | public void getSubaccountInfo(Integer id) throws SparkPostException { 68 | if (logger.isDebugEnabled()) { 69 | logger.debug("getSubaccountInfo()"); 70 | } 71 | 72 | IRestConnection connection = new RestConnection(this.client, getEndPoint()); 73 | SubaccountCreateResponse response = ResourceSubAccountCrud.get(connection, id); 74 | 75 | if (logger.isDebugEnabled()) { 76 | logger.debug("Create Subaccount Response: " + response); 77 | } 78 | 79 | } 80 | 81 | public void sendEmail(String templateName, List recipients) { 82 | if (logger.isDebugEnabled()) { 83 | logger.debug("sendEmail(...)"); 84 | } 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/OptionsAttributesTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class OptionsAttributesTest { 16 | 17 | private static final String OPTIONS_ATTRIBUTE_JSON = "{\n" 18 | + " \"start_time\": \"some start time\",\n" 19 | + " \"open_tracking\": true,\n" 20 | + " \"click_tracking\": true,\n" 21 | + " \"transactional\": true,\n" 22 | + " \"sandbox\": true,\n" 23 | + " \"skip_suppression\": true,\n" 24 | + " \"ip_pool\":\"sp_shared\"\n" 25 | + "}"; 26 | 27 | @BeforeClass 28 | public static void setUpClass() { 29 | Configurator.setRootLevel(Level.DEBUG); 30 | } 31 | 32 | @AfterClass 33 | public static void tearDownClass() { 34 | } 35 | 36 | @Before 37 | public void setUp() { 38 | } 39 | 40 | @After 41 | public void tearDown() { 42 | } 43 | 44 | /** 45 | * 46 | */ 47 | @Test 48 | public void testDecodeOptionsAttributes() { 49 | Gson gson = new Gson(); 50 | OptionsAttributes optionsAttributes = gson.fromJson(OPTIONS_ATTRIBUTE_JSON, OptionsAttributes.class); 51 | Assert.assertNotNull(optionsAttributes); 52 | 53 | Assert.assertEquals(optionsAttributes.getStartTime(), "some start time"); 54 | Assert.assertTrue(optionsAttributes.getClickTracking()); 55 | Assert.assertTrue(optionsAttributes.getOpenTracking()); 56 | Assert.assertTrue(optionsAttributes.getSkipSuppression()); 57 | Assert.assertEquals(optionsAttributes.getIpPool(), "sp_shared"); 58 | Assert.assertTrue(optionsAttributes.getTransactional()); 59 | Assert.assertTrue(optionsAttributes.getSandbox()); 60 | 61 | } 62 | 63 | /** 64 | * 65 | */ 66 | @Test 67 | public void testOptionsAttributesRoundtrip() { 68 | Gson gson = new Gson(); 69 | OptionsAttributes optionsAttributes = gson.fromJson(OPTIONS_ATTRIBUTE_JSON, OptionsAttributes.class); 70 | Assert.assertNotNull(optionsAttributes); 71 | 72 | String optionsAttributes_json = optionsAttributes.toJson(); 73 | OptionsAttributes optionsAttributes2 = gson.fromJson(optionsAttributes_json, OptionsAttributes.class); 74 | 75 | Assert.assertEquals(optionsAttributes.getStartTime(), optionsAttributes2.getStartTime()); 76 | Assert.assertEquals(optionsAttributes.getClickTracking(), optionsAttributes2.getClickTracking()); 77 | Assert.assertEquals(optionsAttributes.getOpenTracking(), optionsAttributes2.getOpenTracking()); 78 | Assert.assertEquals(optionsAttributes.getSkipSuppression(), optionsAttributes2.getSkipSuppression()); 79 | Assert.assertEquals(optionsAttributes.getTransactional(), optionsAttributes2.getTransactional()); 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/StatusAttributesTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class StatusAttributesTest { 16 | 17 | private String STATUS_ATTRIBUTES_JSON = "{\n" 18 | + " \"ownership_verified\": true,\n" 19 | + " \"spf_status\": \"pending\",\n" 20 | + " \"abuse_at_status\": \"pending\",\n" 21 | + " \"dkim_status\": \"pending\",\n" 22 | + " \"compliance_status\": \"pending\",\n" 23 | + " \"postmaster_at_status\": \"pending\"\n" 24 | + "}"; 25 | 26 | @BeforeClass 27 | public static void setUpClass() { 28 | Configurator.setRootLevel(Level.DEBUG); 29 | } 30 | 31 | @AfterClass 32 | public static void tearDownClass() { 33 | } 34 | 35 | @Before 36 | public void setUp() { 37 | } 38 | 39 | @After 40 | public void tearDown() { 41 | } 42 | 43 | /** 44 | * 45 | */ 46 | @Test 47 | public void testDecodeStatusAttributes() { 48 | Gson gson = new Gson(); 49 | StatusAttributes statusAttrbutes = gson.fromJson(this.STATUS_ATTRIBUTES_JSON, StatusAttributes.class); 50 | Assert.assertNotNull(statusAttrbutes); 51 | 52 | Assert.assertTrue(statusAttrbutes.getOwnershipVerified()); 53 | Assert.assertEquals(statusAttrbutes.getSpfStatus(), "pending"); 54 | Assert.assertEquals(statusAttrbutes.getAbuseAtStatus(), "pending"); 55 | Assert.assertEquals(statusAttrbutes.getDkimStatus(), "pending"); 56 | Assert.assertEquals(statusAttrbutes.getComplianceStatus(), "pending"); 57 | Assert.assertEquals(statusAttrbutes.getPostmasterAtStatus(), "pending"); 58 | } 59 | 60 | /** 61 | * 62 | */ 63 | @Test 64 | public void testStatusAttributesRoundtrip() { 65 | Gson gson = new Gson(); 66 | StatusAttributes statusAttributes = gson.fromJson(this.STATUS_ATTRIBUTES_JSON, StatusAttributes.class); 67 | Assert.assertNotNull(statusAttributes); 68 | 69 | String StatusAttributes_json = statusAttributes.toJson(); 70 | StatusAttributes statusAttributes2 = gson.fromJson(StatusAttributes_json, StatusAttributes.class); 71 | 72 | Assert.assertEquals(statusAttributes.getOwnershipVerified(), statusAttributes2.getOwnershipVerified()); 73 | Assert.assertEquals(statusAttributes.getSpfStatus(), statusAttributes2.getSpfStatus()); 74 | Assert.assertEquals(statusAttributes.getAbuseAtStatus(), statusAttributes2.getAbuseAtStatus()); 75 | Assert.assertEquals(statusAttributes.getDkimStatus(), statusAttributes2.getDkimStatus()); 76 | Assert.assertEquals(statusAttributes.getComplianceStatus(), statusAttributes2.getComplianceStatus()); 77 | Assert.assertEquals(statusAttributes.getPostmasterAtStatus(), statusAttributes2.getPostmasterAtStatus()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/resources/ResourceMessageEvents.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.resources; 3 | 4 | import java.net.URI; 5 | import java.net.URISyntaxException; 6 | 7 | import com.sparkpost.exception.SparkPostException; 8 | import com.sparkpost.model.MessageEventsQueryBuilder; 9 | import com.sparkpost.model.responses.MessageEventsResponse; 10 | import com.sparkpost.model.responses.Response; 11 | import com.sparkpost.transport.IRestConnection; 12 | 13 | /** 14 | * Resource collection that is a 1-to-1 match to the Metrics SparkPost API.
15 | *
16 | * See Message Events 17 | * API 18 | */ 19 | public class ResourceMessageEvents { 20 | 21 | public static MessageEventsResponse searchMessageEvents(IRestConnection conn) throws SparkPostException { 22 | return ResourceMessageEvents.searchMessageEvents(conn, 0, null); 23 | } 24 | 25 | public static MessageEventsResponse searchMessageEvents(IRestConnection conn, int perPage) throws SparkPostException { 26 | return ResourceMessageEvents.searchMessageEvents(conn, perPage, null); 27 | } 28 | 29 | public static MessageEventsResponse searchMessageEvents(IRestConnection conn, MessageEventsQueryBuilder queryBuilder) throws SparkPostException { 30 | return ResourceMessageEvents.searchMessageEvents(conn, 0, queryBuilder); 31 | } 32 | 33 | public static MessageEventsResponse searchMessageEvents(IRestConnection conn, int perPage, MessageEventsQueryBuilder queryBuilder) 34 | throws SparkPostException { 35 | Endpoint ep = new Endpoint("events/message"); 36 | if (queryBuilder != null) { 37 | queryBuilder.buildQuery(ep); 38 | } 39 | 40 | if (perPage > 0) { 41 | ep.addParam("per_page", perPage); 42 | } 43 | Response response = conn.get(ep); 44 | 45 | MessageEventsResponse messageResponse = MessageEventsResponse.decode(response, MessageEventsResponse.class); 46 | return messageResponse; 47 | } 48 | 49 | public static MessageEventsResponse nextMessageEvents(IRestConnection conn, MessageEventsResponse page) throws SparkPostException { 50 | if (page.hasNext() == false) { 51 | return null; 52 | } 53 | 54 | String next = page.nextPageUrl(); 55 | try { 56 | URI uri = new URI(next); 57 | 58 | String path = uri.getPath(); 59 | path = path.replaceFirst("/api/v1/", ""); 60 | Endpoint ep = new Endpoint(path); 61 | 62 | String query = uri.getQuery(); 63 | if (query.length() > 0) { 64 | String[] split = query.split("&"); 65 | for (String element : split) { 66 | String[] fields = element.split("=", 2); 67 | ep.addParam(fields[0], fields[1]); 68 | } 69 | } 70 | 71 | Response response = conn.get(ep); 72 | 73 | MessageEventsResponse messageResponse = MessageEventsResponse.decode(response, MessageEventsResponse.class); 74 | return messageResponse; 75 | } catch (URISyntaxException e) { 76 | throw new SparkPostException(e); 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/model/AddressAttributesTests.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import org.apache.logging.log4j.Level; 5 | import org.apache.logging.log4j.core.config.Configurator; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import com.google.gson.Gson; 14 | 15 | public class AddressAttributesTests { 16 | 17 | private String SIMPLE_ADDRESS_JSON = "{" + "\"email\" : \"someone@example.com\"," + "\"name\" : \"First Last\"" + "}"; 18 | 19 | private String SIMPLE_ADDRESS_JSON_2 = "{" 20 | + "\"email\" : \"someone@example.com\"," 21 | + "\"header_to\" : \"some header to\"," 22 | + "\"name\" : \"First Last\"" 23 | + "}"; 24 | 25 | @BeforeClass 26 | public static void setUpClass() { 27 | Configurator.setRootLevel(Level.DEBUG); 28 | } 29 | 30 | @AfterClass 31 | public static void tearDownClass() { 32 | } 33 | 34 | @Before 35 | public void setUp() { 36 | } 37 | 38 | @After 39 | public void tearDown() { 40 | } 41 | 42 | /** 43 | * Check headerto is null if not sent 44 | */ 45 | @Test 46 | public void testSimpleDecodeAddress() { 47 | Gson gson = new Gson(); 48 | AddressAttributes addressAttributes = gson.fromJson(this.SIMPLE_ADDRESS_JSON, AddressAttributes.class); 49 | 50 | Assert.assertNull(addressAttributes.getHeaderTo()); 51 | Assert.assertEquals(addressAttributes.getEmail(), "someone@example.com"); 52 | Assert.assertEquals(addressAttributes.getName(), "First Last"); 53 | } 54 | 55 | /** 56 | * Make sure all fields are decoded 57 | */ 58 | @Test 59 | public void testSimpleDecodeAddress_2() { 60 | Gson gson = new Gson(); 61 | AddressAttributes addressAttributes = gson.fromJson(this.SIMPLE_ADDRESS_JSON_2, AddressAttributes.class); 62 | 63 | Assert.assertEquals(addressAttributes.getHeaderTo(), "some header to"); 64 | Assert.assertEquals(addressAttributes.getEmail(), "someone@example.com"); 65 | Assert.assertEquals(addressAttributes.getName(), "First Last"); 66 | } 67 | 68 | /** 69 | * Make sure a decoded and encoded AdressAttribute are equal is represent same data 70 | */ 71 | @Test 72 | public void testAddressRoundTrip() { 73 | Gson gson = new Gson(); 74 | AddressAttributes addressAttributes = gson.fromJson(this.SIMPLE_ADDRESS_JSON_2, AddressAttributes.class); 75 | 76 | Assert.assertEquals(addressAttributes.getHeaderTo(), "some header to"); 77 | Assert.assertEquals(addressAttributes.getEmail(), "someone@example.com"); 78 | Assert.assertEquals(addressAttributes.getName(), "First Last"); 79 | 80 | String json = addressAttributes.toJson(); 81 | AddressAttributes anotherAddressAttributes = gson.fromJson(json, AddressAttributes.class); 82 | 83 | Assert.assertEquals(addressAttributes.getEmail(), anotherAddressAttributes.getEmail()); 84 | Assert.assertEquals(addressAttributes.getName(), anotherAddressAttributes.getName()); 85 | Assert.assertEquals(addressAttributes.getHeaderTo(), anotherAddressAttributes.getHeaderTo()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/src/main/java/com/sparkpost/samples/CreateRecipientListSample.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.samples; 3 | 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.apache.logging.log4j.Level; 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | import org.apache.logging.log4j.core.config.Configurator; 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.RecipientList; 18 | import com.sparkpost.model.responses.Response; 19 | import com.sparkpost.resources.ResourceRecipientLists; 20 | import com.sparkpost.sdk.samples.helpers.SparkPostBaseApp; 21 | import com.sparkpost.transport.IRestConnection; 22 | import com.sparkpost.transport.RestConnection; 23 | 24 | /** 25 | * A recipient list is a collection of recipients that can be used in a 26 | * transmission. The Recipient List API provides the means to manage recipient 27 | * lists. When creating a new transmission using the Transmissions API, the 28 | * recipients may be submitted "inline" as part of the transmission data, or a 29 | * stored recipient list id attribute can be specified.The Recipient List API 30 | * operates on lists as a whole and does not currently support management of 31 | * individual recipients. 32 | * See: 33 | * https://www.sparkpost.com/api#/reference/recipient-lists/create-a-recipient- 34 | * list 35 | */ 36 | public class CreateRecipientListSample extends SparkPostBaseApp { 37 | 38 | static final Logger logger = LogManager.getLogger(CreateTemplateSimple.class); 39 | 40 | private Client client; 41 | 42 | public static void main(String[] args) throws SparkPostException, IOException { 43 | Configurator.setRootLevel(Level.DEBUG); 44 | 45 | CreateRecipientListSample app = new CreateRecipientListSample(); 46 | app.runApp(); 47 | } 48 | 49 | private void runApp() throws SparkPostException, IOException { 50 | 51 | RecipientList recipientList = createRecipientList(); 52 | 53 | this.client = this.newConfiguredClient(); 54 | IRestConnection connection = new RestConnection(this.client, getEndPoint()); 55 | 56 | Response response = ResourceRecipientLists.create(connection, 0, recipientList); 57 | 58 | if (logger.isDebugEnabled()) { 59 | logger.debug("Create Recipient List Response: " + response); 60 | } 61 | 62 | } 63 | 64 | private RecipientList createRecipientList() { 65 | RecipientList recipientList = new RecipientList(); 66 | 67 | recipientList.setName("100 List"); 68 | recipientList.setDescription("Demonstration of storing a recipient list on the server"); 69 | 70 | List recipients = new ArrayList(); 71 | // Populate our recipient list attributes 72 | for (String recipient : getTestRecipients()) { 73 | RecipientAttributes attributes = new RecipientAttributes(); 74 | attributes.setAddress(new AddressAttributes(recipient)); 75 | recipients.add(attributes); 76 | } 77 | 78 | recipientList.setRecipients(recipients); 79 | 80 | return recipientList; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/main/java/com/sparkpost/model/RecipientList.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.model; 3 | 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | import com.yepher.jsondoc.annotations.Description; 9 | 10 | import lombok.Data; 11 | import lombok.EqualsAndHashCode; 12 | 13 | /** 14 | * A recipient list is a collection of recipients that can be used in a 15 | * transmission. The Recipient List API provides the means to manage recipient 16 | * lists. When creating a new transmission using the Transmissions API, the 17 | * recipients may be submitted "inline" as part of the transmission data, or a 18 | * stored recipient list id attribute can be specified.The Recipient List API 19 | * operates on lists as a whole and does not currently support management of 20 | * individual recipients.Recipient List Attributes 21 | */ 22 | @Data 23 | @EqualsAndHashCode(callSuper = true) 24 | public class RecipientList extends Base { 25 | 26 | /** 27 | * Short, unique, recipient list identifier 28 | * If an id is not specified, one is generated. Maximum length - 64 bytes 29 | */ 30 | @Description(value = "Short, unique, recipient list identifier. Maximum length - 64 bytes", sample = {""}) 31 | private String id = null; 32 | 33 | /** 34 | * Short, pretty/readable recipient list display name, not required to be unique 35 | * If a name is not specified, then defaults to the same value as id. Maximum length - 64 bytes 36 | */ 37 | @Description(value = " Short, pretty/readable recipient list display name, not required to be unique. Maximum length - 64 bytes", sample = {""}) 38 | private String name = null; 39 | 40 | /** 41 | * Detailed description of the recipient list 42 | * Maximum length - 1024 bytes 43 | */ 44 | @Description(value = "Detailed description of the recipient list. Maximum length - 1024 bytes", sample = {""}) 45 | private String description = null; 46 | 47 | /** 48 | * Recipient list attribute object 49 | * This JSON object allows users to store arbitrary metadata related to this list. This data is not used by the API. It is only for the user. 50 | */ 51 | @Description(value = " Recipient list attribute object", sample = {""}) 52 | private Map attributes = null; 53 | 54 | /** 55 | * List of recipient objects 56 | * For a full description, see the Recipient Attributes. 57 | */ 58 | @Description(value = " List of recipient objects", sample = {""}) 59 | private List recipients = null; 60 | 61 | @Description(value = "The number of recipients in this list that have been accepted", sample = {""}) 62 | @SerializedName("total_accepted_recipients") 63 | private int totalAcceptedRecipients; 64 | 65 | @Description(value = "The number of recipients in this list that have been rejected", sample = {""}) 66 | @SerializedName("total_rejected_recipients") 67 | private int totalRejectedRecipients; 68 | 69 | /** 70 | * Returns object that can be used to create transmission. 71 | * 72 | * @return StoredRecipientList object 73 | */ 74 | public StoredRecipientList asStoredRecipientList() { 75 | 76 | StoredRecipientList storedRecipientList = new StoredRecipientList(); 77 | storedRecipientList.setListId(this.getId()); 78 | return storedRecipientList; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /libs/sparkpost-lib/src/test/java/com/sparkpost/testhelpers/StubRestConnection.java: -------------------------------------------------------------------------------- 1 | 2 | package com.sparkpost.testhelpers; 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import com.sparkpost.exception.SparkPostException; 8 | import com.sparkpost.model.responses.Response; 9 | import com.sparkpost.resources.Endpoint; 10 | import com.sparkpost.transport.IRestConnection; 11 | 12 | public class StubRestConnection implements IRestConnection { 13 | 14 | private String path; 15 | 16 | private Endpoint endpoint; 17 | 18 | private final Map extraHeaders = new HashMap(); 19 | 20 | private String json; 21 | 22 | private Response response; 23 | 24 | private boolean wasGet; 25 | 26 | private boolean wasPost; 27 | 28 | private boolean wasPut; 29 | 30 | private boolean wasDelete; 31 | 32 | public StubRestConnection(Response response) { 33 | this.response = response; 34 | } 35 | 36 | @Override 37 | public Response get(Endpoint endpoint) throws SparkPostException { 38 | this.endpoint = endpoint; 39 | this.wasGet = true; 40 | return this.response; 41 | } 42 | 43 | @Override 44 | public Response post(Endpoint endpoint, String json) throws SparkPostException { 45 | this.endpoint = endpoint; 46 | this.wasPost = true; 47 | this.json = json; 48 | return this.response; 49 | } 50 | 51 | @Override 52 | public Response put(Endpoint endpoint, String json) throws SparkPostException { 53 | this.endpoint = endpoint; 54 | this.wasPut = true; 55 | this.json = json; 56 | return this.response; 57 | } 58 | 59 | @Override 60 | public Response delete(Endpoint endpoint) throws SparkPostException { 61 | this.endpoint = endpoint; 62 | this.wasDelete = true; 63 | return this.response; 64 | } 65 | 66 | public String getPath() { 67 | return this.path; 68 | } 69 | 70 | public void setPath(String path) { 71 | this.path = path; 72 | } 73 | 74 | public Endpoint getEndpoint() { 75 | return this.endpoint; 76 | } 77 | 78 | public void setEndpoint(Endpoint endpoint) { 79 | this.endpoint = endpoint; 80 | } 81 | 82 | public String getRequestUri() { 83 | if (this.endpoint != null && this.endpoint.toString() != null) { 84 | return this.endpoint.toString(); 85 | } 86 | return this.path; 87 | } 88 | 89 | public String getJson() { 90 | return this.json; 91 | } 92 | 93 | public void setJson(String json) { 94 | this.json = json; 95 | } 96 | 97 | public Response getResponse() { 98 | return this.response; 99 | } 100 | 101 | public void setResponse(Response response) { 102 | this.response = response; 103 | } 104 | 105 | public boolean wasGet() { 106 | return this.wasGet; 107 | } 108 | 109 | public boolean wasPost() { 110 | return this.wasPost; 111 | } 112 | 113 | public boolean wasPut() { 114 | return this.wasPut; 115 | } 116 | 117 | public boolean wasDelete() { 118 | return this.wasDelete; 119 | } 120 | 121 | @Override 122 | public void addHeader(String key, String value) { 123 | this.extraHeaders.put(key, value); 124 | 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /apps/sparkpost-samples-app/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.sparkpost 6 | apps 7 | 0.27 8 | 9 | sparkpost-samples-app 10 | Example use SparkPost library 11 | /apps/sparkpost-samples-app/ 12 | jar 13 | 14 | 15 | 16 | com.sparkpost 17 | sparkpost-lib 18 | 19 | 20 | 21 | org.apache.logging.log4j 22 | log4j-core 23 | 24 | 25 | com.google.code.gson 26 | gson 27 | 2.3.1 28 | 29 | 30 | org.apache.httpcomponents 31 | httpclient 32 | 4.5.13 33 | 34 | 37 | 38 | org.jmock 39 | jmock-junit4 40 | test 41 | 42 | 43 | junit 44 | junit 45 | test 46 | 47 | 48 | org.projectlombok 49 | lombok 50 | provided 51 | 52 | 53 | commons-io 54 | commons-io 55 | 56 | 57 | 58 | org.json 59 | json 60 | 20170516 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.apache.maven.plugins 68 | maven-source-plugin 69 | 70 | 71 | attach-sources 72 | 73 | jar 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-shade-plugin 83 | 2.3 84 | 85 | 86 | 87 | package 88 | 89 | shade 90 | 91 | 92 | 93 | 94 | 96 | com.sparkpost.samples.DeliverabilityMetricsSample 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | --------------------------------------------------------------------------------