diff --git a/src/main/java/com/sendgrid/APICallback.java b/src/main/java/com/sendgrid/APICallback.java index 8504f41c..101052d6 100644 --- a/src/main/java/com/sendgrid/APICallback.java +++ b/src/main/java/com/sendgrid/APICallback.java @@ -1,19 +1,22 @@ package com.sendgrid; /** - * An interface describing a callback mechanism for the - * asynchronous, rate limit aware API connection. + * An interface describing a callback mechanism for the asynchronous, rate limit aware API + * connection. */ public interface APICallback { - /** - * Callback method in case of an error. - * @param ex the error that was thrown. - */ - void error(Exception ex); - /** - * Callback method in case of a valid response. - * @param response the valid response. - */ - void response(Response response); + /** + * Callback method in case of an error. + * + * @param ex the error that was thrown. + */ + void error(Exception ex); + + /** + * Callback method in case of a valid response. + * + * @param response the valid response. + */ + void response(Response response); } diff --git a/src/main/java/com/sendgrid/RateLimitException.java b/src/main/java/com/sendgrid/RateLimitException.java index 4912ac92..7a2570ac 100644 --- a/src/main/java/com/sendgrid/RateLimitException.java +++ b/src/main/java/com/sendgrid/RateLimitException.java @@ -1,36 +1,40 @@ package com.sendgrid; /** - * An exception thrown when the maximum number of retries - * have occurred, and the API calls are still rate limited. + * An exception thrown when the maximum number of retries have occurred, and the API calls are still + * rate limited. */ public class RateLimitException extends Exception { - private final Request request; - private final int retryCount; - /** - * Construct a new exception. - * @param request the originating request object. - * @param retryCount the number of times a retry was attempted. - */ - public RateLimitException(Request request, int retryCount) { - this.request = request; - this.retryCount = retryCount; - } + private final Request request; + private final int retryCount; - /** - * Get the originating request object. - * @return the request object. - */ - public Request getRequest() { - return this.request; - } + /** + * Construct a new exception. + * + * @param request the originating request object. + * @param retryCount the number of times a retry was attempted. + */ + public RateLimitException(Request request, int retryCount) { + this.request = request; + this.retryCount = retryCount; + } - /** - * Get the number of times the action was attemted. - * @return the retry count. - */ - public int getRetryCount() { - return this.retryCount; - } + /** + * Get the originating request object. + * + * @return the request object. + */ + public Request getRequest() { + return this.request; + } + + /** + * Get the number of times the action was attemted. + * + * @return the retry count. + */ + public int getRetryCount() { + return this.retryCount; + } } diff --git a/src/main/java/com/sendgrid/SendGrid.java b/src/main/java/com/sendgrid/SendGrid.java index 3c27b313..b248e7af 100644 --- a/src/main/java/com/sendgrid/SendGrid.java +++ b/src/main/java/com/sendgrid/SendGrid.java @@ -3,12 +3,12 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.Executors; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** - * Class Twilio SendGrid allows for quick and easy access to the Twilio SendGrid API. - */ + * The Twilio SendGrid class allows for quick and easy access to the Twilio SendGrid API. + */ public class SendGrid implements SendGridAPI { private static final String VERSION = "3.0.0"; @@ -43,6 +43,7 @@ public class SendGrid implements SendGridAPI { /** * Construct a new Twilio SendGrid API wrapper. + * * @param apiKey is your Twilio SendGrid API Key: https://app.sendgrid.com/settings/api_keys */ public SendGrid(String apiKey) { @@ -52,6 +53,7 @@ public SendGrid(String apiKey) { /** * Construct a new Twilio SendGrid API wrapper. + * * @param apiKey is your Twilio SendGrid API Key: https://app.sendgrid.com/settings/api_keys * @param test is true if you are unit testing */ @@ -62,6 +64,7 @@ public SendGrid(String apiKey, Boolean test) { /** * Construct a new Twilio SendGrid API wrapper. + * * @param apiKey is your Twilio SendGrid API Key: https://app.sendgrid.com/settings/api_keys * @param client the Client to use (allows to customize its configuration) */ @@ -72,6 +75,7 @@ public SendGrid(String apiKey, Client client) { /** * Initialize the client. + * * @param apiKey the user's API key. */ public void initializeSendGrid(String apiKey) { @@ -89,14 +93,16 @@ public void initializeSendGrid(String apiKey) { /** * Retrieve the current library version. + * * @return the current version. */ public String getLibraryVersion() { - return this.VERSION; + return VERSION; } /** * Get the API version. + * * @return the current API versioin (v3 by default). */ public String getVersion() { @@ -105,6 +111,7 @@ public String getVersion() { /** * Set the API version. + * * @param version the new version. */ public void setVersion(String version) { @@ -113,6 +120,7 @@ public void setVersion(String version) { /** * Obtain the request headers. + * * @return the request headers. */ public Map getRequestHeaders() { @@ -121,6 +129,7 @@ public Map getRequestHeaders() { /** * Add a new request header. + * * @param key the header key. * @param value the header value. * @return the new set of request headers. @@ -132,6 +141,7 @@ public Map addRequestHeader(String key, String value) { /** * Remove a request header. + * * @param key the header key to remove. * @return the new set of request headers. */ @@ -142,6 +152,7 @@ public Map removeRequestHeader(String key) { /** * Get the Twilio SendGrid host (api.sendgrid.com by default). + * * @return the Twilio SendGrid host. */ public String getHost() { @@ -150,6 +161,7 @@ public String getHost() { /** * Set the Twilio SendGrid host. + * * @param host the new Twilio SendGrid host. */ public void setHost(String host) { @@ -157,8 +169,8 @@ public void setHost(String host) { } /** - * Get the maximum number of retries on a rate limit response. - * The default is 5. + * Get the maximum number of retries on a rate limit response. The default is 5. + * * @return the number of retries on a rate limit. */ public int getRateLimitRetry() { @@ -167,6 +179,7 @@ public int getRateLimitRetry() { /** * Set the maximum number of retries on a rate limit response. + * * @param rateLimitRetry the maximum retry count. */ public void setRateLimitRetry(int rateLimitRetry) { @@ -174,9 +187,9 @@ public void setRateLimitRetry(int rateLimitRetry) { } /** - * Get the duration of time (in milliseconds) to sleep between - * consecutive rate limit retries. The Twilio SendGrid API enforces - * the rate limit to the second. The default value is 1.1 seconds. + * Get the duration of time (in milliseconds) to sleep between consecutive rate limit retries. The + * Twilio SendGrid API enforces the rate limit to the second. The default value is 1.1 seconds. + * * @return the sleep duration. */ public int getRateLimitSleep() { @@ -184,8 +197,8 @@ public int getRateLimitSleep() { } /** - * Set the duration of time (in milliseconds) to sleep between - * consecutive rate limit retries. + * Set the duration of time (in milliseconds) to sleep between consecutive rate limit retries. + * * @param rateLimitSleep the sleep duration. */ public void setRateLimitSleep(int rateLimitSleep) { @@ -194,6 +207,7 @@ public void setRateLimitSleep(int rateLimitSleep) { /** * Impersonate subuser for subsequent requests + * * @param subuser the subuser to be impersonated */ public void addImpersonateSubuser(String subuser) { @@ -211,14 +225,16 @@ public void removeImpersonateSubuser() { /** * Get the impersonated subuser or null if empty + * * @return the impersonated subuser */ public String getImpersonateSubuser() { - return this.subuser; + return this.subuser; } /** * Makes the call to the Twilio SendGrid API, override this method for testing. + * * @param request the request to make. * @return the response object. * @throws IOException in case of a network error. @@ -229,6 +245,7 @@ public Response makeCall(Request request) throws IOException { /** * Class api sets up the request to the Twilio SendGrid API, this is main interface. + * * @param request the request object. * @return the response object. * @throws IOException in case of a network error. @@ -250,9 +267,9 @@ public Response api(Request request) throws IOException { } /** - * Attempt an API call. This method executes the API call asynchronously - * on an internal thread pool. If the call is rate limited, the thread - * will retry up to the maximum configured time. + * Attempt an API call. This method executes the API call asynchronously on an internal thread + * pool. If the call is rate limited, the thread will retry up to the maximum configured time. + * * @param request the API request. */ public void attempt(Request request) { @@ -267,10 +284,10 @@ public void response(Response r) { } /** - * Attempt an API call. This method executes the API call asynchronously - * on an internal thread pool. If the call is rate limited, the thread - * will retry up to the maximum configured time. The supplied callback - * will be called in the event of an error, or a successful response. + * Attempt an API call. This method executes the API call asynchronously on an internal thread + * pool. If the call is rate limited, the thread will retry up to the maximum configured time. The + * supplied callback will be called in the event of an error, or a successful response. + * * @param request the API request. * @param callback the callback. */ diff --git a/src/main/java/com/sendgrid/SendGridAPI.java b/src/main/java/com/sendgrid/SendGridAPI.java index aa9583a2..5110e8ca 100644 --- a/src/main/java/com/sendgrid/SendGridAPI.java +++ b/src/main/java/com/sendgrid/SendGridAPI.java @@ -7,14 +7,14 @@ public interface SendGridAPI { /** * Initializes Twilio SendGrid - * + * * @param apiKey is your Twilio SendGrid API Key: https://app.sendgrid.com/settings/api_keys */ void initializeSendGrid(String apiKey); /** * Returns the library version - * + * * @return the library version. */ String getLibraryVersion(); @@ -28,20 +28,21 @@ public interface SendGridAPI { /** * Sets the version. - * + * * @param version the Twilio SendGrid version. */ void setVersion(String version); /** * Gets the request headers. + * * @return returns a map of request headers. */ Map getRequestHeaders(); /** * Adds a request headers. - * + * * @param key the key * @param value the value * @return returns a map of request headers. @@ -50,7 +51,7 @@ public interface SendGridAPI { /** * Removes a request headers. - * + * * @param key the key * @return returns a map of request headers. */ @@ -58,22 +59,21 @@ public interface SendGridAPI { /** * Gets the host. - * + * * @return returns the host. */ String getHost(); /** * Sets the host. - * + * * @param host the host to set */ void setHost(String host); /** - * Class makeCall makes the call to the Twilio SendGrid API, override this method for - * testing. - * + * Class makeCall makes the call to the Twilio SendGrid API, override this method for testing. + * * @param request the request * @return returns a response. * @throws IOException in case of network or marshal error. @@ -82,7 +82,7 @@ public interface SendGridAPI { /** * Class api sets up the request to the Twilio SendGrid API, this is main interface. - * + * * @param request the request * @return returns a response. * @throws IOException in case of network or marshal error. diff --git a/src/main/java/com/sendgrid/helpers/mail/Mail.java b/src/main/java/com/sendgrid/helpers/mail/Mail.java index 29dd2325..24eb19de 100644 --- a/src/main/java/com/sendgrid/helpers/mail/Mail.java +++ b/src/main/java/com/sendgrid/helpers/mail/Mail.java @@ -5,8 +5,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.sendgrid.helpers.mail.objects.*; - +import com.sendgrid.helpers.mail.objects.ASM; +import com.sendgrid.helpers.mail.objects.Attachments; +import com.sendgrid.helpers.mail.objects.Content; +import com.sendgrid.helpers.mail.objects.Email; +import com.sendgrid.helpers.mail.objects.MailSettings; +import com.sendgrid.helpers.mail.objects.Personalization; +import com.sendgrid.helpers.mail.objects.TrackingSettings; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -14,95 +19,106 @@ import java.util.Map; /** - * Class Mail builds an object that sends an email through Twilio SendGrid. - * Note that this object is not thread safe. + * Class Mail builds an object that sends an email through Twilio SendGrid. Note that this object is + * not thread safe. */ @JsonInclude(Include.NON_DEFAULT) public class Mail { /** The email's from field. */ - @JsonProperty("from") public Email from; + @JsonProperty("from") + public Email from; - /** The email's subject line. This is the global, or - * “message level”, subject of your email. This may - * be overridden by personalizations[x].subject. + /** + * The email's subject line. This is the global, or “message level”, subject of your email. This + * may be overridden by personalizations[x].subject. */ - @JsonProperty("subject") public String subject; + @JsonProperty("subject") + public String subject; - /** - * The email's personalization. Each object within - * personalizations can be thought of as an envelope - * - it defines who should receive an individual message - * and how that message should be handled. + /** + * The email's personalization. Each object within personalizations can be thought of as an + * envelope - it defines who should receive an individual message and how that message should be + * handled. */ - @JsonProperty("personalizations") public List personalization; + @JsonProperty("personalizations") + public List personalization; /** The email's content. */ - @JsonProperty("content") public List content; + @JsonProperty("content") + public List content; /** The email's attachments. */ - @JsonProperty("attachments") public List attachments; + @JsonProperty("attachments") + public List attachments; /** The email's template ID. */ - @JsonProperty("template_id") public String templateId; + @JsonProperty("template_id") + public String templateId; - /** - * The email's sections. An object of key/value pairs that - * define block sections of code to be used as substitutions. + /** + * The email's sections. An object of key/value pairs that define block sections of code to be + * used as substitutions. */ - @JsonProperty("sections") public Map sections; + @JsonProperty("sections") + public Map sections; /** The email's headers. */ - @JsonProperty("headers") public Map headers; + @JsonProperty("headers") + public Map headers; /** The email's categories. */ - @JsonProperty("categories") public List categories; - - /** - * The email's custom arguments. Values that are specific to - * the entire send that will be carried along with the email - * and its activity data. Substitutions will not be made on - * custom arguments, so any string that is entered into this - * parameter will be assumed to be the custom argument that - * you would like to be used. This parameter is overridden by - * personalizations[x].custom_args if that parameter has been - * defined. Total custom args size may not exceed 10,000 bytes. - */ - @JsonProperty("custom_args") public Map customArgs; - - /** - * A unix timestamp allowing you to specify when you want - * your email to be delivered. This may be overridden by - * the personalizations[x].send_at parameter. Scheduling - * more than 72 hours in advance is forbidden. - */ - @JsonProperty("send_at") public long sendAt; - - /** - * This ID represents a batch of emails to be sent at the - * same time. Including a batch_id in your request allows - * you include this email in that batch, and also enables - * you to cancel or pause the delivery of that batch. For - * more information, see https://sendgrid.com/docs/API_Reference/Web_API_v3/cancel_schedule_send. - */ - @JsonProperty("batch_id") public String batchId; + @JsonProperty("categories") + public List categories; + + /** + * The email's custom arguments. Values that are specific to the entire send that will be carried + * along with the email and its activity data. Substitutions will not be made on custom arguments, + * so any string that is entered into this parameter will be assumed to be the custom argument + * that you would like to be used. This parameter is overridden by personalizations[x].custom_args + * if that parameter has been defined. Total custom args size may not exceed 10,000 bytes. + */ + @JsonProperty("custom_args") + public Map customArgs; + + /** + * A unix timestamp allowing you to specify when you want your email to be delivered. This may be + * overridden by the personalizations[x].send_at parameter. Scheduling more than 72 hours in + * advance is forbidden. + */ + @JsonProperty("send_at") + public long sendAt; + + /** + * This ID represents a batch of emails to be sent at the same time. Including a batch_id in your + * request allows you include this email in that batch, and also enables you to cancel or pause + * the delivery of that batch. For more information, see https://sendgrid.com/docs/API_Reference/Web_API_v3/cancel_schedule_send. + */ + @JsonProperty("batch_id") + public String batchId; /** The email's unsubscribe handling object. */ - @JsonProperty("asm") public ASM asm; + @JsonProperty("asm") + public ASM asm; /** The email's IP pool name. */ - @JsonProperty("ip_pool_name") public String ipPoolId; + @JsonProperty("ip_pool_name") + public String ipPoolId; /** The email's mail settings. */ - @JsonProperty("mail_settings") public MailSettings mailSettings; + @JsonProperty("mail_settings") + public MailSettings mailSettings; /** The email's tracking settings. */ - @JsonProperty("tracking_settings") public TrackingSettings trackingSettings; + @JsonProperty("tracking_settings") + public TrackingSettings trackingSettings; /** The email's reply to address. */ - @JsonProperty("reply_to") public Email replyTo; + @JsonProperty("reply_to") + public Email replyTo; private static final ObjectMapper SORTED_MAPPER = new ObjectMapper(); + static { SORTED_MAPPER.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); } @@ -118,17 +134,17 @@ private List addToList(T element, List defaultList) { } } - private Map addToMap(K key, V value, Map defaultMap) { + private Map addToMap(K key, V value, Map defaultMap) { if (defaultMap != null) { defaultMap.put(key, value); return defaultMap; } else { - Map map = new HashMap(); + Map map = new HashMap(); map.put(key, value); return map; } } - + /** Construct a new Mail object. */ public Mail() { return; @@ -136,13 +152,13 @@ public Mail() { /** * Construct a new Mail object. + * * @param from the email's from address. * @param subject the email's subject line. * @param to the email's recipient. * @param content the email's content. */ - public Mail(Email from, String subject, Email to, Content content) - { + public Mail(Email from, String subject, Email to, Content content) { this.setFrom(from); this.setSubject(subject); Personalization personalization = new Personalization(); @@ -153,6 +169,7 @@ public Mail(Email from, String subject, Email to, Content content) /** * Get the email's from address. + * * @return the email's from address. */ @JsonProperty("from") @@ -162,6 +179,7 @@ public Email getFrom() { /** * Set the email's from address. + * * @param from the email's from address. */ public void setFrom(Email from) { @@ -170,6 +188,7 @@ public void setFrom(Email from) { /** * Get the email's subject line. + * * @return the email's subject line. */ @JsonProperty("subject") @@ -179,6 +198,7 @@ public String getSubject() { /** * Set the email's subject line. + * * @param subject the email's subject line. */ public void setSubject(String subject) { @@ -187,6 +207,7 @@ public void setSubject(String subject) { /** * Get the email's unsubscribe handling object (ASM). + * * @return the email's ASM. */ @JsonProperty("asm") @@ -196,6 +217,7 @@ public ASM getASM() { /** * Set the email's unsubscribe handling object (ASM). + * * @param asm the email's ASM. */ public void setASM(ASM asm) { @@ -203,8 +225,9 @@ public void setASM(ASM asm) { } /** - * Get the email's personalizations. Content added to the returned - * list will be included when sent. + * Get the email's personalizations. Content added to the returned list will be included when + * sent. + * * @return the email's personalizations. */ @JsonProperty("personalizations") @@ -214,6 +237,7 @@ public List getPersonalization() { /** * Add a personalizaton to the email. + * * @param personalization a personalization. */ public void addPersonalization(Personalization personalization) { @@ -221,8 +245,8 @@ public void addPersonalization(Personalization personalization) { } /** - * Get the email's content. Content added to the returned list - * will be included when sent. + * Get the email's content. Content added to the returned list will be included when sent. + * * @return the email's content. */ @JsonProperty("content") @@ -232,6 +256,7 @@ public List getContent() { /** * Add content to this email. + * * @param content content to add to this email. */ public void addContent(Content content) { @@ -242,8 +267,9 @@ public void addContent(Content content) { } /** - * Get the email's attachments. Attachments added to the returned - * list will be included when sent. + * Get the email's attachments. Attachments added to the returned list will be included when + * sent. + * * @return the email's attachments. */ @JsonProperty("attachments") @@ -253,6 +279,7 @@ public List getAttachments() { /** * Add attachments to the email. + * * @param attachments attachments to add. */ public void addAttachments(Attachments attachments) { @@ -267,6 +294,7 @@ public void addAttachments(Attachments attachments) { /** * Get the email's template ID. + * * @return the email's template ID. */ @JsonProperty("template_id") @@ -276,6 +304,7 @@ public String getTemplateId() { /** * Set the email's template ID. + * * @param templateId the email's template ID. */ public void setTemplateId(String templateId) { @@ -283,17 +312,18 @@ public void setTemplateId(String templateId) { } /** - * Get the email's sections. Sections added to the returned list - * will be included when sent. + * Get the email's sections. Sections added to the returned list will be included when sent. + * * @return the email's sections. */ @JsonProperty("sections") - public Map getSections() { + public Map getSections() { return sections; } /** * Add a section to the email. + * * @param key the section's key. * @param value the section's value. */ @@ -302,17 +332,18 @@ public void addSection(String key, String value) { } /** - * Get the email's headers. Headers added to the returned list - * will be included when sent. + * Get the email's headers. Headers added to the returned list will be included when sent. + * * @return the email's headers. */ @JsonProperty("headers") - public Map getHeaders() { + public Map getHeaders() { return headers; } /** * Add a header to the email. + * * @param key the header's key. * @param value the header's value. */ @@ -321,8 +352,8 @@ public void addHeader(String key, String value) { } /** - * Get the email's categories. Categories added to the returned list - * will be included when sent. + * Get the email's categories. Categories added to the returned list will be included when sent. + * * @return the email's categories. */ @JsonProperty("categories") @@ -332,6 +363,7 @@ public List getCategories() { /** * Add a category to the email. + * * @param category the category. */ public void addCategory(String category) { @@ -339,17 +371,19 @@ public void addCategory(String category) { } /** - * Get the email's custom arguments. Custom arguments added to the returned list - * will be included when sent. + * Get the email's custom arguments. Custom arguments added to the returned list will be included + * when sent. + * * @return the email's custom arguments. */ @JsonProperty("custom_args") - public Map getCustomArgs() { + public Map getCustomArgs() { return customArgs; } /** * Add a custom argument to the email. + * * @param key argument's key. * @param value the argument's value. */ @@ -359,6 +393,7 @@ public void addCustomArg(String key, String value) { /** * Get the email's send at time (Unix timestamp). + * * @return the email's send at time. */ @JsonProperty("send_at") @@ -368,6 +403,7 @@ public long sendAt() { /** * Set the email's send at time (Unix timestamp). + * * @param sendAt the send at time. */ public void setSendAt(long sendAt) { @@ -376,6 +412,7 @@ public void setSendAt(long sendAt) { /** * Get the email's batch ID. + * * @return the batch ID. */ @JsonProperty("batch_id") @@ -385,6 +422,7 @@ public String getBatchId() { /** * Set the email's batch ID. + * * @param batchId the batch ID. */ public void setBatchId(String batchId) { @@ -393,6 +431,7 @@ public void setBatchId(String batchId) { /** * Get the email's IP pool ID. + * * @return the IP pool ID. */ @JsonProperty("ip_pool_name") @@ -402,6 +441,7 @@ public String getIpPoolId() { /** * Set the email's IP pool ID. + * * @param ipPoolId the IP pool ID. */ public void setIpPoolId(String ipPoolId) { @@ -410,6 +450,7 @@ public void setIpPoolId(String ipPoolId) { /** * Get the email's settings. + * * @return the settings. */ @JsonProperty("mail_settings") @@ -419,6 +460,7 @@ public MailSettings getMailSettings() { /** * Set the email's settings. + * * @param mailSettings the settings. */ public void setMailSettings(MailSettings mailSettings) { @@ -427,6 +469,7 @@ public void setMailSettings(MailSettings mailSettings) { /** * Get the email's tracking settings. + * * @return the tracking settings. */ @JsonProperty("tracking_settings") @@ -436,6 +479,7 @@ public TrackingSettings getTrackingSettings() { /** * Set the email's tracking settings. + * * @param trackingSettings the tracking settings. */ public void setTrackingSettings(TrackingSettings trackingSettings) { @@ -444,6 +488,7 @@ public void setTrackingSettings(TrackingSettings trackingSettings) { /** * Get the email's reply to address. + * * @return the reply to address. */ @JsonProperty("reply_to") @@ -453,6 +498,7 @@ public Email getReplyto() { /** * Set the email's reply to address. + * * @param replyTo the reply to address. */ public void setReplyTo(Email replyTo) { @@ -461,6 +507,7 @@ public void setReplyTo(Email replyTo) { /** * Create a string represenation of the Mail object JSON. + * * @return a JSON string. * @throws IOException in case of a JSON marshal error. */ @@ -475,6 +522,7 @@ public String build() throws IOException { /** * Create a string represenation of the Mail object JSON and pretty print it. + * * @return a pretty JSON string. * @throws IOException in case of a JSON marshal error. */ @@ -505,55 +553,75 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Mail other = (Mail) obj; if (batchId == null) { - if (other.batchId != null) + if (other.batchId != null) { return false; - } else if (!batchId.equals(other.batchId)) + } + } else if (!batchId.equals(other.batchId)) { return false; + } if (categories == null) { - if (other.categories != null) + if (other.categories != null) { return false; - } else if (!categories.equals(other.categories)) + } + } else if (!categories.equals(other.categories)) { return false; + } if (customArgs == null) { - if (other.customArgs != null) + if (other.customArgs != null) { return false; - } else if (!customArgs.equals(other.customArgs)) + } + } else if (!customArgs.equals(other.customArgs)) { return false; + } if (headers == null) { - if (other.headers != null) + if (other.headers != null) { return false; - } else if (!headers.equals(other.headers)) + } + } else if (!headers.equals(other.headers)) { return false; + } if (ipPoolId == null) { - if (other.ipPoolId != null) + if (other.ipPoolId != null) { return false; - } else if (!ipPoolId.equals(other.ipPoolId)) + } + } else if (!ipPoolId.equals(other.ipPoolId)) { return false; + } if (sections == null) { - if (other.sections != null) + if (other.sections != null) { return false; - } else if (!sections.equals(other.sections)) + } + } else if (!sections.equals(other.sections)) { return false; - if (sendAt != other.sendAt) + } + if (sendAt != other.sendAt) { return false; + } if (subject == null) { - if (other.subject != null) + if (other.subject != null) { return false; - } else if (!subject.equals(other.subject)) + } + } else if (!subject.equals(other.subject)) { return false; + } if (templateId == null) { - if (other.templateId != null) + if (other.templateId != null) { return false; - } else if (!templateId.equals(other.templateId)) + } + } else if (!templateId.equals(other.templateId)) { return false; + } return true; } -} \ No newline at end of file +} diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java b/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java index a34895f2..44ce4228 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/ASM.java @@ -3,28 +3,31 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.Arrays; @JsonInclude(Include.NON_DEFAULT) public class ASM { - @JsonProperty("group_id") private int groupId; - @JsonProperty("groups_to_display") private int[] groupsToDisplay; - + + @JsonProperty("group_id") + private int groupId; + + @JsonProperty("groups_to_display") + private int[] groupsToDisplay; + @JsonProperty("group_id") public int getGroupId() { return groupId; } - + public void setGroupId(int groupId) { this.groupId = groupId; } - + @JsonProperty("groups_to_display") public int[] getGroupsToDisplay() { return groupsToDisplay; } - + public void setGroupsToDisplay(int[] groupsToDisplay) { this.groupsToDisplay = Arrays.copyOf(groupsToDisplay, groupsToDisplay.length); } @@ -40,17 +43,22 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ASM other = (ASM) obj; - if (groupId != other.groupId) + if (groupId != other.groupId) { return false; - if (!Arrays.equals(groupsToDisplay, other.groupsToDisplay)) + } + if (!Arrays.equals(groupsToDisplay, other.groupsToDisplay)) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java b/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java index 969c1630..9a3ff1b4 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java @@ -4,68 +4,74 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; import org.apache.commons.codec.binary.Base64; -import java.io.*; - /** * An attachment object. */ @JsonInclude(Include.NON_DEFAULT) public class Attachments { - + /** The attachment content. */ - @JsonProperty("content") private String content; + @JsonProperty("content") + private String content; - /** - * The mime type of the content you are attaching. For example, - * “text/plain” or “text/html”. + /** + * The mime type of the content you are attaching. For example, “text/plain” or “text/html”. */ - @JsonProperty("type") private String type; + @JsonProperty("type") + private String type; /** The attachment file name. */ - @JsonProperty("filename") private String filename; + @JsonProperty("filename") + private String filename; /** The attachment disposition. */ - @JsonProperty("disposition") private String disposition; + @JsonProperty("disposition") + private String disposition; - /** - * The attachment content ID. This is used when the - * disposition is set to “inline” and the attachment - * is an image, allowing the file to be displayed within - * the body of your email. + /** + * The attachment content ID. This is used when the disposition is set to “inline” and the + * attachment is an image, allowing the file to be displayed within the body of your email. */ - @JsonProperty("content_id") private String contentId; + @JsonProperty("content_id") + private String contentId; /** * Get the attachment's content. + * * @return the content. */ - @JsonProperty("content") + @JsonProperty("content") public String getContent() { return content; } /** * Set the attachment's content. + * * @param content the content. */ public void setContent(String content) { this.content = content; } - + /** - * Get the mime type of the content you are attaching. For example, - * “text/plain” or “text/html”. + * Get the mime type of the content you are attaching. For example, “text/plain” or “text/html”. + * * @return the mime type. */ - @JsonProperty("type") + @JsonProperty("type") public String getType() { return type; } - + /** * Set the mime type of the content. + * * @param type the mime type. */ public void setType(String type) { @@ -74,38 +80,39 @@ public void setType(String type) { /** * Get the filename for this attachment. + * * @return the file name. */ - @JsonProperty("filename") + @JsonProperty("filename") public String getFilename() { return filename; } - + /** * Set the filename for this attachment. + * * @param filename the filename. */ public void setFilename(String filename) { this.filename = filename; } - + /** - * Get the content-disposition of the attachment specifying - * how you would like the attachment to be displayed. - * For example, “inline” results in the attached file - * being displayed automatically within the message - * while “attachment” results in the attached file - * requiring some action to be taken before it is - * displayed (e.g. opening or downloading the file). + * Get the content-disposition of the attachment specifying how you would like the attachment to + * be displayed. For example, “inline” results in the attached file being displayed automatically + * within the message while “attachment” results in the attached file requiring some action to be + * taken before it is displayed (e.g. opening or downloading the file). + * * @return the disposition. */ - @JsonProperty("disposition") + @JsonProperty("disposition") public String getDisposition() { return disposition; } - + /** * Set the content-disposition of the attachment. + * * @param disposition the disposition. */ public void setDisposition(String disposition) { @@ -113,19 +120,19 @@ public void setDisposition(String disposition) { } /** - * Get the attachment content ID. This is used when the - * disposition is set to “inline” and the attachment - * is an image, allowing the file to be displayed within - * the body of your email. + * Get the attachment content ID. This is used when the disposition is set to “inline” and the + * attachment is an image, allowing the file to be displayed within the body of your email. + * * @return the content ID. */ - @JsonProperty("content_id") + @JsonProperty("content_id") public String getContentId() { return contentId; } - + /** * Set the content ID. + * * @param contentId the content ID. */ public void setContentId(String contentId) { @@ -148,6 +155,7 @@ public static class Builder { /** * Construct a new attachment builder. + * * @param fileName the filename to include. * @param content an input stream for the content. * @throws IllegalArgumentException in case either the fileName or the content is null. @@ -167,6 +175,7 @@ public Builder(String fileName, InputStream content) { /** * Construct a new attachment builder. + * * @param fileName the filename to include. * @param content an input string for the content. * @throws IllegalArgumentException in case either the fileName or the content is null. @@ -187,7 +196,7 @@ public Builder(String fileName, String content) { private String encodeToBase64(InputStream content) { int read = 0; byte[] bytes = new byte[BYTE_BUFFER_SIZE]; - try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { while ((read = content.read(bytes)) != -1) { baos.write(bytes, 0, read); } @@ -200,6 +209,7 @@ private String encodeToBase64(InputStream content) { /** * Set the type of this attachment builder. + * * @param type the attachment type. */ public Builder withType(String type) { @@ -209,6 +219,7 @@ public Builder withType(String type) { /** * Set the disposition of this attachment builder. + * * @param disposition the disposition. */ public Builder withDisposition(String disposition) { @@ -218,6 +229,7 @@ public Builder withDisposition(String disposition) { /** * Set the content ID of this attachment builder. + * * @param contentId the content ID. */ public Builder withContentId(String contentId) { @@ -253,38 +265,51 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Attachments other = (Attachments) obj; if (content == null) { - if (other.content != null) + if (other.content != null) { return false; - } else if (!content.equals(other.content)) + } + } else if (!content.equals(other.content)) { return false; + } if (contentId == null) { - if (other.contentId != null) + if (other.contentId != null) { return false; - } else if (!contentId.equals(other.contentId)) + } + } else if (!contentId.equals(other.contentId)) { return false; + } if (disposition == null) { - if (other.disposition != null) + if (other.disposition != null) { return false; - } else if (!disposition.equals(other.disposition)) + } + } else if (!disposition.equals(other.disposition)) { return false; + } if (filename == null) { - if (other.filename != null) + if (other.filename != null) { return false; - } else if (!filename.equals(other.filename)) + } + } else if (!filename.equals(other.filename)) { return false; + } if (type == null) { - if (other.type != null) + if (other.type != null) { return false; - } else if (!type.equals(other.type)) + } + } else if (!type.equals(other.type)) { return false; + } return true; } } diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java b/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java index f43803f1..68d7a535 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java @@ -5,14 +5,17 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** - * This object allows you to have a blind carbon copy - * automatically sent to the specified email address - * for every email that is sent. + * This object allows you to have a blind carbon copy automatically sent to the specified email + * address for every email that is sent. */ @JsonInclude(Include.NON_EMPTY) public class BccSettings { - @JsonProperty("enable") private boolean enable; - @JsonProperty("email") private String email; + + @JsonProperty("enable") + private boolean enable; + + @JsonProperty("email") + private String email; @JsonProperty("enable") public boolean getEnable() { @@ -43,20 +46,26 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } BccSettings other = (BccSettings) obj; if (email == null) { - if (other.email != null) + if (other.email != null) { return false; - } else if (!email.equals(other.email)) + } + } else if (!email.equals(other.email)) { return false; - if (enable != other.enable) + } + if (enable != other.enable) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java index ee12fc07..13ce3f13 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/ClickTrackingSetting.java @@ -5,28 +5,32 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** - * Settings to determine how you would like to track the - * metrics of how your recipients interact with your email. + * Settings to determine how you would like to track the metrics of how your recipients interact + * with your email. */ @JsonInclude(Include.NON_EMPTY) public class ClickTrackingSetting { - @JsonProperty("enable") private boolean enable; - @JsonProperty("enable_text") private boolean enableText; - + + @JsonProperty("enable") + private boolean enable; + + @JsonProperty("enable_text") + private boolean enableText; + @JsonProperty("enable") public boolean getEnable() { return enable; } - + public void setEnable(boolean enable) { this.enable = enable; } - + @JsonProperty("enable_text") public boolean getEnableText() { return enableText; - } - + } + public void setEnableText(boolean enableText) { this.enableText = enableText; } @@ -42,17 +46,22 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ClickTrackingSetting other = (ClickTrackingSetting) obj; - if (enable != other.enable) + if (enable != other.enable) { return false; - if (enableText != other.enableText) + } + if (enableText != other.enableText) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Content.java b/src/main/java/com/sendgrid/helpers/mail/objects/Content.java index 0a7a6557..329cf285 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Content.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Content.java @@ -3,22 +3,21 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.regex.Pattern; -import java.lang.IllegalArgumentException; /** - * An object in which you may specify the content of your email. + * An object in which you may specify the content of your email. */ @JsonInclude(Include.NON_DEFAULT) public class Content { - @JsonProperty("type") private String type; - @JsonProperty("value") private String value; + + @JsonProperty("type") + private String type; + + @JsonProperty("value") + private String value; public Content() { return; @@ -59,34 +58,42 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Content other = (Content) obj; if (type == null) { - if (other.type != null) + if (other.type != null) { return false; - } else if (!type.equals(other.type)) + } + } else if (!type.equals(other.type)) { return false; + } if (value == null) { - if (other.value != null) + if (other.value != null) { return false; - } else if (!value.equals(other.value)) + } + } else if (!value.equals(other.value)) { return false; + } return true; } } class ContentVerifier { + private static final List FORBIDDEN_PATTERNS = Collections.singletonList( - Pattern.compile(".*SG\\.[a-zA-Z0-9(-|_)]*\\.[a-zA-Z0-9(-|_)]*.*") + Pattern.compile(".*SG\\.[a-zA-Z0-9(-|_)]*\\.[a-zA-Z0-9(-|_)]*.*") ); static void verifyContent(String content) { - for (Pattern pattern: FORBIDDEN_PATTERNS) { + for (Pattern pattern : FORBIDDEN_PATTERNS) { if (pattern.matcher(content).matches()) { throw new IllegalArgumentException("Found a Forbidden Pattern in the content of the email"); } diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Email.java b/src/main/java/com/sendgrid/helpers/mail/objects/Email.java index 537b27b6..37e8fbcf 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Email.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Email.java @@ -6,8 +6,12 @@ @JsonInclude(Include.NON_DEFAULT) public class Email { - @JsonProperty("name") private String name; - @JsonProperty("email") private String email; + + @JsonProperty("name") + private String name; + + @JsonProperty("email") + private String email; public Email() { return; @@ -51,23 +55,30 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Email other = (Email) obj; if (email == null) { - if (other.email != null) + if (other.email != null) { return false; - } else if (!email.equals(other.email)) + } + } else if (!email.equals(other.email)) { return false; + } if (name == null) { - if (other.name != null) + if (other.name != null) { return false; - } else if (!name.equals(other.name)) + } + } else if (!name.equals(other.name)) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java index 905436ed..6ec12eb2 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/FooterSetting.java @@ -5,15 +5,20 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** - * An object representing the default footer - * that you would like included on every email. + * An object representing the default footer that you would like included on every email. */ @JsonInclude(Include.NON_EMPTY) public class FooterSetting { - @JsonProperty("enable") private boolean enable; - @JsonProperty("text") private String text; - @JsonProperty("html") private String html; - + + @JsonProperty("enable") + private boolean enable; + + @JsonProperty("text") + private String text; + + @JsonProperty("html") + private String html; + @JsonProperty("enable") public boolean getEnable() { return enable; @@ -22,16 +27,16 @@ public boolean getEnable() { public void setEnable(boolean enable) { this.enable = enable; } - + @JsonProperty("text") public String getText() { return text; } - + public void setText(String text) { this.text = text; } - + @JsonProperty("html") public String getHtml() { return html; @@ -53,25 +58,33 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } FooterSetting other = (FooterSetting) obj; - if (enable != other.enable) + if (enable != other.enable) { return false; + } if (html == null) { - if (other.html != null) + if (other.html != null) { return false; - } else if (!html.equals(other.html)) + } + } else if (!html.equals(other.html)) { return false; + } if (text == null) { - if (other.text != null) + if (other.text != null) { return false; - } else if (!text.equals(other.text)) + } + } else if (!text.equals(other.text)) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java index a01d4df6..e8f12f70 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/GoogleAnalyticsSetting.java @@ -9,22 +9,34 @@ */ @JsonInclude(Include.NON_EMPTY) public class GoogleAnalyticsSetting { - @JsonProperty("enable") private boolean enable; - @JsonProperty("utm_source") private String campaignSource; - @JsonProperty("utm_term") private String campaignTerm; - @JsonProperty("utm_content") private String campaignContent; - @JsonProperty("utm_campaign") private String campaignName; - @JsonProperty("utm_medium") private String campaignMedium; - + + @JsonProperty("enable") + private boolean enable; + + @JsonProperty("utm_source") + private String campaignSource; + + @JsonProperty("utm_term") + private String campaignTerm; + + @JsonProperty("utm_content") + private String campaignContent; + + @JsonProperty("utm_campaign") + private String campaignName; + + @JsonProperty("utm_medium") + private String campaignMedium; + @JsonProperty("enable") public boolean getEnable() { return enable; } - + public void setEnable(boolean enable) { this.enable = enable; } - + @JsonProperty("utm_source") public String getCampaignSource() { return campaignSource; @@ -33,7 +45,7 @@ public String getCampaignSource() { public void setCampaignSource(String campaignSource) { this.campaignSource = campaignSource; } - + @JsonProperty("utm_term") public String getCampaignTerm() { return campaignTerm; @@ -42,30 +54,30 @@ public String getCampaignTerm() { public void setCampaignTerm(String campaignTerm) { this.campaignTerm = campaignTerm; } - + @JsonProperty("utm_content") public String getCampaignContent() { return campaignContent; } - + public void setCampaignContent(String campaignContent) { this.campaignContent = campaignContent; } - + @JsonProperty("utm_campaign") public String getCampaignName() { return campaignName; } - + public void setCampaignName(String campaignName) { this.campaignName = campaignName; } - + @JsonProperty("utm_medium") public String getCampaignMedium() { return campaignMedium; } - + public void setCampaignMedium(String campaignMedium) { this.campaignMedium = campaignMedium; } @@ -85,40 +97,54 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } GoogleAnalyticsSetting other = (GoogleAnalyticsSetting) obj; if (campaignContent == null) { - if (other.campaignContent != null) + if (other.campaignContent != null) { return false; - } else if (!campaignContent.equals(other.campaignContent)) + } + } else if (!campaignContent.equals(other.campaignContent)) { return false; + } if (campaignMedium == null) { - if (other.campaignMedium != null) + if (other.campaignMedium != null) { return false; - } else if (!campaignMedium.equals(other.campaignMedium)) + } + } else if (!campaignMedium.equals(other.campaignMedium)) { return false; + } if (campaignName == null) { - if (other.campaignName != null) + if (other.campaignName != null) { return false; - } else if (!campaignName.equals(other.campaignName)) + } + } else if (!campaignName.equals(other.campaignName)) { return false; + } if (campaignSource == null) { - if (other.campaignSource != null) + if (other.campaignSource != null) { return false; - } else if (!campaignSource.equals(other.campaignSource)) + } + } else if (!campaignSource.equals(other.campaignSource)) { return false; + } if (campaignTerm == null) { - if (other.campaignTerm != null) + if (other.campaignTerm != null) { return false; - } else if (!campaignTerm.equals(other.campaignTerm)) + } + } else if (!campaignTerm.equals(other.campaignTerm)) { return false; - if (enable != other.enable) + } + if (enable != other.enable) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java b/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java index 5175642c..bd239880 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/MailSettings.java @@ -5,18 +5,27 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** - * An object representing a collection of different mail - * settings that you can use to specify how you would - * like this email to be handled. + * An object representing a collection of different mail settings that you can use to specify how + * you would like this email to be handled. */ @JsonInclude(Include.NON_DEFAULT) public class MailSettings { - @JsonProperty("bcc") private BccSettings bccSettings; - @JsonProperty("bypass_list_management") private Setting bypassListManagement; - @JsonProperty("footer") private FooterSetting footerSetting; - @JsonProperty("sandbox_mode") private Setting sandBoxMode; - @JsonProperty("spam_check") private SpamCheckSetting spamCheckSetting; + + @JsonProperty("bcc") + private BccSettings bccSettings; + + @JsonProperty("bypass_list_management") + private Setting bypassListManagement; + + @JsonProperty("footer") + private FooterSetting footerSetting; + + @JsonProperty("sandbox_mode") + private Setting sandBoxMode; + + @JsonProperty("spam_check") + private SpamCheckSetting spamCheckSetting; @JsonProperty("bcc") public BccSettings getBccSettings() { @@ -25,6 +34,7 @@ public BccSettings getBccSettings() { /** * Set the BCC settings. + * * @param bccSettings the BCC settings. */ public void setBccSettings(BccSettings bccSettings) { @@ -32,11 +42,10 @@ public void setBccSettings(BccSettings bccSettings) { } /** - * A setting that allows you to bypass all unsubscribe - * groups and suppressions to ensure that the email is - * delivered to every single recipient. This should only - * be used in emergencies when it is absolutely necessary - * that every recipient receives your email. + * A setting that allows you to bypass all unsubscribe groups and suppressions to ensure that the + * email is delivered to every single recipient. This should only be used in emergencies when it + * is absolutely necessary that every recipient receives your email. + * * @return the bypass list setting. */ @@ -51,6 +60,7 @@ public void setBypassListManagement(Setting bypassListManagement) { /** * Get the the footer settings that you would like included on every email. + * * @return the setting. */ @@ -61,6 +71,7 @@ public FooterSetting getFooterSetting() { /** * Set the the footer settings that you would like included on every email. + * * @param footerSetting the setting. */ public void setFooterSetting(FooterSetting footerSetting) { @@ -68,8 +79,9 @@ public void setFooterSetting(FooterSetting footerSetting) { } /** - * Get sandbox mode. This allows you to send a test email to - * ensure that your request body is valid and formatted correctly. + * Get sandbox mode. This allows you to send a test email to ensure that your request body is + * valid and formatted correctly. + * * @return the sandbox mode setting. */ @@ -80,6 +92,7 @@ public Setting getSandBoxMode() { /** * Set sandbox mode. + * * @param sandBoxMode the sandbox mode setting. */ @JsonProperty("sandbox_mode") @@ -88,8 +101,8 @@ public void setSandboxMode(Setting sandBoxMode) { } /** - * Get the spam check setting. This allows you to test the - * content of your email for spam. + * Get the spam check setting. This allows you to test the content of your email for spam. + * * @return the spam check setting. */ @@ -99,8 +112,8 @@ public SpamCheckSetting getSpamCheck() { } /** - * Set the spam check setting. This allows you to test the - * content of your email for spam. + * Set the spam check setting. This allows you to test the content of your email for spam. + * * @param spamCheckSetting the spam check setting. */ @@ -113,7 +126,8 @@ public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((bccSettings == null) ? 0 : bccSettings.hashCode()); - result = prime * result + ((bypassListManagement == null) ? 0 : bypassListManagement.hashCode()); + result = + prime * result + ((bypassListManagement == null) ? 0 : bypassListManagement.hashCode()); result = prime * result + ((footerSetting == null) ? 0 : footerSetting.hashCode()); result = prime * result + ((sandBoxMode == null) ? 0 : sandBoxMode.hashCode()); result = prime * result + ((spamCheckSetting == null) ? 0 : spamCheckSetting.hashCode()); @@ -122,38 +136,51 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } MailSettings other = (MailSettings) obj; if (bccSettings == null) { - if (other.bccSettings != null) + if (other.bccSettings != null) { return false; - } else if (!bccSettings.equals(other.bccSettings)) + } + } else if (!bccSettings.equals(other.bccSettings)) { return false; + } if (bypassListManagement == null) { - if (other.bypassListManagement != null) + if (other.bypassListManagement != null) { return false; - } else if (!bypassListManagement.equals(other.bypassListManagement)) + } + } else if (!bypassListManagement.equals(other.bypassListManagement)) { return false; + } if (footerSetting == null) { - if (other.footerSetting != null) + if (other.footerSetting != null) { return false; - } else if (!footerSetting.equals(other.footerSetting)) + } + } else if (!footerSetting.equals(other.footerSetting)) { return false; + } if (sandBoxMode == null) { - if (other.sandBoxMode != null) + if (other.sandBoxMode != null) { return false; - } else if (!sandBoxMode.equals(other.sandBoxMode)) + } + } else if (!sandBoxMode.equals(other.sandBoxMode)) { return false; + } if (spamCheckSetting == null) { - if (other.spamCheckSetting != null) + if (other.spamCheckSetting != null) { return false; - } else if (!spamCheckSetting.equals(other.spamCheckSetting)) + } + } else if (!spamCheckSetting.equals(other.spamCheckSetting)) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java index e4497d9c..a44cb8d8 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/OpenTrackingSetting.java @@ -5,30 +5,33 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** - * An open tracking settings object. This allows you to track - * whether the email was opened or not, but including a single - * pixel image in the body of the content. When the pixel is - * loaded, we can log that the email was opened. + * An open tracking settings object. This allows you to track whether the email was opened or not, + * but including a single pixel image in the body of the content. When the pixel is loaded, we can + * log that the email was opened. */ @JsonInclude(Include.NON_EMPTY) public class OpenTrackingSetting { - @JsonProperty("enable") private boolean enable; - @JsonProperty("substitution_tag") private String substitutionTag; - + + @JsonProperty("enable") + private boolean enable; + + @JsonProperty("substitution_tag") + private String substitutionTag; + @JsonProperty("enable") public boolean getEnable() { return enable; } - + public void setEnable(boolean enable) { this.enable = enable; } - + @JsonProperty("substitution_tag") public String getSubstitutionTag() { return substitutionTag; } - + public void setSubstitutionTag(String substitutionTag) { this.substitutionTag = substitutionTag; } @@ -44,21 +47,27 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } OpenTrackingSetting other = (OpenTrackingSetting) obj; - if (enable != other.enable) + if (enable != other.enable) { return false; + } if (substitutionTag == null) { - if (other.substitutionTag != null) + if (other.substitutionTag != null) { return false; - } else if (!substitutionTag.equals(other.substitutionTag)) + } + } else if (!substitutionTag.equals(other.substitutionTag)) { return false; + } return true; } - + } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java b/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java index 9a91db5d..82cb3de3 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Personalization.java @@ -3,29 +3,47 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.Collections; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @JsonInclude(Include.NON_DEFAULT) public class Personalization { - @JsonProperty("to") private List tos; - @JsonProperty("cc") private List ccs; - @JsonProperty("bcc") private List bccs; - @JsonProperty("subject") private String subject; - @JsonProperty("headers") private Map headers; - @JsonProperty("substitutions") private Map substitutions; - @JsonProperty("custom_args") private Map customArgs; - @JsonProperty("dynamic_template_data") private Map dynamicTemplateData; - @JsonProperty("send_at") private long sendAt; + + @JsonProperty("to") + private List tos; + + @JsonProperty("cc") + private List ccs; + + @JsonProperty("bcc") + private List bccs; + + @JsonProperty("subject") + private String subject; + + @JsonProperty("headers") + private Map headers; + + @JsonProperty("substitutions") + private Map substitutions; + + @JsonProperty("custom_args") + private Map customArgs; + + @JsonProperty("dynamic_template_data") + private Map dynamicTemplateData; + + @JsonProperty("send_at") + private long sendAt; @JsonProperty("to") public List getTos() { - if(tos == null) - return Collections.emptyList(); + if (tos == null) { + return Collections.emptyList(); + } return tos; } @@ -43,8 +61,9 @@ public void addTo(Email email) { @JsonProperty("cc") public List getCcs() { - if(ccs == null) - return Collections.emptyList(); + if (ccs == null) { + return Collections.emptyList(); + } return ccs; } @@ -62,8 +81,9 @@ public void addCc(Email email) { @JsonProperty("bcc") public List getBccs() { - if(bccs == null) - return Collections.emptyList(); + if (bccs == null) { + return Collections.emptyList(); + } return bccs; } @@ -89,15 +109,16 @@ public void setSubject(String subject) { } @JsonProperty("headers") - public Map getHeaders() { - if(headers == null) - return Collections.emptyMap(); + public Map getHeaders() { + if (headers == null) { + return Collections.emptyMap(); + } return headers; } public void addHeader(String key, String value) { if (headers == null) { - headers = new HashMap(); + headers = new HashMap(); headers.put(key, value); } else { headers.put(key, value); @@ -105,15 +126,16 @@ public void addHeader(String key, String value) { } @JsonProperty("substitutions") - public Map getSubstitutions() { - if(substitutions == null) - return Collections.emptyMap(); + public Map getSubstitutions() { + if (substitutions == null) { + return Collections.emptyMap(); + } return substitutions; } public void addSubstitution(String key, String value) { if (substitutions == null) { - substitutions = new HashMap(); + substitutions = new HashMap(); substitutions.put(key, value); } else { substitutions.put(key, value); @@ -121,15 +143,16 @@ public void addSubstitution(String key, String value) { } @JsonProperty("custom_args") - public Map getCustomArgs() { - if(customArgs == null) - return Collections.emptyMap(); + public Map getCustomArgs() { + if (customArgs == null) { + return Collections.emptyMap(); + } return customArgs; } public void addCustomArg(String key, String value) { if (customArgs == null) { - customArgs = new HashMap(); + customArgs = new HashMap(); customArgs.put(key, value); } else { customArgs.put(key, value); @@ -146,14 +169,14 @@ public void setSendAt(long sendAt) { } @JsonProperty("dynamic_template_data") - public Map getDynamicTemplateData() { + public Map getDynamicTemplateData() { return dynamicTemplateData == null - ? Collections.emptyMap() : dynamicTemplateData; + ? Collections.emptyMap() : dynamicTemplateData; } public void addDynamicTemplateData(String key, Object value) { if (dynamicTemplateData == null) { - dynamicTemplateData = new HashMap(); + dynamicTemplateData = new HashMap(); } dynamicTemplateData.put(key, value); } @@ -175,50 +198,68 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Personalization other = (Personalization) obj; if (bccs == null) { - if (other.bccs != null) + if (other.bccs != null) { return false; - } else if (!bccs.equals(other.bccs)) + } + } else if (!bccs.equals(other.bccs)) { return false; + } if (ccs == null) { - if (other.ccs != null) + if (other.ccs != null) { return false; - } else if (!ccs.equals(other.ccs)) + } + } else if (!ccs.equals(other.ccs)) { return false; + } if (customArgs == null) { - if (other.customArgs != null) + if (other.customArgs != null) { return false; - } else if (!customArgs.equals(other.customArgs)) + } + } else if (!customArgs.equals(other.customArgs)) { return false; + } if (headers == null) { - if (other.headers != null) + if (other.headers != null) { return false; - } else if (!headers.equals(other.headers)) + } + } else if (!headers.equals(other.headers)) { return false; - if (sendAt != other.sendAt) + } + if (sendAt != other.sendAt) { return false; + } if (subject == null) { - if (other.subject != null) + if (other.subject != null) { return false; - } else if (!subject.equals(other.subject)) + } + } else if (!subject.equals(other.subject)) { return false; + } if (substitutions == null) { - if (other.substitutions != null) + if (other.substitutions != null) { return false; - } else if (!substitutions.equals(other.substitutions)) + } + } else if (!substitutions.equals(other.substitutions)) { return false; + } if (tos == null) { - if (other.tos != null) + if (other.tos != null) { return false; - } else if (!tos.equals(other.tos)) + } + } else if (!tos.equals(other.tos)) { return false; + } return true; } } diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java b/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java index 45bef3bb..84a26b0f 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/Setting.java @@ -6,7 +6,9 @@ @JsonInclude(Include.NON_DEFAULT) public class Setting { - @JsonProperty("enable") private boolean enable; + + @JsonProperty("enable") + private boolean enable; @JsonProperty("enable") public boolean getEnable() { @@ -27,15 +29,19 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Setting other = (Setting) obj; - if (enable != other.enable) + if (enable != other.enable) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java index d2cd79c1..b0939bdb 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/SpamCheckSetting.java @@ -5,38 +5,43 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** - * A setting object that allows you to test the content of - * your email for spam. + * A setting object that allows you to test the content of your email for spam. */ @JsonInclude(Include.NON_EMPTY) public class SpamCheckSetting { - @JsonProperty("enable") private boolean enable; - @JsonProperty("threshold") private int spamThreshold; - @JsonProperty("post_to_url") private String postToUrl; + + @JsonProperty("enable") + private boolean enable; + + @JsonProperty("threshold") + private int spamThreshold; + + @JsonProperty("post_to_url") + private String postToUrl; @JsonProperty("enable") public boolean getEnable() { return enable; } - + public void setEnable(boolean enable) { this.enable = enable; } - + @JsonProperty("threshold") public int getSpamThreshold() { return spamThreshold; } - + public void setSpamThreshold(int spamThreshold) { this.spamThreshold = spamThreshold; } - + @JsonProperty("post_to_url") public String getPostToUrl() { return postToUrl; } - + public void setPostToUrl(String postToUrl) { this.postToUrl = postToUrl; } @@ -53,22 +58,29 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } SpamCheckSetting other = (SpamCheckSetting) obj; - if (enable != other.enable) + if (enable != other.enable) { return false; + } if (postToUrl == null) { - if (other.postToUrl != null) + if (other.postToUrl != null) { return false; - } else if (!postToUrl.equals(other.postToUrl)) + } + } else if (!postToUrl.equals(other.postToUrl)) { return false; - if (spamThreshold != other.spamThreshold) + } + if (spamThreshold != other.spamThreshold) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java b/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java index 6c438cc9..fe0f102e 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/SubscriptionTrackingSetting.java @@ -5,50 +5,56 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** - * A subscription tracking setting object. Subscription tracking - * allows you to insert a subscription management link at the - * bottom of the text and html bodies of your email. If you - * would like to specify the location of the link within your - * email, you may use the substitution_tag. + * A subscription tracking setting object. Subscription tracking allows you to insert a subscription + * management link at the bottom of the text and html bodies of your email. If you would like to + * specify the location of the link within your email, you may use the substitution_tag. */ @JsonInclude(Include.NON_EMPTY) public class SubscriptionTrackingSetting { - @JsonProperty("enable") private boolean enable; - @JsonProperty("text") private String text; - @JsonProperty("html") private String html; - @JsonProperty("substitution_tag") private String substitutionTag; - + + @JsonProperty("enable") + private boolean enable; + + @JsonProperty("text") + private String text; + + @JsonProperty("html") + private String html; + + @JsonProperty("substitution_tag") + private String substitutionTag; + @JsonProperty("enable") public boolean getEnable() { return enable; } - + public void setEnable(boolean enable) { this.enable = enable; } - + @JsonProperty("text") public String getText() { return text; } - + public void setText(String text) { this.text = text; } - + @JsonProperty("html") public String getHtml() { return html; - } + } public void setHtml(String html) { this.html = html; } - + @JsonProperty("substitution_tag") public String getSubstitutionTag() { return substitutionTag; - } + } public void setSubstitutionTag(String substitutionTag) { this.substitutionTag = substitutionTag; @@ -67,30 +73,40 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } SubscriptionTrackingSetting other = (SubscriptionTrackingSetting) obj; - if (enable != other.enable) + if (enable != other.enable) { return false; + } if (html == null) { - if (other.html != null) + if (other.html != null) { return false; - } else if (!html.equals(other.html)) + } + } else if (!html.equals(other.html)) { return false; + } if (substitutionTag == null) { - if (other.substitutionTag != null) + if (other.substitutionTag != null) { return false; - } else if (!substitutionTag.equals(other.substitutionTag)) + } + } else if (!substitutionTag.equals(other.substitutionTag)) { return false; + } if (text == null) { - if (other.text != null) + if (other.text != null) { return false; - } else if (!text.equals(other.text)) + } + } else if (!text.equals(other.text)) { return false; + } return true; } } \ No newline at end of file diff --git a/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java b/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java index 981875c8..08a9b411 100644 --- a/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java +++ b/src/main/java/com/sendgrid/helpers/mail/objects/TrackingSettings.java @@ -6,43 +6,52 @@ @JsonInclude(Include.NON_DEFAULT) public class TrackingSettings { - @JsonProperty("click_tracking") private ClickTrackingSetting clickTrackingSetting; - @JsonProperty("open_tracking") private OpenTrackingSetting openTrackingSetting; - @JsonProperty("subscription_tracking") private SubscriptionTrackingSetting subscriptionTrackingSetting; - @JsonProperty("ganalytics") private GoogleAnalyticsSetting googleAnalyticsSetting; + + @JsonProperty("click_tracking") + private ClickTrackingSetting clickTrackingSetting; + + @JsonProperty("open_tracking") + private OpenTrackingSetting openTrackingSetting; + + @JsonProperty("subscription_tracking") + private SubscriptionTrackingSetting subscriptionTrackingSetting; + + @JsonProperty("ganalytics") + private GoogleAnalyticsSetting googleAnalyticsSetting; @JsonProperty("click_tracking") public ClickTrackingSetting getClickTrackingSetting() { return clickTrackingSetting; } - + public void setClickTrackingSetting(ClickTrackingSetting clickTrackingSetting) { this.clickTrackingSetting = clickTrackingSetting; } - + @JsonProperty("open_tracking") public OpenTrackingSetting getOpenTrackingSetting() { return openTrackingSetting; } - + public void setOpenTrackingSetting(OpenTrackingSetting openTrackingSetting) { this.openTrackingSetting = openTrackingSetting; } - + @JsonProperty("subscription_tracking") public SubscriptionTrackingSetting getSubscriptionTrackingSetting() { return subscriptionTrackingSetting; } - - public void setSubscriptionTrackingSetting(SubscriptionTrackingSetting subscriptionTrackingSetting) { + + public void setSubscriptionTrackingSetting( + SubscriptionTrackingSetting subscriptionTrackingSetting) { this.subscriptionTrackingSetting = subscriptionTrackingSetting; } - + @JsonProperty("ganalytics") public GoogleAnalyticsSetting getGoogleAnalyticsSetting() { return googleAnalyticsSetting; } - + public void setGoogleAnalyticsSetting(GoogleAnalyticsSetting googleAnalyticsSetting) { this.googleAnalyticsSetting = googleAnalyticsSetting; } @@ -51,42 +60,56 @@ public void setGoogleAnalyticsSetting(GoogleAnalyticsSetting googleAnalyticsSett public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((clickTrackingSetting == null) ? 0 : clickTrackingSetting.hashCode()); - result = prime * result + ((googleAnalyticsSetting == null) ? 0 : googleAnalyticsSetting.hashCode()); + result = + prime * result + ((clickTrackingSetting == null) ? 0 : clickTrackingSetting.hashCode()); + result = + prime * result + ((googleAnalyticsSetting == null) ? 0 : googleAnalyticsSetting.hashCode()); result = prime * result + ((openTrackingSetting == null) ? 0 : openTrackingSetting.hashCode()); - result = prime * result + ((subscriptionTrackingSetting == null) ? 0 : subscriptionTrackingSetting.hashCode()); + result = prime * result + ((subscriptionTrackingSetting == null) ? 0 + : subscriptionTrackingSetting.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } TrackingSettings other = (TrackingSettings) obj; if (clickTrackingSetting == null) { - if (other.clickTrackingSetting != null) + if (other.clickTrackingSetting != null) { return false; - } else if (!clickTrackingSetting.equals(other.clickTrackingSetting)) + } + } else if (!clickTrackingSetting.equals(other.clickTrackingSetting)) { return false; + } if (googleAnalyticsSetting == null) { - if (other.googleAnalyticsSetting != null) + if (other.googleAnalyticsSetting != null) { return false; - } else if (!googleAnalyticsSetting.equals(other.googleAnalyticsSetting)) + } + } else if (!googleAnalyticsSetting.equals(other.googleAnalyticsSetting)) { return false; + } if (openTrackingSetting == null) { - if (other.openTrackingSetting != null) + if (other.openTrackingSetting != null) { return false; - } else if (!openTrackingSetting.equals(other.openTrackingSetting)) + } + } else if (!openTrackingSetting.equals(other.openTrackingSetting)) { return false; + } if (subscriptionTrackingSetting == null) { - if (other.subscriptionTrackingSetting != null) + if (other.subscriptionTrackingSetting != null) { return false; - } else if (!subscriptionTrackingSetting.equals(other.subscriptionTrackingSetting)) + } + } else if (!subscriptionTrackingSetting.equals(other.subscriptionTrackingSetting)) { return false; + } return true; } } \ No newline at end of file diff --git a/src/test/java/com/sendgrid/LicenseTest.java b/src/test/java/com/sendgrid/LicenseTest.java index 493458e6..96bf096c 100644 --- a/src/test/java/com/sendgrid/LicenseTest.java +++ b/src/test/java/com/sendgrid/LicenseTest.java @@ -1,27 +1,28 @@ package com.sendgrid; -import org.junit.Assert; -import org.junit.Test; - import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Calendar; +import org.junit.Assert; +import org.junit.Test; public class LicenseTest { - @Test - public void testLicenseShouldHaveCorrectYear() throws IOException { - String copyrightText = null; - try (BufferedReader br = new BufferedReader(new FileReader("./LICENSE.md"))) { - for (String line; (line = br.readLine()) != null; ) { - if (line.startsWith("Copyright")) { - copyrightText = line; - break; - } - } + @Test + public void testLicenseShouldHaveCorrectYear() throws IOException { + String copyrightText = null; + try (BufferedReader br = new BufferedReader(new FileReader("./LICENSE.md"))) { + for (String line; (line = br.readLine()) != null; ) { + if (line.startsWith("Copyright")) { + copyrightText = line; + break; } - String expectedCopyright = String.format("Copyright (C) %d, Twilio SendGrid, Inc. ", Calendar.getInstance().get(Calendar.YEAR)); - Assert.assertEquals("License has incorrect year", copyrightText, expectedCopyright); + } } + String expectedCopyright = String + .format("Copyright (C) %d, Twilio SendGrid, Inc. ", + Calendar.getInstance().get(Calendar.YEAR)); + Assert.assertEquals("License has incorrect year", copyrightText, expectedCopyright); + } } diff --git a/src/test/java/com/sendgrid/SendGridTest.java b/src/test/java/com/sendgrid/SendGridTest.java index 1873be71..d72909e3 100644 --- a/src/test/java/com/sendgrid/SendGridTest.java +++ b/src/test/java/com/sendgrid/SendGridTest.java @@ -1,20 +1,21 @@ package com.sendgrid; -import org.junit.Assert; -import org.junit.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import static org.mockito.Mockito.*; +import org.junit.Assert; +import org.junit.Test; public class SendGridTest { private final String SENDGRID_API_KEY = ""; - public Map buildDefaultHeaders() { + private Map buildDefaultHeaders() { SendGrid sg = new SendGrid(SENDGRID_API_KEY); - Map requestHeaders = new HashMap(); + Map requestHeaders = new HashMap(); requestHeaders.put("Authorization", "Bearer " + SENDGRID_API_KEY); String USER_AGENT = "sendgrid/" + sg.getLibraryVersion() + ";java"; requestHeaders.put("User-agent", USER_AGENT); @@ -27,7 +28,7 @@ public void testInitialization() { SendGrid sg = new SendGrid(SENDGRID_API_KEY); Assert.assertEquals(sg.getHost(), "api.sendgrid.com"); Assert.assertEquals(sg.getVersion(), "v3"); - Map requestHeaders = buildDefaultHeaders(); + Map requestHeaders = buildDefaultHeaders(); Assert.assertEquals(sg.getRequestHeaders(), requestHeaders); } @@ -56,7 +57,7 @@ public void testVersion() { @Test public void testRequestHeaders() { SendGrid sg = new SendGrid(SENDGRID_API_KEY); - Map requestHeaders = buildDefaultHeaders(); + Map requestHeaders = buildDefaultHeaders(); sg.addRequestHeader("Test", "one"); requestHeaders.put("Test", "one"); @@ -93,7 +94,7 @@ public void testRateLimitSleep() { public void test_async() { final Object sync = new Object(); SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { + if (System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { sg = new SendGrid("SENDGRID_API_KEY"); sg.setHost(System.getenv("MOCK_HOST")); } else { @@ -111,7 +112,7 @@ public void test_async() { @Override public void error(Exception e) { Assert.fail(); - synchronized(sync) { + synchronized (sync) { sync.notify(); } } @@ -119,17 +120,17 @@ public void error(Exception e) { @Override public void response(Response response) { Assert.assertEquals(200, response.getStatusCode()); - synchronized(sync) { + synchronized (sync) { sync.notify(); } } }); try { - synchronized(sync) { + synchronized (sync) { sync.wait(2000); } - } catch(InterruptedException ex) { + } catch (InterruptedException ex) { Assert.fail(ex.toString()); } } @@ -138,7 +139,7 @@ public void response(Response response) { public void test_async_rate_limit() { final Object sync = new Object(); SendGrid sg = null; - if(System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { + if (System.getenv("TRAVIS") != null && Boolean.parseBoolean(System.getenv("TRAVIS"))) { sg = new SendGrid("SENDGRID_API_KEY"); sg.setHost(System.getenv("MOCK_HOST")); } else { @@ -167,10 +168,10 @@ public void response(Response response) { }); try { - synchronized(sync) { + synchronized (sync) { sync.wait(2000); } - } catch(InterruptedException ex) { + } catch (InterruptedException ex) { Assert.fail(ex.toString()); } } @@ -198,7 +199,8 @@ public void test_access_settings_whitelist_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("access_settings/whitelist"); - request.setBody("{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"); + request.setBody( + "{\"ips\":[{\"ip\":\"192.168.1.1\"},{\"ip\":\"192.*.*.*\"},{\"ip\":\"192.168.1.3/32\"}]}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -265,7 +267,8 @@ public void test_alerts_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("alerts"); - request.setBody("{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"); + request.setBody( + "{\"type\":\"stats_notification\",\"frequency\":\"daily\",\"email_to\":\"example@example.com\"}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -332,7 +335,8 @@ public void test_api_keys_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("api_keys"); - request.setBody("{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"); + request.setBody( + "{\"sample\":\"data\",\"scopes\":[\"mail.send\",\"alerts.create\",\"alerts.read\"],\"name\":\"My API Key\"}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -360,7 +364,8 @@ public void test_api_keys__api_key_id__put() throws IOException { Request request = new Request(); request.setMethod(Method.PUT); request.setEndpoint("api_keys/{api_key_id}"); - request.setBody("{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"); + request.setBody( + "{\"scopes\":[\"user.profile.read\",\"user.profile.update\"],\"name\":\"A New Hope\"}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -414,7 +419,8 @@ public void test_asm_groups_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("asm/groups"); - request.setBody("{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"); + request.setBody( + "{\"is_default\":true,\"description\":\"Suggestions for products our users might like.\",\"name\":\"Product Suggestions\"}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -442,7 +448,8 @@ public void test_asm_groups__group_id__patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("asm/groups/{group_id}"); - request.setBody("{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"); + request.setBody( + "{\"description\":\"Suggestions for items our users might like.\",\"name\":\"Item Suggestions\",\"id\":103}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -509,7 +516,8 @@ public void test_asm_groups__group_id__suppressions_search_post() throws IOExcep Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("asm/groups/{group_id}/suppressions/search"); - request.setBody("{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"); + request.setBody( + "{\"recipient_emails\":[\"exists1@example.com\",\"exists2@example.com\",\"doesnotexists@example.com\"]}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -621,7 +629,8 @@ public void test_campaigns_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("campaigns"); - request.setBody("{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"); + request.setBody( + "{\"custom_unsubscribe_url\":\"\",\"html_content\":\"

Check out our spring line!

\",\"list_ids\":[110,124],\"sender_id\":124451,\"subject\":\"New Products for Spring!\",\"plain_content\":\"Check out our spring line!\",\"suppression_group_id\":42,\"title\":\"March Newsletter\",\"segment_ids\":[110],\"categories\":[\"spring line\"],\"ip_pool\":\"marketing\"}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -650,7 +659,8 @@ public void test_campaigns__campaign_id__patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("campaigns/{campaign_id}"); - request.setBody("{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"); + request.setBody( + "{\"html_content\":\"

Check out our summer line!

\",\"subject\":\"New Products for Summer!\",\"title\":\"May Newsletter\",\"categories\":[\"summer line\"],\"plain_content\":\"Check out our summer line!\"}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -1053,7 +1063,8 @@ public void test_contactdb_recipients_patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("contactdb/recipients"); - request.setBody("[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"); + request.setBody( + "[{\"first_name\":\"Guy\",\"last_name\":\"Jones\",\"email\":\"jones@example.com\"}]"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -1067,7 +1078,8 @@ public void test_contactdb_recipients_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("contactdb/recipients"); - request.setBody("[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"); + request.setBody( + "[{\"age\":25,\"last_name\":\"User\",\"email\":\"example@example.com\",\"first_name\":\"\"},{\"age\":25,\"last_name\":\"User\",\"email\":\"example2@example.com\",\"first_name\":\"Example\"}]"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -1202,7 +1214,8 @@ public void test_contactdb_segments_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("contactdb/segments"); - request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"); + request.setBody( + "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"},{\"operator\":\"gt\",\"field\":\"last_clicked\",\"and_or\":\"and\",\"value\":\"01/02/2015\"},{\"operator\":\"eq\",\"field\":\"clicks.campaign_identifier\",\"and_or\":\"or\",\"value\":\"513\"}],\"name\":\"Last Name Miller\",\"list_id\":4}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -1229,7 +1242,8 @@ public void test_contactdb_segments__segment_id__patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("contactdb/segments/{segment_id}"); - request.setBody("{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"); + request.setBody( + "{\"conditions\":[{\"operator\":\"eq\",\"field\":\"last_name\",\"and_or\":\"\",\"value\":\"Miller\"}],\"name\":\"The Millers\",\"list_id\":5}"); request.addQueryParam("segment_id", "test_string"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); @@ -1541,7 +1555,8 @@ public void test_mail_send_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("mail/send"); - request.setBody("{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiveing these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"); + request.setBody( + "{\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"from\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"attachments\":[{\"name\":\"file1\",\"filename\":\"file1.jpg\",\"content\":\"[BASE64 encoded content block here]\",\"disposition\":\"inline\",\"content_id\":\"ii_139db99fdb5c3704\",\"type\":\"jpg\"}],\"personalizations\":[{\"to\":[{\"email\":\"john.doe@example.com\",\"name\":\"John Doe\"}],\"cc\":[{\"email\":\"jane.doe@example.com\",\"name\":\"Jane Doe\"}],\"bcc\":[{\"email\":\"sam.doe@example.com\",\"name\":\"Sam Doe\"}],\"custom_args\":{\"New Argument 1\":\"New Value 1\",\"activationAttempt\":\"1\",\"customerAccountNumber\":\"[CUSTOMER ACCOUNT NUMBER GOES HERE]\"},\"headers\":{\"X-Accept-Language\":\"en\",\"X-Mailer\":\"MyApp\"},\"send_at\":1409348513,\"substitutions\":{\"type\":\"object\",\"id\":\"substitutions\"},\"subject\":\"Hello, World!\"}],\"subject\":\"Hello, World!\",\"ip_pool_name\":\"[YOUR POOL NAME GOES HERE]\",\"content\":[{\"type\":\"text/html\",\"value\":\"

Hello, world!

\"}],\"headers\":{},\"asm\":{\"groups_to_display\":[1,2,3],\"group_id\":1},\"batch_id\":\"[YOUR BATCH ID GOES HERE]\",\"tracking_settings\":{\"subscription_tracking\":{\"text\":\"If you would like to unsubscribe and stop receiveing these emails <% click here %>.\",\"enable\":true,\"html\":\"If you would like to unsubscribe and stop receiving these emails <% clickhere %>.\",\"substitution_tag\":\"<%click here%>\"},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"%opentrack\"},\"click_tracking\":{\"enable\":true,\"enable_text\":true},\"ganalytics\":{\"utm_campaign\":\"[NAME OF YOUR REFERRER SOURCE]\",\"enable\":true,\"utm_name\":\"[NAME OF YOUR CAMPAIGN]\",\"utm_term\":\"[IDENTIFY PAID KEYWORDS HERE]\",\"utm_content\":\"[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]\",\"utm_medium\":\"[NAME OF YOUR MARKETING MEDIUM e.g. email]\"}},\"mail_settings\":{\"footer\":{\"text\":\"Thanks,/n The SendGrid Team\",\"enable\":true,\"html\":\"

Thanks
The SendGrid Team

\"},\"spam_check\":{\"threshold\":3,\"post_to_url\":\"http://example.com/compliance\",\"enable\":true},\"bypass_list_management\":{\"enable\":true},\"sandbox_mode\":{\"enable\":false},\"bcc\":{\"enable\":true,\"email\":\"ben.doe@example.com\"}},\"reply_to\":{\"email\":\"sam.smith@example.com\",\"name\":\"Sam Smith\"},\"sections\":{\"section\":{\":sectionName2\":\"section 2 text\",\":sectionName1\":\"section 1 text\"}},\"template_id\":\"[YOUR TEMPLATE ID GOES HERE]\",\"categories\":[\"category1\",\"category2\"],\"send_at\":1409348513}"); Response response = sg.api(request); Assert.assertEquals(202, response.getStatusCode()); } @@ -1887,7 +1902,8 @@ public void test_senders_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("senders"); - request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); + request.setBody( + "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -1914,7 +1930,8 @@ public void test_senders__sender_id__patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("senders/{sender_id}"); - request.setBody("{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); + request.setBody( + "{\"city\":\"Denver\",\"from\":{\"email\":\"from@example.com\",\"name\":\"Example INC\"},\"zip\":\"80202\",\"country\":\"United States\",\"state\":\"Colorado\",\"address_2\":\"Apt. 456\",\"address\":\"123 Elm St.\",\"reply_to\":{\"email\":\"replyto@example.com\",\"name\":\"Example INC\"},\"nickname\":\"My Sender ID\"}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -1985,7 +2002,8 @@ public void test_subusers_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("subusers"); - request.setBody("{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"); + request.setBody( + "{\"username\":\"John@example.com\",\"ips\":[\"1.1.1.1\",\"2.2.2.2\"],\"password\":\"johns_password\",\"email\":\"John@example.com\"}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -2217,7 +2235,8 @@ public void test_suppression_blocks_delete() throws IOException { Request request = new Request(); request.setMethod(Method.DELETE); request.setEndpoint("suppression/blocks"); - request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); + request.setBody( + "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); Assert.assertEquals(204, response.getStatusCode()); } @@ -2272,7 +2291,8 @@ public void test_suppression_bounces_delete() throws IOException { Request request = new Request(); request.setMethod(Method.DELETE); request.setEndpoint("suppression/bounces"); - request.setBody("{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"); + request.setBody( + "{\"emails\":[\"example@example.com\",\"example2@example.com\"],\"delete_all\":true}"); Response response = sg.api(request); Assert.assertEquals(204, response.getStatusCode()); } @@ -2330,7 +2350,8 @@ public void test_suppression_invalid_emails_delete() throws IOException { Request request = new Request(); request.setMethod(Method.DELETE); request.setEndpoint("suppression/invalid_emails"); - request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); + request.setBody( + "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); Assert.assertEquals(204, response.getStatusCode()); } @@ -2413,7 +2434,8 @@ public void test_suppression_spam_reports_delete() throws IOException { Request request = new Request(); request.setMethod(Method.DELETE); request.setEndpoint("suppression/spam_reports"); - request.setBody("{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); + request.setBody( + "{\"emails\":[\"example1@example.com\",\"example2@example.com\"],\"delete_all\":false}"); Response response = sg.api(request); Assert.assertEquals(204, response.getStatusCode()); } @@ -2511,7 +2533,8 @@ public void test_templates__template_id__versions_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("templates/{template_id}/versions"); - request.setBody("{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"); + request.setBody( + "{\"name\":\"example_version_name\",\"html_content\":\"<%body%>\",\"plain_content\":\"<%body%>\",\"active\":1,\"template_id\":\"ddb96bbc-9b92-425e-8979-99464621b543\",\"subject\":\"<%subject%>\"}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -2525,7 +2548,8 @@ public void test_templates__template_id__versions__version_id__patch() throws IO Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("templates/{template_id}/versions/{version_id}"); - request.setBody("{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"); + request.setBody( + "{\"active\":1,\"html_content\":\"<%body%>\",\"subject\":\"<%subject%>\",\"name\":\"updated_example_name\",\"plain_content\":\"<%body%>\"}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -2557,7 +2581,8 @@ public void test_templates__template_id__versions__version_id__delete() throws I } @Test - public void test_templates__template_id__versions__version_id__activate_post() throws IOException { + public void test_templates__template_id__versions__version_id__activate_post() + throws IOException { SendGrid sg = new SendGrid("SENDGRID_API_KEY", true); sg.setHost("localhost:4010"); sg.addRequestHeader("X-Mock", "200"); @@ -2620,7 +2645,8 @@ public void test_tracking_settings_google_analytics_patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("tracking_settings/google_analytics"); - request.setBody("{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"); + request.setBody( + "{\"utm_campaign\":\"website\",\"utm_term\":\"\",\"utm_content\":\"\",\"enabled\":true,\"utm_source\":\"sendgrid.com\",\"utm_medium\":\"email\"}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -2674,7 +2700,8 @@ public void test_tracking_settings_subscription_patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("tracking_settings/subscription"); - request.setBody("{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"); + request.setBody( + "{\"url\":\"url\",\"html_content\":\"html content\",\"enabled\":true,\"landing\":\"landing page html\",\"replace\":\"replacement tag\",\"plain_content\":\"text content\"}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -2916,7 +2943,8 @@ public void test_user_webhooks_event_settings_patch() throws IOException { Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/webhooks/event/settings"); - request.setBody("{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); + request.setBody( + "{\"group_resubscribe\":true,\"delivered\":true,\"group_unsubscribe\":true,\"spam_report\":true,\"url\":\"url\",\"enabled\":true,\"bounce\":true,\"deferred\":true,\"unsubscribe\":true,\"dropped\":true,\"open\":true,\"click\":true,\"processed\":true}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -2957,7 +2985,8 @@ public void test_user_webhooks_parse_settings_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("user/webhooks/parse/settings"); - request.setBody("{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"); + request.setBody( + "{\"url\":\"http://email.myhosthame.com\",\"send_raw\":false,\"hostname\":\"myhostname.com\",\"spam_check\":true}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -2984,7 +3013,8 @@ public void test_user_webhooks_parse_settings__hostname__patch() throws IOExcept Request request = new Request(); request.setMethod(Method.PATCH); request.setEndpoint("user/webhooks/parse/settings/{hostname}"); - request.setBody("{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"); + request + .setBody("{\"url\":\"http://newdomain.com/parse\",\"send_raw\":true,\"spam_check\":false}"); Response response = sg.api(request); Assert.assertEquals(200, response.getStatusCode()); } @@ -3042,7 +3072,8 @@ public void test_whitelabel_domains_post() throws IOException { Request request = new Request(); request.setMethod(Method.POST); request.setEndpoint("whitelabel/domains"); - request.setBody("{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"); + request.setBody( + "{\"automatic_security\":false,\"username\":\"john@example.com\",\"domain\":\"example.com\",\"default\":true,\"custom_spf\":true,\"ips\":[\"192.168.1.1\",\"192.168.1.2\"],\"subdomain\":\"news\"}"); Response response = sg.api(request); Assert.assertEquals(201, response.getStatusCode()); } @@ -3409,7 +3440,7 @@ public void test_whitelabel_links__link_id__subuser_post() throws IOException { @Test public void test_add_impersonate_subuser() { SendGrid sg = new SendGrid(SENDGRID_API_KEY); - + sg.addImpersonateSubuser("subusername"); Assert.assertEquals(sg.getRequestHeaders().get("on-behalf-of"), "subusername"); } @@ -3417,22 +3448,22 @@ public void test_add_impersonate_subuser() { @Test public void test_remove_impersonate_subuser() { SendGrid sg = new SendGrid(SENDGRID_API_KEY); - + sg.addImpersonateSubuser("subusername"); Assert.assertEquals(sg.getRequestHeaders().get("on-behalf-of"), "subusername"); sg.removeImpersonateSubuser(); Assert.assertEquals(sg.getRequestHeaders().get("on-behalf-of"), null); } - + @Test public void test_get_impersonate_subuser() { SendGrid sg = new SendGrid(SENDGRID_API_KEY); - + sg.addImpersonateSubuser("subusername"); Assert.assertEquals(sg.getImpersonateSubuser(), "subusername"); - + sg.removeImpersonateSubuser(); Assert.assertEquals(sg.getImpersonateSubuser(), null); - } + } } diff --git a/src/test/java/com/sendgrid/TestRequiredFilesExist.java b/src/test/java/com/sendgrid/TestRequiredFilesExist.java index bb5dd46c..62eda186 100644 --- a/src/test/java/com/sendgrid/TestRequiredFilesExist.java +++ b/src/test/java/com/sendgrid/TestRequiredFilesExist.java @@ -1,94 +1,108 @@ package com.sendgrid; -import org.junit.Test; +import static org.junit.Assert.assertTrue; import java.io.File; - -import static org.junit.Assert.assertTrue; +import org.junit.Test; public class TestRequiredFilesExist { - // ./Docker or docker/Docker - @Test public void checkDockerExists() { - boolean dockerExists = new File("./Dockerfile").exists() || + // ./Docker or docker/Docker + @Test + public void checkDockerExists() { + boolean dockerExists = new File("./Dockerfile").exists() || new File("./docker/Dockerfile").exists(); - assertTrue(dockerExists); - } - - // // ./docker-compose.yml or ./docker/docker-compose.yml - // @Test public void checkDockerComposeExists() { - // boolean dockerComposeExists = new File("./docker-compose.yml").exists() || - // new File("./docker/docker-compose.yml").exists(); - // assertTrue(dockerComposeExists); - // } - - // ./.env_sample - @Test public void checkEnvSampleExists() { - assertTrue(new File("./.env_sample").exists()); - } - - // ./.gitignore - @Test public void checkGitIgnoreExists() { - assertTrue(new File("./.gitignore").exists()); - } - - // ./.travis.yml - @Test public void checkTravisExists() { - assertTrue(new File("./.travis.yml").exists()); - } - - // ./.codeclimate.yml - @Test public void checkCodeClimateExists() { - assertTrue(new File("./.codeclimate.yml").exists()); - } - - // ./CHANGELOG.md - @Test public void checkChangelogExists() { - assertTrue(new File("./CHANGELOG.md").exists()); - } - - // ./CODE_OF_CONDUCT.md - @Test public void checkCodeOfConductExists() { - assertTrue(new File("./CODE_OF_CONDUCT.md").exists()); - } - - // ./CONTRIBUTING.md - @Test public void checkContributingGuideExists() { - assertTrue(new File("./CONTRIBUTING.md").exists()); - } - - // ./ISSUE_TEMPLATE.md - @Test public void checkIssuesTemplateExists() { - assertTrue(new File("./ISSUE_TEMPLATE.md").exists()); - } - - // ./LICENSE.md - @Test public void checkLicenseExists() { - assertTrue(new File("./LICENSE.md").exists()); - } - - // ./PULL_REQUEST_TEMPLATE.md - @Test public void checkPullRequestExists() { - assertTrue(new File("./PULL_REQUEST_TEMPLATE.md").exists()); - } - - // ./README.md - @Test public void checkReadMeExists() { - assertTrue(new File("./README.md").exists()); - } - - // ./TROUBLESHOOTING.md - @Test public void checkTroubleShootingGuideExists() { - assertTrue(new File("./TROUBLESHOOTING.md").exists()); - } - - // ./USAGE.md - @Test public void checkUsageGuideExists() { - assertTrue(new File("./USAGE.md").exists()); - } - - // ./USE_CASES.md - @Test public void checkUseCases() { - assertTrue(new File("./USE_CASES.md").exists()); - } + assertTrue(dockerExists); + } + + // // ./docker-compose.yml or ./docker/docker-compose.yml + // @Test public void checkDockerComposeExists() { + // boolean dockerComposeExists = new File("./docker-compose.yml").exists() || + // new File("./docker/docker-compose.yml").exists(); + // assertTrue(dockerComposeExists); + // } + + // ./.env_sample + @Test + public void checkEnvSampleExists() { + assertTrue(new File("./.env_sample").exists()); + } + + // ./.gitignore + @Test + public void checkGitIgnoreExists() { + assertTrue(new File("./.gitignore").exists()); + } + + // ./.travis.yml + @Test + public void checkTravisExists() { + assertTrue(new File("./.travis.yml").exists()); + } + + // ./.codeclimate.yml + @Test + public void checkCodeClimateExists() { + assertTrue(new File("./.codeclimate.yml").exists()); + } + + // ./CHANGELOG.md + @Test + public void checkChangelogExists() { + assertTrue(new File("./CHANGELOG.md").exists()); + } + + // ./CODE_OF_CONDUCT.md + @Test + public void checkCodeOfConductExists() { + assertTrue(new File("./CODE_OF_CONDUCT.md").exists()); + } + + // ./CONTRIBUTING.md + @Test + public void checkContributingGuideExists() { + assertTrue(new File("./CONTRIBUTING.md").exists()); + } + + // ./ISSUE_TEMPLATE.md + @Test + public void checkIssuesTemplateExists() { + assertTrue(new File("./ISSUE_TEMPLATE.md").exists()); + } + + // ./LICENSE.md + @Test + public void checkLicenseExists() { + assertTrue(new File("./LICENSE.md").exists()); + } + + // ./PULL_REQUEST_TEMPLATE.md + @Test + public void checkPullRequestExists() { + assertTrue(new File("./PULL_REQUEST_TEMPLATE.md").exists()); + } + + // ./README.md + @Test + public void checkReadMeExists() { + assertTrue(new File("./README.md").exists()); + } + + // ./TROUBLESHOOTING.md + @Test + public void checkTroubleShootingGuideExists() { + assertTrue(new File("./TROUBLESHOOTING.md").exists()); + } + + // ./USAGE.md + @Test + public void checkUsageGuideExists() { + assertTrue(new File("./USAGE.md").exists()); + } + + // ./USE_CASES.md + @Test + public void checkUseCases() { + assertTrue(new File("./USE_CASES.md").exists()); + } }