Skip to content

[3.5.0] Add Contact Fields CRUD #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025
Merged

[3.5.0] Add Contact Fields CRUD #46

merged 1 commit into from
Jul 12, 2025

Conversation

gaalferov
Copy link
Collaborator

@gaalferov gaalferov commented Jul 9, 2025

Motivation

Support new functionality (Contact Fields)
https://help.mailtrap.io/article/147-contacts

Changes

  • Add Contact Fields CRUD

How to test

composer test

OR run PHP code from the example

(new MailtrapGeneralClient($config))->contacts($accountId)->getAllContactFields();

Summary by CodeRabbit

  • New Features

    • Added support for managing Contact Fields, including creating, retrieving, updating, and deleting fields through the API.
  • Documentation

    • Updated the changelog with a new version entry documenting Contact Fields API functionality.
    • Expanded the README to list "Fields CRUD" under supported contact management features.
    • Added examples demonstrating Contact Fields management.
  • Tests

    • Introduced comprehensive tests covering all aspects of Contact Fields management.

Copy link

coderabbitai bot commented Jul 9, 2025

Walkthrough

The changes introduce full CRUD support for Contact Fields in the Mailtrap API client. This includes new public methods for field management in the client class, expanded documentation, example usage scripts, comprehensive tests for the new endpoints, and an updated changelog and README to reflect the new functionality.

Changes

File(s) Change Summary
CHANGELOG.md, README.md Added version entry and updated documentation to include Contact Fields CRUD support.
src/Api/General/Contact.php Added five new public methods for Contact Fields CRUD operations using the API.
examples/general/contacts.php Added example usages demonstrating all Contact Fields CRUD operations.
tests/Api/General/ContactTest.php Added new tests covering all Contact Fields CRUD operations, including success and error scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Client as API Client (Contact)
    participant API as Mailtrap API

    Client->>API: GET /contacts/fields (getAllContactFields)
    API-->>Client: List of fields

    Client->>API: GET /contacts/fields/{id} (getContactField)
    API-->>Client: Field details

    Client->>API: POST /contacts/fields (createContactField)
    API-->>Client: Created field

    Client->>API: PATCH /contacts/fields/{id} (updateContactField)
    API-->>Client: Updated field

    Client->>API: DELETE /contacts/fields/{id} (deleteContactField)
    API-->>Client: 204 No Content
Loading

Suggested reviewers

  • leonid-shevtsov
  • IgorDobryn
  • i7an
  • mklocek
  • VladimirTaytor

Poem

In the warren of code, new fields now bloom,
CRUD for contacts—no more gloom!
With docs and tests, the path is clear,
Rabbits cheer and engineers hear:
“Hop to your data, manage with glee—
Contact Fields are now CRUD-fully free!”
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87f2116 and d69e570.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • README.md (1 hunks)
  • examples/general/contacts.php (1 hunks)
  • src/Api/General/Contact.php (1 hunks)
  • tests/Api/General/ContactTest.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
examples/general/contacts.php (2)
src/Api/General/Contact.php (5)
  • getAllContactFields (180-185)
  • getContactField (193-198)
  • createContactField (208-216)
  • updateContactField (226-234)
  • deleteContactField (242-247)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/Api/General/Contact.php (1)
src/Api/AbstractApi.php (5)
  • handleResponse (84-111)
  • httpGet (34-41)
  • httpPost (43-50)
  • httpPatch (61-68)
  • httpDelete (70-77)
🪛 LanguageTool
CHANGELOG.md

[grammar] ~2-~2: There might be a mistake here.
Context: ...] - 2025-07-12 - Add Contact Fields API functionality ## [3.4.0] - 2025-07-04 - Add Batch sendin...

(QB_NEW_EN_OTHER)

🔇 Additional comments (19)
CHANGELOG.md (1)

1-3: LGTM! Well-formatted changelog entry.

The changelog entry follows the established format and appropriately documents the new Contact Fields API functionality.

README.md (1)

33-33: LGTM! Clear documentation update.

The addition of "Fields CRUD" appropriately documents the new Contact Fields functionality and follows the existing format.

examples/general/contacts.php (5)

191-203: LGTM! Comprehensive example for retrieving all contact fields.

The example correctly demonstrates the getAllContactFields() method usage with proper error handling and output formatting.


206-219: LGTM! Well-documented example for retrieving a specific contact field.

The example shows proper usage of getContactField() with appropriate placeholder values and error handling.


222-238: LGTM! Informative example for creating contact fields.

The example demonstrates createContactField() with clear comments explaining the parameter constraints and allowed values for data_type.


241-258: LGTM! Clear example for updating contact fields.

The example shows updateContactField() usage with an important note about the immutability of data_type.


260-273: LGTM! Complete example for deleting contact fields.

The example demonstrates deleteContactField() with proper status code handling instead of response body parsing.

src/Api/General/Contact.php (5)

175-185: LGTM! Well-implemented method for retrieving all contact fields.

The getAllContactFields() method follows the established pattern, uses the correct HTTP GET method, and properly constructs the /fields endpoint.


187-198: LGTM! Proper implementation for retrieving a specific contact field.

The getContactField() method correctly uses the field ID in the URL path and follows the established pattern.


200-216: LGTM! Comprehensive method for creating contact fields.

The createContactField() method properly accepts all required parameters (name, data_type, merge_tag) and constructs the correct POST request body.


218-234: LGTM! Appropriate implementation for updating contact fields.

The updateContactField() method correctly omits data_type from the update payload (as it's immutable) and uses the PATCH method appropriately.


236-247: LGTM! Simple and correct implementation for deleting contact fields.

The deleteContactField() method properly uses the DELETE HTTP method and constructs the correct endpoint URL.

tests/Api/General/ContactTest.php (7)

362-378: LGTM! Comprehensive test for retrieving all contact fields.

The test properly verifies the HTTP GET request to the correct endpoint and validates the response structure including all expected fields.


380-394: LGTM! Well-structured test for retrieving a specific contact field.

The test correctly verifies the field ID is included in the URL path and validates the response data.


396-414: LGTM! Thorough test for creating contact fields.

The test properly verifies the HTTP POST request with all required parameters and validates the response structure.


416-441: LGTM! Excellent test for handling validation errors.

The test demonstrates proper error handling for multiple validation failures, which is important for robustness.


443-463: LGTM! Proper test for updating contact fields.

The test correctly verifies the PATCH request excludes data_type (as it's immutable) and validates the response.


465-477: LGTM! Simple and correct test for deleting contact fields.

The test properly verifies the DELETE request and checks the 204 status code response.


479-485: LGTM! Well-structured helper method for test data.

The getExpectedContactFields() helper method provides consistent test data with all required fields.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gaalferov gaalferov marked this pull request as ready for review July 9, 2025 14:42
@gaalferov gaalferov linked an issue Jul 9, 2025 that may be closed by this pull request
@gaalferov gaalferov merged commit 9fb9143 into main Jul 12, 2025
20 checks passed
@gaalferov gaalferov deleted the feature/contact-fields branch July 12, 2025 10:33
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.

Custom Fields API
3 participants