-
Notifications
You must be signed in to change notification settings - Fork 7
Add Sandbox Projects API #78
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
Changes from all commits
7a51baf
657ad0a
c5132a5
3cf8e26
2173be8
107f2ba
dee41d1
886a763
471f831
605cc2e
e12ab39
193fee3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| require 'mailtrap' | ||
|
|
||
| account_id = 3229 | ||
| client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
| projects_api = Mailtrap::ProjectsAPI.new(account_id, client) | ||
|
|
||
| # Set your API credentials as environment variables | ||
| # export MAILTRAP_API_KEY='your-api-key' | ||
| # export MAILTRAP_ACCOUNT_ID=your-account-id | ||
| # | ||
| # projects_api = Mailtrap::ProjectsAPI.new | ||
|
|
||
| # Get all projects | ||
| projects_api.list | ||
|
|
||
| # Create a new project | ||
| project = projects_api.create( | ||
| name: 'Example Project' | ||
| ) | ||
|
|
||
| # Get a project | ||
| project = projects_api.get(project.id) | ||
|
|
||
| # Update a project | ||
| project = projects_api.update(project.id, name: 'New Project name') | ||
|
|
||
| # Delete a project | ||
| projects_api.delete(project.id) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mailtrap | ||
| # Data Transfer Object for Inbox | ||
| # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project | ||
| # @attr_reader id [Integer] The inbox ID | ||
| # @attr_reader name [String] The inbox name | ||
| # @attr_reader username [String] The inbox username | ||
| # @attr_reader password [String, nil] The inbox password | ||
| # @attr_reader max_size [Integer] The maximum inbox size in MB | ||
| # @attr_reader status [String] The inbox status | ||
| # @attr_reader email_username [String] The email username | ||
| # @attr_reader email_username_enabled [Boolean] Whether the email username is enabled | ||
| # @attr_reader sent_messages_count [Integer] The count of sent messages | ||
| # @attr_reader forwarded_messages_count [Integer] The count of forwarded messages | ||
| # @attr_reader used [Integer] The used inbox size in MB | ||
| # @attr_reader forward_from_email_address [String] The forwarding email address | ||
| # @attr_reader project_id [Integer] The associated project ID | ||
| # @attr_reader domain [String] The inbox domain | ||
| # @attr_reader pop3_domain [String] The POP3 domain | ||
| # @attr_reader email_domain [String] The email domain | ||
| # @attr_reader api_domain [String] The API domain | ||
| # @attr_reader emails_count [Integer] The total number of emails | ||
| # @attr_reader emails_unread_count [Integer] The number of unread emails | ||
| # @attr_reader last_message_sent_at [String, nil] The timestamp of the last sent message | ||
| # @attr_reader smtp_ports [Array<Integer>] The list of SMTP ports | ||
| # @attr_reader pop3_ports [Array<Integer>] The list of POP3 ports | ||
| # @attr_reader max_message_size [Integer] The maximum message size in MB | ||
| # @attr_reader permissions [Hash] List of permissions | ||
| Inbox = Struct.new( | ||
| :id, | ||
| :name, | ||
| :username, | ||
| :password, | ||
| :max_size, | ||
| :status, | ||
| :email_username, | ||
| :email_username_enabled, | ||
| :sent_messages_count, | ||
| :forwarded_messages_count, | ||
| :used, | ||
| :forward_from_email_address, | ||
| :project_id, | ||
| :domain, | ||
| :pop3_domain, | ||
| :email_domain, | ||
| :api_domain, | ||
| :emails_count, | ||
| :emails_unread_count, | ||
| :last_message_sent_at, | ||
| :smtp_ports, | ||
| :pop3_ports, | ||
| :max_message_size, | ||
| :permissions, | ||
| keyword_init: true | ||
| ) | ||
| end |
DagonWat marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mailtrap | ||
| # Data Transfer Object for Project | ||
| # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project | ||
| # @attr_reader id [Integer] The project ID | ||
| # @attr_reader name [String] The project name | ||
| # @attr_reader share_links [Hash] Admin and viewer share links | ||
| # @attr_reader inboxes [Array<Mailtrap::Inbox>] Array of inboxes | ||
| # @attr_reader permissions [Hash] List of permissions | ||
| # | ||
| Project = Struct.new( | ||
| :id, | ||
| :name, | ||
| :share_links, | ||
| :inboxes, | ||
| :permissions, | ||
| keyword_init: true | ||
| ) | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'base_api' | ||
| require_relative 'project' | ||
| require_relative 'inbox' | ||
|
|
||
| module Mailtrap | ||
| class ProjectsAPI | ||
| include BaseAPI | ||
|
|
||
| self.supported_options = %i[name] | ||
|
|
||
| self.response_class = Project | ||
|
|
||
| # Lists all projects for the account | ||
| # @return [Array<Project>] Array of projects | ||
| # @!macro api_errors | ||
| def list | ||
| base_list | ||
| end | ||
|
|
||
| # Retrieves a specific project | ||
| # @param project_id [Integer] The project ID | ||
| # @return [Project] Project object | ||
| # @!macro api_errors | ||
| def get(project_id) | ||
| base_get(project_id) | ||
| end | ||
|
|
||
| # Creates a new project | ||
| # @param [Hash] options The parameters to create | ||
| # @option options [String] :name The project name | ||
| # @return [Project] Created project object | ||
| # @!macro api_errors | ||
| # @raise [ArgumentError] If invalid options are provided | ||
| def create(options) | ||
| base_create(options) | ||
| end | ||
|
|
||
| # Updates an existing project | ||
| # @param project_id [Integer] The project ID | ||
| # @param [Hash] options The parameters to update | ||
| # @return [Project] Updated project object | ||
| # @!macro api_errors | ||
| # @raise [ArgumentError] If invalid options are provided | ||
| def update(project_id, options) | ||
| base_update(project_id, options) | ||
| end | ||
|
|
||
| # Deletes a project | ||
| # @param project_id [Integer] The project ID | ||
| # @return nil | ||
| # @!macro api_errors | ||
| def delete(project_id) | ||
| base_delete(project_id) | ||
| end | ||
|
Comment on lines
+50
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the return value documentation. The YARD comment states 📝 Suggested fix- # @return nil
+ # @return [Hash] The deleted project response, e.g., { id: project_id }🤖 Prompt for AI Agents |
||
|
|
||
| private | ||
|
|
||
| def handle_response(response) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must be |
||
| build_entity( | ||
| response.merge( | ||
| inboxes: response[:inboxes]&.map { |inbox| build_entity(inbox, Mailtrap::Inbox) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is still not covered by any spec. |
||
| ), | ||
| response_class | ||
| ) | ||
| end | ||
|
|
||
| def base_path | ||
| "/api/accounts/#{account_id}/projects" | ||
| end | ||
|
|
||
| def wrap_request(options) | ||
| { project: options } | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Email templates are already a big chunk of examples, I see no reason to have it here.