Skip to content

Add SandboxMessagesAPI#list_each#101

Open
i7an wants to merge 2 commits intomainfrom
sandbox-messages-list-each
Open

Add SandboxMessagesAPI#list_each#101
i7an wants to merge 2 commits intomainfrom
sandbox-messages-list-each

Conversation

@i7an
Copy link
Contributor

@i7an i7an commented Mar 17, 2026

Motivation

Unify pagination approach.

Changes

  • Added SandboxMessagesAPI#list_each

Summary by CodeRabbit

  • New Features
    • Added list_each method to Sandbox Messages API for automatic pagination over all messages. This method simplifies iterating through large message sets without manual page handling.

@i7an i7an requested review from DagonWat and mklocek March 17, 2026 16:18
@i7an i7an changed the base branch from main to email-logs-api March 17, 2026 16:19
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 85d8be1d-b418-4f0e-98d9-64cb2562e5a3

📥 Commits

Reviewing files that changed from the base of the PR and between 3bfe096 and 7147107.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • lib/mailtrap/email_logs_api.rb
  • lib/mailtrap/sandbox_messages_api.rb
  • spec/fixtures/vcr_cassettes/Mailtrap_SandboxMessagesAPI/_list_each/iterates_over_all_messages.yml
  • spec/mailtrap/email_logs_api_spec.rb
  • spec/mailtrap/sandbox_messages_api_spec.rb

📝 Walkthrough

Walkthrough

This PR introduces list_each to the SandboxMessagesAPI for automatic pagination across all messages using cursor-based pagination, while refactoring the existing list_each in EmailLogsAPI to use an internal Enumerator with lazy first-page fetching. Both implementations support returning an Enumerator when no block is provided or iterating when a block is given.

Changes

Cohort / File(s) Summary
API Implementation
lib/mailtrap/sandbox_messages_api.rb, lib/mailtrap/email_logs_api.rb
Added new list_each(search: nil, &block) to SandboxMessagesAPI for cursor-based pagination over all messages; refactored EmailLogsAPI's list_each to use internal Enumerator with lazy first-page fetch and embedded paging loop.
Test Coverage
spec/mailtrap/sandbox_messages_api_spec.rb, spec/mailtrap/email_logs_api_spec.rb, spec/fixtures/vcr_cassettes/Mailtrap_SandboxMessagesAPI/_list_each/...
Added tests for SandboxMessagesAPI's new list_each method covering Enumerator return and multi-page iteration; updated EmailLogsAPI tests to reflect refactored enumerator behavior; added VCR cassette fixture recording paginated API interactions.
Documentation
CHANGELOG.md
Added entry documenting new list_each feature in Sandbox Messages API.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant SandboxMessagesAPI
    participant MailtrapAPI as Mailtrap API
    participant Consumer

    Client->>SandboxMessagesAPI: list_each(search:)
    Note over SandboxMessagesAPI: Create Enumerator
    
    alt Block provided
        SandboxMessagesAPI->>SandboxMessagesAPI: Iterate enumerator
    else No block
        Client->>Client: Receive Enumerator
    end
    
    SandboxMessagesAPI->>MailtrapAPI: GET /messages (first page)
    MailtrapAPI-->>SandboxMessagesAPI: Messages + cursor
    
    loop For each page
        SandboxMessagesAPI->>Consumer: Yield each message
        alt Has next page
            SandboxMessagesAPI->>MailtrapAPI: GET /messages?last_id=cursor
            MailtrapAPI-->>SandboxMessagesAPI: Next page of messages
        else Empty page
            Note over SandboxMessagesAPI: Stop iteration
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #100: Added EmailLogsAPI with initial list_each implementation that is now being refactored in this PR.
  • #82: Introduced SandboxMessagesAPI class that is being extended with the new list_each method.

Suggested reviewers

  • IgorDobryn
  • DagonWat

Poem

🐰 Hops with glee o'er paginated streams,
Each message caught in enumerator's dreams,
With cursors dancing through infinite lists,
No page goes unconsumed by bunny's fists! 🌕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description includes Motivation and Changes sections as per the template, but omits the How to test and Images and GIFs sections which are expected. Complete the description by adding the How to test section with test checkboxes and clarify if Images and GIFs are applicable, or explicitly note N/A if not relevant.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main change: adding a new list_each method to SandboxMessagesAPI.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sandbox-messages-list-each
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

Base automatically changed from email-logs-api to main March 18, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants