Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/mailtrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative 'mailtrap/contact_fields_api'
require_relative 'mailtrap/contact_imports_api'
require_relative 'mailtrap/suppressions_api'
require_relative 'mailtrap/projects_api'

module Mailtrap
# @!macro api_errors
Expand Down
62 changes: 62 additions & 0 deletions lib/mailtrap/inbox.rb
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 project ID
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
# @attr_reader name [String] The project name
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
# @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 [Boolean] The used inbox size in MB
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
# @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 project attributes as a hash
def to_h
super.compact

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last_message_sent_at can be nil. Compacting will remove it. Is it necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's nil and you call inbox.to_h[:last_message_sent_at] it will return nil, the only difference is that when you visually go through the fields in console output - its not seen.

If we do it in all other Struct's I think we should either live with it or create a task for future to remove compact everywhere.

end
end
end
45 changes: 45 additions & 0 deletions lib/mailtrap/project.rb
Comment thread
DagonWat marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module Mailtrap
class Project
# 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
attr_reader :id, :name, :share_links, :inboxes, :permissions

def self.members
[:id, :name, :share_links, :inboxes, :permissions]
end
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

# @param args [Hash] The project attributes
def initialize(args = {})
@id = args[:id]
@name = args[:name]
@share_links = args[:share_links]
@permissions = args[:permissions]

raw_inboxes = args[:inboxes]
@inboxes =
if raw_inboxes
raw_inboxes.map do |inbox|
inbox.is_a?(Mailtrap::Inbox) ? inbox : Mailtrap::Inbox.new(**inbox)
end
end
end

# @return [Hash] The project attributes as a hash
def to_h
{
id: id,
name: name,
share_links: share_links,
inboxes: inboxes&.map(&:to_h),
permissions: permissions
}.compact
end
end
end
68 changes: 68 additions & 0 deletions lib/mailtrap/projects_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Update the return value documentation.

The YARD comment states @return nil, but base_delete returns the response from client.delete, which the specs expect to be a hash like { id: project_id }.

📝 Suggested fix
-    # @return nil
+    # @return [Hash] The deleted project response, e.g., { id: project_id }
🤖 Prompt for AI Agents
In @lib/mailtrap/projects_api.rb around lines 50 - 56, The YARD @return is
incorrect: the delete(project_id) method calls base_delete(project_id) which
returns the client response (e.g., a Hash like { id: project_id }), not nil;
update the comment for delete to reflect the actual return type and shape (for
example "@return [Hash] response hash containing the deleted project id" or
similar) and ensure any related docs/macro references match the new return
description; keep the method body unchanged (it should still call
base_delete(project_id)).


private

def base_path
"/api/accounts/#{account_id}/projects"
end

def wrap_request(options)
{ project: options }
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading