Conversation
📝 WalkthroughWalkthroughIntroduces a new Sending Stats API: adds Mailtrap::StatsAPI, DTOs for SendingStats and SendingStatGroup, example usage, VCR fixtures, and RSpec coverage; loads new modules and bumps gem version to 2.9.0. Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant StatsAPI as StatsAPI
participant Query as QueryBuilder
participant HTTP as HTTPClient
participant Remote as Remote API
participant Parser as ResponseParser
Client->>StatsAPI: get(start_date, end_date, filters)
StatsAPI->>Query: build_query_params(dates, filters)
Query-->>StatsAPI: query_params
StatsAPI->>HTTP: GET /api/accounts/{id}/stats?...
HTTP->>Remote: HTTP GET request
Remote-->>HTTP: 200 JSON response
HTTP-->>StatsAPI: response body
StatsAPI->>Parser: parse to SendingStats
Parser-->>StatsAPI: SendingStats
StatsAPI-->>Client: SendingStats
Client->>StatsAPI: by_domains(start_date, end_date, filters)
StatsAPI->>Query: build_query_params(dates, filters)
Query-->>StatsAPI: query_params
StatsAPI->>HTTP: GET /api/accounts/{id}/stats/domains?...
HTTP->>Remote: HTTP GET request
Remote-->>HTTP: 200 JSON array
HTTP-->>StatsAPI: response body
StatsAPI->>Parser: map to SendingStatGroup[]
Parser-->>StatsAPI: SendingStatGroup array
StatsAPI-->>Client: grouped stats array
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c5a2318 to
bd40917
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
examples/stats_api.rb (1)
3-5: Use ENV-based placeholders for runnable credentials.For executable examples, prefer
ENV.fetchforaccount_idandapi_keyto reduce accidental hardcoded-secret edits in local copies.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/stats_api.rb` around lines 3 - 5, Replace hardcoded credentials with ENV-based placeholders: use ENV.fetch to obtain the API key and account id and convert the account id to an integer before constructing Mailtrap::StatsAPI. Update the account_id variable (currently "account_id = 3229"), the Mailtrap::Client.new call that passes api_key: 'your-api-key', and the Mailtrap::StatsAPI.new(account_id, client) usage to read ENV.fetch('MAILTRAP_ACCOUNT_ID') (to_i) and ENV.fetch('MAILTRAP_API_KEY') so the example is runnable without hardcoded secrets.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@spec/mailtrap/stats_api_spec.rb`:
- Around line 12-159: Add a cassette-backed spec that exercises the optional
array filters and [] serialization by calling the relevant API method (e.g.,
stats_api.get or a grouping method like stats_api.by_categories) with filter
params sending_domain_ids, sending_streams, categories, and
email_service_providers set to arrays; assert the request was recorded/played
(VCR cassette) and that the response mapping still succeeds, and additionally
verify the request query string uses the [] form (e.g.,
"sending_domain_ids[]=1") or that the client sent multiple param[] entries—use
the existing examples (subject(:stats) { ... }) and test helpers (match_struct)
to validate the returned stats while exercising these filters so query param
construction/regression is covered.
---
Nitpick comments:
In `@examples/stats_api.rb`:
- Around line 3-5: Replace hardcoded credentials with ENV-based placeholders:
use ENV.fetch to obtain the API key and account id and convert the account id to
an integer before constructing Mailtrap::StatsAPI. Update the account_id
variable (currently "account_id = 3229"), the Mailtrap::Client.new call that
passes api_key: 'your-api-key', and the Mailtrap::StatsAPI.new(account_id,
client) usage to read ENV.fetch('MAILTRAP_ACCOUNT_ID') (to_i) and
ENV.fetch('MAILTRAP_API_KEY') so the example is runnable without hardcoded
secrets.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 123b0e56-2fa0-4011-b3ed-cec1ba30ca8d
📒 Files selected for processing (15)
CHANGELOG.mdREADME.mdexamples/stats_api.rblib/mailtrap.rblib/mailtrap/sending_stat_group.rblib/mailtrap/sending_stats.rblib/mailtrap/stats_api.rbspec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_by_categories/returns_stats_grouped_by_categories.ymlspec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_by_date/returns_stats_grouped_by_date.ymlspec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_by_domains/returns_stats_grouped_by_domains.ymlspec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_by_email_service_providers/returns_stats_grouped_by_email_service_providers.ymlspec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_get/returns_aggregated_sending_stats.ymlspec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_get/when_api_key_is_incorrect/raises_authorization_error.ymlspec/mailtrap/stats_api_spec.rbspec/spec_helper.rb
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
spec/mailtrap/stats_api_spec.rb (1)
27-49:⚠️ Potential issue | 🟡 MinorStill missing an assertion for
[]query serialization.This example exercises the filters, but it only checks response mapping. The PR’s main risk is the outgoing query shape (
sending_domain_ids[],sending_streams[], etc.), and that still is not asserted here.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/mailtrap/stats_api_spec.rb` around lines 27 - 49, The test exercises stats_api.get with filter arrays but doesn't assert that array query params are serialized with trailing brackets (e.g. sending_domain_ids[], sending_streams[], categories[], email_service_providers[]); update the spec for stats_api.get to also assert the outgoing request/query string includes those bracketed keys — either by inspecting the stubbed HTTP request made by the client or by asserting the full generated query params on the request double used in the test so the spec ensures correct "[]"-style serialization for sending_domain_ids, sending_streams, categories and email_service_providers.
🧹 Nitpick comments (1)
spec/mailtrap/stats_api_spec.rb (1)
68-92: Avoid coupling grouped-spec assertions to response order.These examples all pin
first/last. If the API returns the same groups in a different order, the SDK is still correct but the suite fails. Prefer sorting byvaluefirst or using order-insensitive expectations.Also applies to: 98-123, 129-153, 159-183
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/mailtrap/stats_api_spec.rb` around lines 68 - 92, The test assumes a fixed response order by using stats.first/stats.last which makes it flaky; update the assertions to be order-insensitive by either sorting the stats array by the grouping key (e.g., sort by element[:value]) before asserting, or locate each group by its value and assert its contents (use stats.find { |s| s[:value] == 1 } and stats.find { |s| s[:value] == 2 }), and keep the existing match_struct checks (name: :sending_domain_id, value: ..., stats: ...) unchanged so the test validates group contents regardless of order.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@spec/mailtrap/stats_api_spec.rb`:
- Around line 27-49: The test exercises stats_api.get with filter arrays but
doesn't assert that array query params are serialized with trailing brackets
(e.g. sending_domain_ids[], sending_streams[], categories[],
email_service_providers[]); update the spec for stats_api.get to also assert the
outgoing request/query string includes those bracketed keys — either by
inspecting the stubbed HTTP request made by the client or by asserting the full
generated query params on the request double used in the test so the spec
ensures correct "[]"-style serialization for sending_domain_ids,
sending_streams, categories and email_service_providers.
---
Nitpick comments:
In `@spec/mailtrap/stats_api_spec.rb`:
- Around line 68-92: The test assumes a fixed response order by using
stats.first/stats.last which makes it flaky; update the assertions to be
order-insensitive by either sorting the stats array by the grouping key (e.g.,
sort by element[:value]) before asserting, or locate each group by its value and
assert its contents (use stats.find { |s| s[:value] == 1 } and stats.find { |s|
s[:value] == 2 }), and keep the existing match_struct checks (name:
:sending_domain_id, value: ..., stats: ...) unchanged so the test validates
group contents regardless of order.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2ffca3dc-28fe-4244-b8d2-5be950b6e72f
⛔ Files ignored due to path filters (1)
Gemfile.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
CHANGELOG.mdlib/mailtrap/version.rbspec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_get/with_optional_filters/returns_filtered_sending_stats.ymlspec/mailtrap/stats_api_spec.rb
✅ Files skipped from review due to trivial changes (1)
- spec/fixtures/vcr_cassettes/Mailtrap_StatsAPI/_get/with_optional_filters/returns_filtered_sending_stats.yml
🚧 Files skipped from review as they are similar to previous changes (1)
- CHANGELOG.md
Motivation
Changes
How to test
Mailtrap::StatsAPI.new(account_id, client).getmethod with different parameters (start_date, end_date, sending_domain_ids[], sending_streams[], categories[], email_service_providers[])Examples
Summary by CodeRabbit
New Features
Documentation
Examples
Tests
Chores