mailtrap-ruby icon indicating copy to clipboard operation
mailtrap-ruby copied to clipboard

add projects API

Open jurgens opened this issue 5 months ago • 3 comments

Motivation

add API support for projects

Changes

  • add projects API wrapper and project struct
  • add specs and rubydocs

Summary by CodeRabbit

  • New Features

    • Project management added: list, retrieve, create, update, and delete projects via the API.
  • Tests

    • Comprehensive test coverage and recorded HTTP fixtures for project operations, including success and error scenarios.
  • Chores

    • Repository ignore list updated to exclude a new developer file (.claude).

jurgens avatar Aug 05 '25 13:08 jurgens

Walkthrough

A new ProjectsAPI class and Project struct were added for project CRUD operations. Tests and many VCR fixtures were added/updated. Spec helper VCR redaction logic was changed. Client initialization no longer auto-selects an api_host. A .claude entry was added to .gitignore.

Changes

Cohort / File(s) Summary
Core Projects API
lib/mailtrap.rb, lib/mailtrap/project.rb, lib/mailtrap/projects_api.rb
Added Mailtrap::Project struct with to_h and introduced Mailtrap::ProjectsAPI with list, get, create, update, delete, base_path and wrap_request. lib/mailtrap.rb now requires the new API file.
Client
lib/mailtrap/client.rb
Removed automatic api_host selection (`api_host
VCR / Test infra
spec/spec_helper.rb, .gitignore
Reworked VCR filtering: removed some account_id redactions, added config.filter_sensitive_data('ACCOUNT_ID', ENV.fetch('MAILTRAP_ACCOUNT_ID')), and added a before_record hook to redact share_links in responses. Added .claude to .gitignore.
Projects API tests
spec/mailtrap/project_spec.rb, spec/mailtrap/projects_api_spec.rb
Added RSpec tests for Mailtrap::Project and full CRUD coverage for Mailtrap::ProjectsAPI, including success and error scenarios (auth, not-found).
Projects API fixtures
spec/fixtures/vcr_cassettes/Mailtrap_ProjectsAPI/*
Added many VCR cassettes covering list/get/create/update/delete flows and error cases (401, 404, 422), plus variants (hash requests, name-only updates, delete return).
EmailTemplates fixtures (refreshed)
spec/fixtures/vcr_cassettes/Mailtrap_EmailTemplatesAPI/*
Updated numerous EmailTemplates VCR cassettes: replaced hard-coded account IDs with ACCOUNT_ID, refreshed timestamps, headers (Date, Cf‑Ray/Server), CSP nonces and related metadata; no code/API signature changes.
Other fixtures updated
spec/fixtures/vcr_cassettes/Mailtrap_SuppressionsAPI/...
Updated recorded interaction(s) to use ACCOUNT_ID placeholder and refreshed request/response metadata (timestamps, headers, CSP nonce).

Sequence Diagram(s)

sequenceDiagram
    rect rgba(200,230,201,0.6)
    participant Test
    participant ProjectsAPI as Projects API
    participant BaseAPI as Base API
    participant Server as Mailtrap API
    end

    Test->>ProjectsAPI: list()
    ProjectsAPI->>BaseAPI: base_list(path: /api/accounts/{account_id}/projects)
    BaseAPI->>Server: GET /api/accounts/{id}/projects
    Server-->>BaseAPI: 200 [projects JSON]
    BaseAPI->>ProjectsAPI: [mapped Project objects]
    ProjectsAPI-->>Test: [Mailtrap::Project[]]

    Test->>ProjectsAPI: create({name: "New Project"})
    ProjectsAPI->>ProjectsAPI: wrap_request(params) -> { project: {...} }
    ProjectsAPI->>BaseAPI: base_create(body: { project: {...} })
    BaseAPI->>Server: POST /api/accounts/{id}/projects
    Server-->>BaseAPI: 200/201 [project JSON]
    BaseAPI->>ProjectsAPI: Project object
    ProjectsAPI-->>Test: Mailtrap::Project

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay attention to the client initialization change in lib/mailtrap/client.rb (behavioral risk if callers expect auto-selection of api_host).
  • Verify spec/spec_helper.rb VCR before_record redaction correctly handles both Hash and Array response bodies and does not mangle unrelated fixtures.
  • Confirm ProjectsAPI#wrap_request and base_path align with BaseAPI conventions (payload wrapping and path construction).
  • Large numbers of regenerated VCR fixtures (EmailTemplates, ProjectsAPI) should be scanned to ensure only intended changes (placeholders, timestamps, CSP/header updates) are present.

Suggested reviewers

  • IgorDobryn
  • VladimirTaytor

Poem

🐰 I hopped in quick with struct and route,
CRUD carrots ready, no need to shout.
Tests recorded, share links tucked away,
Client kept tidy — hop, hop, hooray!
The warren’s cleaner for another day. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a projects API, which is the primary objective of this pull request.
Description check ✅ Passed The PR description provides motivation and lists key changes, but omits the 'How to test' and 'Images and GIFs' sections from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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.

coderabbitai[bot] avatar Aug 05 '25 13:08 coderabbitai[bot]

@IgorDobryn @i7an guys, i believe it's ready for a merge conflicts resolved and tests are green

jurgens avatar Nov 06 '25 17:11 jurgens

@IgorDobryn @i7an guys, i believe it's ready for a merge conflicts resolved and tests are green

tests are still failing as before.

See https://github.com/mailtrap/mailtrap-ruby/pull/67#pullrequestreview-3239585499

i7an avatar Nov 19 '25 14:11 i7an