diff --git a/README.md b/README.md index 092b079..735978e 100644 --- a/README.md +++ b/README.md @@ -833,7 +833,7 @@ class Example { To build the email with the simple editor, set `editor` to `EmailEditors.SIMPLE`, and do not set `content`. Then change the email with [the email methods](#emails). The ID of the email is in `campaign.emails[0].id`. - `editor`: the only accepted value is `simple`, which selects the simple editor instead of the drag-and-drop builder. It has to be the same across every email in the payload; a mixed array is rejected. Setting it prohibits `emails.*.content`. -- `templateId` (`template_id`): the template the new email starts from. Allowed only when `editor` is `simple`, accepts only a template from the shared gallery, and also has to be the same across every email. +- `templateId` (`template_id`): the simple editor template the new email starts from. It is a template from the shared gallery, or a template that you saved from your own email with [`createTemplate`](#save-an-email-as-a-template). Allowed only when `editor` is `simple`, and also has to be the same across every email. - Only `create()` accepts `editor` and `templateId`. If an email has one of them set, `update()` gets a `422` error. - The SDK does not send `editor`, `templateId`, `replyTo` or `content` when they are `null`. @@ -1146,6 +1146,8 @@ Without `placement`, the API puts the block at the end of the email. The positio A `null` block throws `NullPointerException`, and the SDK sends no request. +The API removes the attributes and the `mobile` keys that the block type does not declare, and the insert is still a success. Then the response has `rejected` with the paths of these values, for example `editor_content.attrs.onclick`. Otherwise `rejected` is `null`. Only `createBlock` and `updateBlock` fill `rejected`. `getBlock` and `moveBlock` leave it `null`. + ```java // import .... @@ -1174,6 +1176,11 @@ class Example { System.out.println(blockId + " " + etag); + if (response.rejected != null) { + + System.out.println(String.join(", ", response.rejected.keys)); + } + } catch (MailerLiteException e) { e.printStackTrace(); @@ -1186,6 +1193,8 @@ class Example { The new `editorContent` replaces the whole content of the block. The API removes the keys that you do not send. So get the block, change its `editorContent`, and send all of it. The type and the position of the block do not change. +The API removes the attributes and the `mobile` keys that the block type does not declare, and the update is still a success. Then the response has `rejected` with the paths of these values. Otherwise `rejected` is `null`. + ```java // import .... @@ -1206,6 +1215,11 @@ class Example { System.out.println(response.etag); + if (response.rejected != null) { + + System.out.println(String.join(", ", response.rejected.keys)); + } + } catch (MailerLiteException e) { e.printStackTrace(); @@ -1268,7 +1282,7 @@ class Example { ### Validate a block -Checks a block before you insert it, and saves nothing. It needs no email and no etag. An invalid block is not an error: the response has `valid` set to `false` and the `errors` for each field. A `null` block sends an empty body. +Checks a block before you insert it, and saves nothing. It needs no email and no etag. An invalid block is not an error: the response has `valid` set to `false` and the `errors` for each field. If the block is valid and an insert would remove attributes, `rejected` has their paths. A `null` block sends an empty body. ```java @@ -1384,6 +1398,8 @@ class Example { Copies the email to a new template. The API cannot delete templates. +To start a new campaign email from the template, send the `id` of the template as `templateId` (`template_id`) when you [create a campaign with the simple editor](#create-a-campaign-with-the-simple-editor). + ```java // import .... diff --git a/src/main/java/com/mailerlite/sdk/emails/EmailBase.java b/src/main/java/com/mailerlite/sdk/emails/EmailBase.java index 880d609..358cf56 100644 --- a/src/main/java/com/mailerlite/sdk/emails/EmailBase.java +++ b/src/main/java/com/mailerlite/sdk/emails/EmailBase.java @@ -47,8 +47,9 @@ public class EmailBase extends ApiResource { public String editor; /** - * The template ID: the template the new email starts from. Allowed only when {@code editor} is {@code simple}, - * accepts only a template from the shared gallery, and also has to be the same across every email. + * The template ID: the simple editor template the new email starts from. It is a template from the shared + * gallery, or a template that you saved from your own email with {@code Emails.createTemplate()}. Allowed only + * when {@code editor} is {@code simple}, and also has to be the same across every email. *
* If it is null, the SDK does not send it. Only {@code CampaignBuilder.create()} accepts it. If it is set, * {@code CampaignBuilder.update()} gets a 422 error. diff --git a/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java b/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java index bd7569e..8048de6 100644 --- a/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java +++ b/src/main/java/com/mailerlite/sdk/emails/EmailRejected.java @@ -10,7 +10,10 @@ import com.google.gson.annotations.SerializedName; /** - * The unsafe values that the API removed or replaced. The request is still a success. + * The values that the API removed or replaced. The request is still a success. + *
+ * For settings, these are unsafe values. For a block, these are the attributes and the mobile keys that the block + * type does not declare. */ public class EmailRejected { @@ -18,7 +21,9 @@ public class EmailRejected { @SerializedName("message") public String message; - /** The paths of the values, for example "footer.social_links[0].url". */ + /** + * The paths of the values, for example "footer.social_links[0].url" or "editor_content.attrs.onclick". + */ @SerializedName("keys") public String[] keys; } diff --git a/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java b/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java index ba1c939..5d313a6 100644 --- a/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java +++ b/src/main/java/com/mailerlite/sdk/emails/EmailValidation.java @@ -33,7 +33,9 @@ public class EmailValidation extends MailerLiteResponse { public EmailSchema schema; /** - * The unsafe values that an update would remove, or null if there are none. Only the validation of settings has it. + * The values that the write would remove, or null if there are none. The API sends it only when valid is true. + * For settings, these are unsafe values. For a block, these are the attributes and the mobile keys that the + * block type does not declare. */ @SerializedName("rejected") public EmailRejected rejected; diff --git a/src/main/java/com/mailerlite/sdk/emails/Emails.java b/src/main/java/com/mailerlite/sdk/emails/Emails.java index c0aebb6..cc95a0d 100644 --- a/src/main/java/com/mailerlite/sdk/emails/Emails.java +++ b/src/main/java/com/mailerlite/sdk/emails/Emails.java @@ -103,6 +103,9 @@ public SingleEmailBlock getBlock(String emailId, String blockId) throws MailerLi *
* Without a placement, the API puts the block at the end of the email. The response has the new block with * its placement and the new etag. + *
+ * The API removes the attributes and the mobile keys that the block type does not declare, and the insert is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param etag the etag from the last response for the email @@ -121,6 +124,9 @@ public SingleEmailBlock createBlock(String emailId, String etag, EmailBlockInput *
* Without a placement, the API puts the block at the end of the email. The response has the new block with * its placement and the new etag. + *
+ * The API removes the attributes and the mobile keys that the block type does not declare, and the insert is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param etag the etag from the last response for the email @@ -144,6 +150,9 @@ public SingleEmailBlock createBlock(String emailId, String etag, EmailBlockInput *
* The new editor content replaces the whole content of the block. The API removes the keys that you do not * send. Read the block, change it, and send the full editor content. + *
+ * The API removes the attributes and the mobile keys that the block type does not declare, and the update is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param blockId the block ID @@ -163,6 +172,9 @@ public SingleEmailBlock updateBlock(String emailId, String blockId, String etag, *
* The new editor content replaces the whole content of the block. The API removes the keys that you do not * send. Read the block, change it, and send the full editor content. + *
+ * The API removes the attributes and the mobile keys that the block type does not declare, and the update is + * still a success. Then the rejected field of the response has their paths. Otherwise it is null. * * @param emailId the email ID * @param blockId the block ID @@ -267,6 +279,7 @@ public SingleEmailBlock moveBlock(String emailId, String blockId, String etag, E * Checks a block with the rules of an insert, and saves nothing. It needs no email and no etag. *
* An invalid block is not an error: the response has valid set to false and the errors for each field. + * If the block is valid and an insert would remove attributes, rejected has their paths. * * @param block the block to check. A null block sends an empty body. * @return the result of the validation @@ -354,6 +367,9 @@ public EmailValidation validateSettings(String emailId, EmailSettings settings) /** * Copies an email to a new template. The API cannot delete templates. + *
+ * To start a new campaign email from the template, set the templateId of the email to the ID of the template + * when you create a campaign with the simple editor. * * @param emailId the email ID * @param name the name of the new template @@ -367,6 +383,9 @@ public SingleEmailTemplate createTemplate(String emailId, String name) throws Ma /** * Copies an email to a new template. The API cannot delete templates. + *
+ * To start a new campaign email from the template, set the templateId of the email to the ID of the template
+ * when you create a campaign with the simple editor.
*
* @param emailId the email ID
* @param name the name of the new template
diff --git a/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java b/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java
index d9431fc..ea0dcfa 100644
--- a/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java
+++ b/src/main/java/com/mailerlite/sdk/emails/SingleEmailBlock.java
@@ -22,4 +22,11 @@ public class SingleEmailBlock extends MailerLiteResponse {
/** The etag of the email. Send it with the next write to the email. */
@SerializedName("etag")
public String etag;
+
+ /**
+ * The attributes that the API removed from the block, or null if there are none. Only createBlock and
+ * updateBlock fill it. getBlock and moveBlock leave it null.
+ */
+ @SerializedName("rejected")
+ public EmailRejected rejected;
}
diff --git a/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java b/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java
index ed78be7..fa45e58 100644
--- a/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java
+++ b/src/test/java/com/mailerlite/sdk/tests/EmailsTest.java
@@ -275,6 +275,7 @@ public void getBlockDecodesTheBlock() throws Exception
assertEquals("56", response.block.placement.after);
assertNull(response.block.placement.before);
assertNull(response.block.children);
+ assertNull(response.rejected);
}
@Test
@@ -378,6 +379,24 @@ public void createBlockSendsTheBlock() throws Exception
assertEquals("center", map(response.block.editorContent, "attrs").get("textAlign"));
assertEquals("57", response.block.placement.after);
assertNull(response.block.placement.before);
+ assertNull(response.rejected);
+ }
+
+ @Test
+ public void createBlockReadsTheRejectedAttributes() throws Exception
+ {
+ client.respond(201, Fixtures.read("email_block_created_rejected.json"));
+
+ Map