MT-22401: Add Email Campaigns API - #119
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds typed email campaign entities and a ChangesEmail Campaigns API
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant EmailCampaignsAPI
participant CampaignsEndpoint
Client->>EmailCampaignsAPI: create, update, or list campaigns
EmailCampaignsAPI->>CampaignsEndpoint: send campaign request
CampaignsEndpoint-->>EmailCampaignsAPI: return campaign or list data
EmailCampaignsAPI-->>Client: return typed response
Client->>EmailCampaignsAPI: schedule, start, or retrieve stats
EmailCampaignsAPI->>CampaignsEndpoint: send lifecycle or statistics request
CampaignsEndpoint-->>EmailCampaignsAPI: return action or statistics data
EmailCampaignsAPI-->>Client: return typed result
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/mailtrap/email_campaigns_api.rb (1)
104-110: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFix YARD
@returntag format fordelete.
#@returnnil(Line 106) should be#@return[nil]to match the@return [Type] descriptionconvention used by every other method in this file, so YARD parses the return type correctly.📝 Proposed fix
# Deletes an email campaign. The campaign must not be in a sending state. # `@param` email_campaign_id [Integer] The email campaign ID - # `@return` nil + # `@return` [nil] # @!macro api_errors def delete(email_campaign_id)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/mailtrap/email_campaigns_api.rb` around lines 104 - 110, Update the YARD documentation for the delete method so its `@return` annotation uses the bracketed type format [nil], matching the convention used throughout the file; leave the delete implementation unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/mailtrap/email_campaigns_api.rb`:
- Around line 104-110: Update the YARD documentation for the delete method so
its `@return` annotation uses the bracketed type format [nil], matching the
convention used throughout the file; leave the delete implementation unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 618f5e87-eb29-4288-a78d-8517b08aaaf8
📒 Files selected for processing (7)
README.mdexamples/email_campaigns_api.rblib/mailtrap.rblib/mailtrap/email_campaign.rblib/mailtrap/email_campaigns_api.rbspec/mailtrap/email_campaign_spec.rbspec/mailtrap/email_campaigns_api_spec.rb
|
Addressed the CodeRabbit nitpick: |
Decisions:
- Request bodies are flat (no {email_campaign: ...} wrapper), matching the controller's top-level params; create and update accept the same writable set
- Single-object and stats responses unwrap the {data: ...} envelope (WebhooksAPI pattern); list returns {data, pagination} via EmailCampaignsListResponse
- delete uses base_delete and returns nil (API responds 204 No Content)
- Five lifecycle endpoints (start/schedule/cancel/terminate/reset) share a private perform_action helper; schedule takes an ISO 8601 datetime
- list(name:) maps to the search query param to filter by name; API is token-scoped, so the constructor takes only a client (AccountsAPI precedent)
4f60fa8 to
42ce077
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/email_campaigns_api.rb`:
- Around line 50-52: Update the example around email_campaigns.schedule and the
delivery-statistics query to use execution-relative future dates and a
statistics window that includes the newly scheduled campaign’s activity;
alternatively, clearly mark the shown outputs as illustrative. Keep the
scheduling and query behavior consistent so the example does not use dates
already in the past or a range that excludes the created campaign.
- Around line 62-68: Update the Email Campaign termination example around
terminate to poll the campaign with get until current_state is no longer
"terminating" or otherwise sending, then call delete only after it reaches a
deletable terminal state; keep the reset example unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9707087e-01e7-485e-81dc-79be917c869e
📒 Files selected for processing (7)
README.mdexamples/email_campaigns_api.rblib/mailtrap.rblib/mailtrap/email_campaign.rblib/mailtrap/email_campaigns_api.rbspec/mailtrap/email_campaign_spec.rbspec/mailtrap/email_campaigns_api_spec.rb
🚧 Files skipped from review as they are similar to previous changes (5)
- README.md
- spec/mailtrap/email_campaign_spec.rb
- lib/mailtrap.rb
- spec/mailtrap/email_campaigns_api_spec.rb
- lib/mailtrap/email_campaigns_api.rb
42ce077 to
e17f815
Compare
| # => #<struct Mailtrap::EmailCampaign id=4567, name="Spring Sale", current_state="draft", ...> | ||
|
|
||
| # Get all Email Campaigns (paginated, newest first; filter by name) | ||
| list = email_campaigns.list(per_page: 50, name: 'Spring') |
There was a problem hiding this comment.
In other SDK search param name is search. Is there any reason to keep it as name?
There was a problem hiding this comment.
Fixed: renamed the list keyword to search to match the other SDKs and the OpenAPI spec.
Decisions: - align with other SDKs and the OpenAPI spec, which expose the campaign filter as `search`
|
|
||
| describe '#list' do | ||
| it 'returns a paginated list of EmailCampaign objects' do | ||
| stub_request(:get, base_url) |
There was a problem hiding this comment.
Isn't the convention here to record VCR cassettes?
Motivation
MT-22401
Port the Email Campaigns public API (MT-21113) to the Ruby SDK.
Changes
Mailtrap::EmailCampaignsAPIcovering the full contract: list (page-token pagination + name filter), get, create, update, delete, the five lifecycle actions (start,schedule,cancel,terminate,reset), andstatswith an optional date rangeMailtrap::EmailCampaign/EmailCampaignStats/EmailCampaignsListResponseDTOs matching the OpenAPI schema (audience ids, template withbody_html/body_text/merge_tags, 10-state lifecycle)dataenvelope, per the published spec;deletereturnsnilon 204examples/email_campaigns_api.rb+ README "Email marketing" entryHow to test
examples/email_campaigns_api.rbwith a real API token and a verified sending domain — create a draft campaign, update its design, schedule + cancel it, fetch stats, delete itcurrent_state, template fields)Summary by CodeRabbit
New Features
Tests