Repository navigation
Conversation
[Medium risk] The description says to merge and release only after the endpoints appear in the public API documentation, and the release steps say to wait for that too. Nothing in the repository, the description or the account shows that this was met, so it is an unmet prerequisite for merging. The account also reports the CHANGELOG heading as "[Unreleased]", while the description says the 2.1.0 entry carries an "Unreleased" date. The change is additive, with no existing behavior changed, and the new code … FindingsEarlier findings (1 dismissed)
SummaryAdds simple-editor Emails, BrandStyles and Files endpoints with shared request helpers Adds What's good
Review context · 0/5 commands
Reviews (6) · Last reviewed commit: "refactor: leave value checks to the API" · claude-sonnet-5-5 |
Add the JSON fixtures for the email, brand style and file endpoints. Add a helper that reads them in the specs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the error classes for the client-side checks. Add the Params module. It checks path IDs, etags, Hash and String values, block placements, settings and idempotency keys. It also builds query parameters and drops nil values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the ApiResponse module. The new resources extend each response with it. idempotent_replay? reads the Idempotent-Replayed header without case. api_error returns nil for a 2xx status, and an ApiError for other statuses. ApiError has the status, the API code, the etag, the field errors and the API message. It keeps only plain values, so Marshal works. The SDK does not raise it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Request.call. It sends a JSON body only when there is one, so a write without a body sends no body. It sends PATCH and DELETE bodies, adds the query, and adds the Idempotency-Key header when the caller gives a key. It reads the base URL when the request runs, and returns the response with the ApiResponse methods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the Emails class for the emails built with the simple editor, and the constants for the version conflict code, the block types, the block positions and the brand modes. Add Emails#get and its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#get_html. It returns the HTML of an email and its etag. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#get_block. It returns a block of an email, its placement and the etag of the email. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#create_block. It inserts a block in an email. It checks the email ID, the etag, the block type, the content and the block_id of the placement before the request. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#update_block. It sends a PATCH request that replaces the content of a block. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#delete_block. It sends a DELETE request with the etag in the body, and returns the response with the new etag. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#move_block. It moves a block to a new placement in the email. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#validate_block. It checks a block without an email and without an etag. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#update_settings. It sends a PATCH request with the keys of the settings Hash and the etag. It rejects settings that contain an etag key. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#validate_settings. It checks a change to the design settings without an etag, and saves nothing. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#create_template. It saves an email as a new template. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#list_versions. It lists the saved versions of an email, with an optional page and limit. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#create_version. It saves a version of an email and sends no request body. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Emails#restore_version. It restores an email to a saved version and returns the email with the new etag. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the BrandStyles class and BrandStyles#get. It returns the brand, default and preset palettes of the account. Add its README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the Files class and Files#list. It lists the files of the media library with an optional filter, sort, page and limit. It drops nil values from the query. Add the constants for the file types and the sort values, and the README section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the EDITOR_SIMPLE constant to Campaigns. Document the editor and template_id keys of the campaign emails. Campaigns#create already sends each email as it is, so the request code does not change. Add a README section and tests for the request body. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the optional idempotency_key keyword to the 8 email writes. The SDK checks the key and sends it in the Idempotency-Key header. The two validate methods do not accept a key. Add a README section that shows a retry with the same key after a network error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Set the version to 2.1.0, because the change adds methods and does not break the current methods. Add the CHANGELOG entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The API uses block_id only for the before and after positions. For
the other positions, it discards the value without a check.
Before this change, the SDK checked block_id for each position. A
placement such as { position: 'end', block_id: nil } raised
EmptyIdError, but the API accepts it.
Now Params.placement checks block_id only for before and after. For
these positions, a missing block_id raises EmptyIdError. For the
other positions, the SDK removes block_id from the body that it sends.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The validate example used a button with attrs.href and content. The API does not document this shape. Now the example sends a paragraph with textAlign set to sideways, as in the API documentation. A note tells that the block is not valid, so the response has valid: false and errors. The matching spec sends the same block and gets an invalid result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No spec uses this fixture now. The validate example and its spec show an invalid block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An empty string unsets only a brand colour. An empty editor document unsets a footer text. For other colours, sizes, button.border_radius and brand.style, an empty string gives a 422 error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new specs expect the header Authorization: Bearer dummy_token, but only the CI workflow set that token. With a different token or with no token, the WebMock stubs did not match. A shared context now sets the token before each example and restores the old value after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove doc comments that repeat the code in the internal Params and Request helpers and in the specs. Remove notes that only explain names to the reviewer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK now checks only the IDs in the URL path and the settings Hash of update_settings. It sends the placement, the etag, the block values, the template name and the idempotency key as the caller gives them, and the API answers with its errors. Remove EmptyEtagError and InvalidIdempotencyKeyError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
761d723 to
9bc0b51
Compare
Why?
The MailerLite API adds endpoints to read and edit emails that are built with the simple editor. It also adds two related endpoints: brand styles and files. This PR adds all 16 endpoints to the Ruby SDK, so that Ruby users can build and edit these emails without raw HTTP requests.
Merge and release this only after the endpoints are in the public API documentation.
Changes
New
MailerLite::Emailsclass (lib/mailerlite/emails/emails.rb)getGET /emails/{email}get_htmlGET /emails/{email}/htmlget_blockGET /emails/{email}/blocks/{block}create_blockPOST /emails/{email}/blocksupdate_blockPATCH /emails/{email}/blocks/{block}delete_blockDELETE /emails/{email}/blocks/{block}move_blockPOST /emails/{email}/blocks/{block}/movevalidate_blockPOST /emails/blocks/validateupdate_settingsPATCH /emails/{email}/settingsvalidate_settingsPOST /emails/{email}/settings/validatecreate_templatePOST /emails/{email}/templateslist_versionsGET /emails/{email}/versionscreate_versionPOST /emails/{email}/versionsrestore_versionPOST /emails/{email}/versions/{version}/restoreCampaigns.editor_content,placementandsettingsare Hashes. The SDK sends them as they are, so the camelCase keys ofeditor_contentdo not change.delete_blocksends{"etag": ...}in the DELETE body.create_versionsends no body.New
MailerLite::BrandStylesclass:getcallsGET /brand-styles.brandisnullwhen the account has no brand styles.New
MailerLite::Filesclass:listcallsGET /files, with thenameandtypefilters,sort,pageandlimit. The name isFiles, notFile, so that it does not hide theFileclass of Ruby.Responses and errors
HTTP::Response, like all other methods of the gem. They do not raise for an API error.api_errorreturnsnilfor a2xxresponse. For other responses, it returns aMailerLite::ApiErrorwithstatus,code,etag,errorsandapi_message. It also works when the body is not JSON, for example a503HTML page.idempotent_replay?is true when the API returned a stored response (Idempotent-Replayed: true, without case).409withcode == MailerLite::Emails::VERSION_CONFLICTand the currentetag.Checks before the request: the SDK checks a value only when the API cannot see the problem, or when the SDK code must read the value to build the request. If a check fails, the SDK raises the error and sends no request.
MailerLite::EmptyIdError,MailerLite::InvalidIdErrororTypeError. Reason: the API decodes an escaped/in a path, so an escaped ID could reach a different endpoint.update_settingsmerges the etag into thesettingsHash. Asettingsvalue that is not a Hash raisesTypeError, and a Hash with anetagkey raisesArgumentError.filterofFiles#listmust be a Hash, because the SDK buildsfilter[name]from its keys.placement(alsoblock_idforstartandend), the etag (also an empty etag),type,editor_content, the template name and the settings ofvalidate_settings. The API checks them and answers with422, or withvalid: falseon the two validate endpoints.Idempotency keys: the 8 email writes accept an optional
idempotency_key:argument, and the SDK sends it as theIdempotency-Keyheader. If a request with the same key already succeeded, the API returns the stored response again and does not do the write two times. This makes it safe to retry a write after a network error. Without a key (nil), the SDK sends no header. The SDK sends a key as the caller gives it, and the API returns400for a key that is not valid.Campaigns (
lib/mailerlite/campaigns/campaigns.rb):Campaigns#createalready sends each email Hash as it is. The YARD doc now describes theeditorandtemplate_idkeys, and there is a new constant,Campaigns::EDITOR_SIMPLE. Seteditor: MailerLite::Campaigns::EDITOR_SIMPLEto create an email with the simple editor, and then edit it withMailerLite::Emails. Onlycreateaccepts these keys.Shared helpers:
lib/mailerlite/params.rb(the ID and settings checks, and the query builder),request.rb,api_response.rbanderrors.rb. The query builder dropsnilvalues and keeps empty strings.Constants: block types, block positions (
AT_START,AT_END,BEFORE,AFTER, becauseENDis a Ruby keyword), brand modes, file types and file sorts.README: new "Emails", "Brand styles" and "Files" sections, with one example for each method, a "Retry a write with an idempotency key" example, and a campaign example with the simple editor.
Version:
2.1.0inlib/mailerlite/version.rb. TheCHANGELOG.mdentries are under## [Unreleased], after the entries thatmainalready has there.Compatibility
All changes add to the public API. No existing method signature or return value changes, and the existing methods do not change their behavior.
Tests
409withversion_conflict,422witherrors, and503with an HTML body;create_versionwith201and with200, and with an empty raw body;brand: null, and a file name filter with spaces;placementwithoutblock_id, a wrong type): the SDK sends the exact body and returns the API error;true,True, no header), and keys that are not valid, which the SDK sends as given;editoris present andcontentis absent.rspec(246 examples, after the rebase ontomain) passes on Ruby 3.1. RuboCop finds no new offenses.409(old etag),404(unknown block) and422(invalid file type), and an idempotency check: a retry with the same key returned the stored201with the same block ID, the same key with a different body returned422, and a retry without a key returned409.How to test
bundle exec rspec spec/*rspec.rb.editor: MailerLite::Campaigns::EDITOR_SIMPLE, and get the email ID fromdata.emails[0].idof the response.etagof each response to the next write.api_error.codeisMailerLite::Emails::VERSION_CONFLICT.idempotent_replay?is true.How to release
CHANGELOG.md, change## [Unreleased]to## [2.1.0] - <date>. This entry also has the changes that are already onmain.v2.1.0. The tag starts the publish workflow. This is a minor version because all changes are additions.Rollback
No data or configuration changes. To roll back, revert the merge commit and release a new patch version.
🤖 Generated with Claude Code