-
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,62 @@ | ||
| # 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 | ||
| ) do | ||
| # @return [Hash] The inbox attributes as a hash | ||
| def to_h | ||
| super.compact | ||
|
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.
|
||
| end | ||
| end | ||
| end | ||
DagonWat marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # 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 | ||
| ) do | ||
| # @return [Hash] The Project attributes as a hash | ||
| def to_h | ||
| super.compact | ||
| end | ||
| end | ||
| 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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, let's find all delete methods in the lib directory
rg -n "def delete\(" lib/mailtrap --type rbRepository: mailtrap/mailtrap-ruby Length of output: 92 🏁 Script executed: #!/bin/bash
# Check the spec file to verify delete expectations
find . -name "*projects_api*spec*" -type fRepository: mailtrap/mailtrap-ruby Length of output: 102 🏁 Script executed: #!/bin/bash
# Look at the BaseAPI to understand base_delete behavior
find . -name "*base*api*" -type f | grep -E "\.(rb|py)$"Repository: mailtrap/mailtrap-ruby Length of output: 92 🏁 Script executed: #!/bin/bash
# Search for delete methods without type flag
rg -n "def delete\(" lib/mailtrap/Repository: mailtrap/mailtrap-ruby Length of output: 489 🏁 Script executed: #!/bin/bash
# Read the projects_api_spec.rb to verify delete expectations
cat ./spec/mailtrap/projects_api_spec.rbRepository: mailtrap/mailtrap-ruby Length of output: 5345 🏁 Script executed: #!/bin/bash
# Read the base_api.rb to understand base_delete
cat ./lib/mailtrap/base_api.rbRepository: mailtrap/mailtrap-ruby Length of output: 2361 🏁 Script executed: #!/bin/bash
# Read the Client class to see what delete returns
cat ./lib/mailtrap/client.rb | head -250Repository: mailtrap/mailtrap-ruby Length of output: 7799 🏁 Script executed: #!/bin/bash
# Also check projects_api.rb to see the full context
cat ./lib/mailtrap/projects_api.rbRepository: mailtrap/mailtrap-ruby Length of output: 1692 🏁 Script executed: #!/bin/bash
# Check other delete method YARD docs for consistency
grep -A 3 "def delete(" lib/mailtrap/*.rb | grep -E "(def delete|@return)"Repository: mailtrap/mailtrap-ruby Length of output: 467 🏁 Script executed: #!/bin/bash
# Check a couple of other spec files to see if they also expect hash return
grep -A 2 "it 'returns" spec/mailtrap/*_spec.rb | grep -E "(it 'returns|expect.*delete)"Repository: mailtrap/mailtrap-ruby Length of output: 1662 Update The YARD comment for Update the documentation to match the actual behavior: - # @return nil
+ # @return [Hash] Deleted project identifier, e.g. { id: project_id }🤖 Prompt for AI Agents |
||
|
|
||
| def build_entity(options, response_class) | ||
| response_class.new( | ||
| **options.slice(*(response_class.members - [:inboxes])), | ||
| inboxes: options[:inboxes]&.map do |inbox| | ||
| inbox.is_a?(Mailtrap::Inbox) ? inbox : Mailtrap::Inbox.new(**inbox) | ||
| end | ||
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| 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.