-
Notifications
You must be signed in to change notification settings - Fork 7
Add Inboxes API #80
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?
Add Inboxes API #80
Changes from all commits
f7c0d9e
5a561c0
a59d544
336efa7
0a54666
1207818
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,33 @@ | ||
| require 'mailtrap' | ||
|
|
||
| account_id = 3229 | ||
| client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
| inboxes = Mailtrap::InboxesAPI.new(account_id, client) | ||
|
|
||
| # Create new Inbox | ||
| inbox = inboxes.create(name: 'Test Inbox', project_id: 123_456) | ||
| # => #<struct Mailtrap::Inbox id=1, name="Test Inbox"> | ||
|
|
||
| # Get all Inboxes | ||
| inboxes.list | ||
| # => [#<struct Mailtrap::Inbox id=1, name="Test Inbox">] | ||
|
|
||
| # Update inbox | ||
| inboxes.update(inbox.id, name: 'Test List Updated') | ||
|
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. "Test Inbox Updated" |
||
| # => #<struct Mailtrap::Inbox id=1, name="Test Inbox Updated"> | ||
|
|
||
| # Get contact list | ||
| inbox = inboxes.get(inbox.id) | ||
| # => #<struct Mailtrap::Inbox id=1, name="Test Inbox Updated"> | ||
|
|
||
| # Delete all messages (emails) from Inbox | ||
| inboxes.clean(inbox.id) | ||
|
|
||
| # Mark all messages in the inbox as read | ||
| inboxes.mark_as_read(inbox.id) | ||
|
|
||
| # Reset SMTP credentials of the inbox | ||
| inboxes.reset_credentials(inbox.id) | ||
|
|
||
| # Delete unbox list | ||
| inboxes.delete(inbox.id) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'base_api' | ||
| require_relative 'inbox' | ||
|
|
||
| module Mailtrap | ||
| class InboxesAPI | ||
| include BaseAPI | ||
|
|
||
| self.supported_options = %i[name email_username] | ||
|
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. you can't specify email_username on inbox creation |
||
| self.response_class = Inbox | ||
|
|
||
| # Lists all Inboxes for the account | ||
| # @return [Array<Inbox>] Array of Inboxes | ||
| # @!macro api_errors | ||
| def list | ||
| base_list | ||
| end | ||
|
|
||
| # Retrieves a specific inbox | ||
| # @param inbox_id [Integer] The inbox identifier | ||
| # @return [Inbox] Inbox object | ||
| # @!macro api_errors | ||
| def get(inbox_id) | ||
| base_get(inbox_id) | ||
| end | ||
|
|
||
| # Creates a new inbox | ||
| # @param [Hash] options The parameters to create | ||
| # @option options [String] :name The inbox name | ||
| # @return [Inbox] Created inbox object | ||
| # @!macro api_errors | ||
| # @raise [ArgumentError] If invalid options are provided | ||
| def create(options) | ||
| validate_options!(options, supported_options + [:project_id]) | ||
| response = client.post("/api/accounts/#{account_id}/projects/#{options[:project_id]}/inboxes", | ||
| wrap_request(options)) | ||
| handle_response(response) | ||
| end | ||
|
Comment on lines
+28
to
+39
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. Missing validation for required The Additionally, the Proposed fix # Creates a new inbox
# `@param` [Hash] options The parameters to create
# `@option` options [String] :name The inbox name
+ # `@option` options [Integer] :project_id The project identifier (required)
# `@return` [Inbox] Created inbox object
# @!macro api_errors
# `@raise` [ArgumentError] If invalid options are provided
def create(options)
validate_options!(options, supported_options + [:project_id])
+ raise ArgumentError, 'project_id is required' unless options[:project_id]
response = client.post("/api/accounts/#{account_id}/projects/#{options[:project_id]}/inboxes",
wrap_request(options))
handle_response(response)
end🧰 Tools🪛 ast-grep (0.40.5)[warning] 35-36: Found the use of an hardcoded passphrase for RSA. The passphrase can be easily discovered, and therefore should not be stored in source-code. It is recommended to remove the passphrase from source-code, and use system environment variables or a restricted configuration file. (hardcoded-secret-rsa-passphrase-ruby) 🤖 Prompt for AI Agents |
||
|
|
||
| # Deletes an inbox | ||
| # @param inbox_id [Integer] The Inbox identifier | ||
| # @return nil | ||
| # @!macro api_errors | ||
| def delete(inbox_id) | ||
| base_delete(inbox_id) | ||
| end | ||
|
|
||
| # Updates an existing Inbox | ||
| # @param inbox_id [Integer] The Inbox identifier | ||
| # @param [Hash] options The parameters to update | ||
| # @option options [String] :name The inbox name | ||
| # @option options [String] :email_username The inbox email username | ||
| # @return [Inbox] Updated Inbox object | ||
| # @!macro api_errors | ||
| # @raise [ArgumentError] If invalid options are provided | ||
| def update(inbox_id, options) | ||
| base_update(inbox_id, options) | ||
| end | ||
|
|
||
| # Delete all messages (emails) from Inbox | ||
| # @param inbox_id [Integer] The Inbox identifier | ||
| # @return [Inbox] Updated Inbox object | ||
| # @!macro api_errors | ||
| def clean(inbox_id) | ||
| response = client.patch("#{base_path}/#{inbox_id}/clean") | ||
| handle_response(response) | ||
| end | ||
|
|
||
| # Mark all messages in the inbox as read | ||
| # @param inbox_id [Integer] The Inbox identifier | ||
| # @return [Inbox] Updated Inbox object | ||
| # @!macro api_errors | ||
| def mark_as_read(inbox_id) | ||
| response = client.patch("#{base_path}/#{inbox_id}/all_read") | ||
| handle_response(response) | ||
| end | ||
|
|
||
| # Reset SMTP credentials of the inbox | ||
| # @param inbox_id [Integer] The Inbox identifier | ||
| # @return [Inbox] Updated Inbox object | ||
| # @!macro api_errors | ||
| def reset_credentials(inbox_id) | ||
| response = client.patch("#{base_path}/#{inbox_id}/reset_credentials") | ||
| handle_response(response) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def wrap_request(options) | ||
| { inbox: options } | ||
| end | ||
|
|
||
| def base_path | ||
| "/api/accounts/#{account_id}/inboxes" | ||
| end | ||
| end | ||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
minor. inconsistent with the previous line