Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
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 @@ -8,6 +8,7 @@
require_relative 'mailtrap/contacts_api'
require_relative 'mailtrap/contact_lists_api'
require_relative 'mailtrap/contact_fields_api'
require_relative 'mailtrap/projects_api'

module Mailtrap
# @!macro api_errors
Expand Down
28 changes: 28 additions & 0 deletions lib/mailtrap/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 [String] The project ID
# @attr_reader name [String] The project name
# @attr_reader share_links [Array] Array of links
# @attr_reader inboxes [Array] Array of inboxes
# @attr_reader permissions [Hash] List of permissions
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix YARD types and accessor annotations (docs are incorrect).

  • id is returned as an Integer by the API, not String.
  • share_links is a Hash (with admin/viewer), not an Array.
  • Struct defines writer methods too; documenting these as reader-only is misleading.

Apply this doc fix:

-  # @attr_reader id [String] The project ID
-  # @attr_reader name [String] The project name
-  # @attr_reader share_links [Array] Array of links
-  # @attr_reader inboxes [Array] Array of inboxes
-  # @attr_reader permissions [Hash] List of permissions
+  # @!attribute [rw] id
+  #   @return [Integer] The project ID
+  # @!attribute [rw] name
+  #   @return [String] The project name
+  # @!attribute [rw] share_links
+  #   @return [Hash] Admin and viewer share links
+  # @!attribute [rw] inboxes
+  #   @return [Array] Array of inboxes
+  # @!attribute [rw] permissions
+  #   @return [Hash] List of permissions
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# @attr_reader id [String] The project ID
# @attr_reader name [String] The project name
# @attr_reader share_links [Array] Array of links
# @attr_reader inboxes [Array] Array of inboxes
# @attr_reader permissions [Hash] List of permissions
# @!attribute [rw] id
# @return [Integer] The project ID
# @!attribute [rw] name
# @return [String] The project name
# @!attribute [rw] share_links
# @return [Hash] Admin and viewer share links
# @!attribute [rw] inboxes
# @return [Array] Array of inboxes
# @!attribute [rw] permissions
# @return [Hash] List of permissions
🤖 Prompt for AI Agents
In lib/mailtrap/project.rb around lines 6 to 10, the YARD annotations are
incorrect: change the id type to Integer instead of String, change share_links
to a Hash (e.g. Hash with admin/viewer keys) instead of Array, keep inboxes as
an Array and permissions as a Hash, and mark the attributes as read-write (the
Struct defines writers) rather than reader-only; update the @attr_* tags or
replace them with @!attribute [rw] annotations to reflect the correct types and
that getters and setters exist.

Project = Struct.new(
:id,
:name,
:share_links,
:inboxes,
:permissions,
keyword_init: true
) do
def initialize(options)
super
end

# @return [Hash] The project attributes as a hash
def to_h
super.compact
end
end
end
67 changes: 67 additions & 0 deletions lib/mailtrap/projects_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

require_relative 'base_api'
require_relative 'project'

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

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