diff --git a/README.md b/README.md index a4ec7b8..7b4c7fe 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ Email API: Email Sandbox (Testing): - Project management CRUD – [`projects_api.rb`](examples/projects_api.rb) +- Inboxes CRUD - [`inboxes_api.rb`](examples/inboxes_api.rb) Contact management: diff --git a/examples/inboxes_api.rb b/examples/inboxes_api.rb new file mode 100644 index 0000000..4778469 --- /dev/null +++ b/examples/inboxes_api.rb @@ -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) +# => # + +# Get all Inboxes +inboxes.list +# => [#] + +# Update inbox +inboxes.update(inbox.id, name: 'Test List Updated') +# => # + +# Get contact list +inbox = inboxes.get(inbox.id) +# => # + +# 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) diff --git a/lib/mailtrap.rb b/lib/mailtrap.rb index 3b6af23..37f1cdd 100644 --- a/lib/mailtrap.rb +++ b/lib/mailtrap.rb @@ -11,6 +11,7 @@ require_relative 'mailtrap/contact_imports_api' require_relative 'mailtrap/suppressions_api' require_relative 'mailtrap/projects_api' +require_relative 'mailtrap/inboxes_api' module Mailtrap # @!macro api_errors diff --git a/lib/mailtrap/inboxes_api.rb b/lib/mailtrap/inboxes_api.rb new file mode 100644 index 0000000..e9e474b --- /dev/null +++ b/lib/mailtrap/inboxes_api.rb @@ -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] + self.response_class = Inbox + + # Lists all Inboxes for the account + # @return [Array] 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 + + # 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 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_clean/cleans_Inbox_and_returns_Inbox_object.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_clean/cleans_Inbox_and_returns_Inbox_object.yml new file mode 100644 index 0000000..c090fa3 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_clean/cleans_Inbox_and_returns_Inbox_object.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/4278175/clean + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 17:10:08 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"b806febaa0d1508c418fc9aa248e543f" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - b6b01df6-5a6a-4061-9d43-b8b58cd87493 + X-Runtime: + - '0.039374' + X-Cloud-Trace-Context: + - 4d4fb37492584991cfebb9a1b29d099f;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b42309cabe8bd24-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Updated Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"b5bf6ce98dcfd9","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 17:10:08 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_clean/when_inbox_does_not_exist/raises_not_found_error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_clean/when_inbox_does_not_exist/raises_not_found_error.yml new file mode 100644 index 0000000..f19bc7e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_clean/when_inbox_does_not_exist/raises_not_found_error.yml @@ -0,0 +1,77 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/-1/clean + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 26 Dec 2025 17:10:08 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '148' + Cache-Control: + - no-cache + X-Request-Id: + - 233205dc-d166-4b73-9f17-ffe10d7922f4 + X-Runtime: + - '0.012632' + X-Cloud-Trace-Context: + - '09dd3a8e86a84af682242d833e0ad386;o=0' + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b42309e2d5fd8d6-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"error":"Not Found"}' + recorded_at: Fri, 26 Dec 2025 17:10:08 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_create/maps_response_data_to_Inbox_object.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_create/maps_response_data_to_Inbox_object.yml new file mode 100644 index 0000000..ee8393e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_create/maps_response_data_to_Inbox_object.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: post + uri: https://mailtrap.io/api/accounts/1111111/projects/2379735/inboxes + body: + encoding: UTF-8 + string: '{"inbox":{"name":"Test Inbox","project_id":2379735}}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 16:53:29 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"2cf81c032e6e106bcc15ae0e7813c6b3" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 44c45745-5902-4b9f-b9a6-7fdecb919dfe + X-Runtime: + - '0.061158' + X-Cloud-Trace-Context: + - e8ecc98dd6204248ceed8bfb0da9b7a3;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b421838da20b32c-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Test Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"b5bf6ce98dcfd9","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 16:53:29 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_create/when_API_returns_an_error/raises_a_Mailtrap_Error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_create/when_API_returns_an_error/raises_a_Mailtrap_Error.yml new file mode 100644 index 0000000..fa4ea13 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_create/when_API_returns_an_error/raises_a_Mailtrap_Error.yml @@ -0,0 +1,78 @@ +--- +http_interactions: +- request: + method: post + uri: https://mailtrap.io/api/accounts/1111111/projects/2379735/inboxes + body: + encoding: UTF-8 + string: '{"inbox":{"name":"","project_id":2379735}}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 422 + message: Unprocessable Entity + headers: + Date: + - Fri, 26 Dec 2025 16:53:29 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '110' + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '148' + Cache-Control: + - no-cache + X-Request-Id: + - dfdec05f-27fc-4087-8919-17d86f5f792e + X-Runtime: + - '0.038009' + X-Cloud-Trace-Context: + - 8d0bb8b5197d49bb878f253bef608125;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b42183a5f0890e7-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: UTF-8 + string: '{"errors":{"name":["You''ve reached the sandboxes limit. Please upgrade + your plan to create the new sandbox"]}}' + recorded_at: Fri, 26 Dec 2025 16:53:29 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_delete/returns_deleted_inbox_data.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_delete/returns_deleted_inbox_data.yml new file mode 100644 index 0000000..bc1ca3a --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_delete/returns_deleted_inbox_data.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: delete + uri: https://mailtrap.io/api/accounts/1111111/inboxes/4278175 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 17:15:15 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"338b9c6a630814e8bec88c155c2114d7" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 4600b7d4-422c-4f7a-ae3e-58597f611ac3 + X-Runtime: + - '0.050752' + X-Cloud-Trace-Context: + - 725615cd55814b88ce1b48086fa6d471;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b42381f599a3554-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Updated Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"66ae8915674837","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 17:15:15 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_delete/when_inbox_does_not_exist/raises_not_found_error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_delete/when_inbox_does_not_exist/raises_not_found_error.yml new file mode 100644 index 0000000..78ceb40 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_delete/when_inbox_does_not_exist/raises_not_found_error.yml @@ -0,0 +1,77 @@ +--- +http_interactions: +- request: + method: delete + uri: https://mailtrap.io/api/accounts/1111111/inboxes/-1 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 26 Dec 2025 17:15:16 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '148' + Cache-Control: + - no-cache + X-Request-Id: + - 733c4b03-9afa-442c-b5b5-ed3e8814503f + X-Runtime: + - '0.013713' + X-Cloud-Trace-Context: + - 3868b3d5945d4843c4c12cecf70971de;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b4238218f80d285-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"error":"Not Found"}' + recorded_at: Fri, 26 Dec 2025 17:15:16 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_get/maps_response_data_to_Inbox_object.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_get/maps_response_data_to_Inbox_object.yml new file mode 100644 index 0000000..61377f9 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_get/maps_response_data_to_Inbox_object.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: get + uri: https://mailtrap.io/api/accounts/1111111/inboxes/4278175 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 16:59:23 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"2cf81c032e6e106bcc15ae0e7813c6b3" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 6aa68831-a4f5-4206-b50e-ebdb0fe9276b + X-Runtime: + - '0.024725' + X-Cloud-Trace-Context: + - a512c905911549d588dd11499058d3ca;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b4220e01ac7903c-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Test Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"b5bf6ce98dcfd9","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 16:59:23 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_get/when_inbox_does_not_exist/raises_not_found_error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_get/when_inbox_does_not_exist/raises_not_found_error.yml new file mode 100644 index 0000000..9eb0de4 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_get/when_inbox_does_not_exist/raises_not_found_error.yml @@ -0,0 +1,77 @@ +--- +http_interactions: +- request: + method: get + uri: https://mailtrap.io/api/accounts/1111111/inboxes/-1 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 26 Dec 2025 16:59:24 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '148' + Cache-Control: + - no-cache + X-Request-Id: + - 818763f7-e89b-41b2-8529-7b5a873d4728 + X-Runtime: + - '0.015297' + X-Cloud-Trace-Context: + - 474ae8a57f8f4fa2cf5eb599cfe0cd05;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b4220e30f719f33-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"error":"Not Found"}' + recorded_at: Fri, 26 Dec 2025 16:59:24 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_list/maps_response_data_to_Inboxes_objects.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_list/maps_response_data_to_Inboxes_objects.yml new file mode 100644 index 0000000..4e603a8 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_list/maps_response_data_to_Inboxes_objects.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: get + uri: https://mailtrap.io/api/accounts/1111111/inboxes + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 14:29:55 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"aec9a1faefaa0af164f39ffc5e443a25" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 9eed8d32-2e75-4143-9414-00a73c342e32 + X-Runtime: + - '0.041466' + X-Cloud-Trace-Context: + - aa52c3d676f74001807ae3b136dcb7a5;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b4145ece982dca0-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '[{"id":3715083,"name":"My Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i3715083@forward.mailtrap.info","project_id":2379735,"password":"d0a5272456b7fb","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}]' + recorded_at: Fri, 26 Dec 2025 14:29:55 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_list/when_api_key_is_incorrect/raises_authorization_error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_list/when_api_key_is_incorrect/raises_authorization_error.yml new file mode 100644 index 0000000..f026826 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_list/when_api_key_is_incorrect/raises_authorization_error.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: get + uri: https://mailtrap.io/api/accounts/1111111/inboxes + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 401 + message: Unauthorized + headers: + Date: + - Fri, 26 Dec 2025 14:29:55 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '31' + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Www-Authenticate: + - Token realm="Application" + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Cache-Control: + - no-cache + X-Request-Id: + - 678578c6-68ad-487d-bab2-bd1f9615c358 + X-Runtime: + - '0.012461' + X-Cloud-Trace-Context: + - e69f0ee106f3401c8371ae5f11d21d6f;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b4145ee4ef86c21-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: UTF-8 + string: '{"error":"Incorrect API token"}' + recorded_at: Fri, 26 Dec 2025 14:29:55 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_mark_as_read/returns_nil.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_mark_as_read/returns_nil.yml new file mode 100644 index 0000000..7b9cf21 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_mark_as_read/returns_nil.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/4278175/all_read + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 17:14:42 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"b806febaa0d1508c418fc9aa248e543f" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - c14353b3-63e5-4c5c-b3a2-db52da5ebcb8 + X-Runtime: + - '0.024366' + X-Cloud-Trace-Context: + - a234c5211e674b878ed1005d6ee1a28b;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b42374a2eef3554-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Updated Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"b5bf6ce98dcfd9","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 17:14:42 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_mark_as_read/when_inbox_does_not_exist/raises_not_found_error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_mark_as_read/when_inbox_does_not_exist/raises_not_found_error.yml new file mode 100644 index 0000000..e49e634 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_mark_as_read/when_inbox_does_not_exist/raises_not_found_error.yml @@ -0,0 +1,77 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/-1/all_read + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 26 Dec 2025 17:14:42 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '148' + Cache-Control: + - no-cache + X-Request-Id: + - 42765c00-3c41-4ce2-a856-a0ffc6e40333 + X-Runtime: + - '0.010824' + X-Cloud-Trace-Context: + - 82b5db722efe4614c9cb52feb3ac2afa;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b42374dbc73d372-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"error":"Not Found"}' + recorded_at: Fri, 26 Dec 2025 17:14:42 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_reset_credentials/returns_nil.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_reset_credentials/returns_nil.yml new file mode 100644 index 0000000..b9af55b --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_reset_credentials/returns_nil.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/4278175/reset_credentials + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 17:15:07 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"338b9c6a630814e8bec88c155c2114d7" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - f1bd1cb5-9c00-4c6d-a8c4-5248b61e78bc + X-Runtime: + - '0.033364' + X-Cloud-Trace-Context: + - 0da52de942cb45eac6d944100fe554fb;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b4237e81af52bb5-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Updated Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"66ae8915674837","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 17:15:07 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_reset_credentials/when_inbox_does_not_exist/raises_not_found_error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_reset_credentials/when_inbox_does_not_exist/raises_not_found_error.yml new file mode 100644 index 0000000..90fc5f2 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_reset_credentials/when_inbox_does_not_exist/raises_not_found_error.yml @@ -0,0 +1,77 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/-1/reset_credentials + body: + encoding: UTF-8 + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 26 Dec 2025 17:15:07 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '148' + Cache-Control: + - no-cache + X-Request-Id: + - afe67dfd-7a23-4722-8ddc-3f0dce166ea8 + X-Runtime: + - '0.008827' + X-Cloud-Trace-Context: + - ea6626e21aac4956cf48adbc2bc95d6d;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b4237ec0ef99b2b-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"error":"Not Found"}' + recorded_at: Fri, 26 Dec 2025 17:15:07 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/maps_response_data_to_Inbox_object.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/maps_response_data_to_Inbox_object.yml new file mode 100644 index 0000000..4d604c8 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/maps_response_data_to_Inbox_object.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/4278175 + body: + encoding: UTF-8 + string: '{"inbox":{"name":"Updated Inbox","email_username":"updated_username"}}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 17:06:55 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '149' + Etag: + - W/"b806febaa0d1508c418fc9aa248e543f" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - a852bfd0-43dc-4183-9aa7-1cf5ca30367c + X-Runtime: + - '0.028523' + X-Cloud-Trace-Context: + - c25b5a209b5f4257c7d1b1eb50f4e6d5;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b422be5adced359-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Updated Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"b5bf6ce98dcfd9","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 17:06:55 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/when_inbox_does_not_exist/raises_not_found_error.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/when_inbox_does_not_exist/raises_not_found_error.yml new file mode 100644 index 0000000..f85c400 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/when_inbox_does_not_exist/raises_not_found_error.yml @@ -0,0 +1,77 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/-1 + body: + encoding: UTF-8 + string: '{"inbox":{"name":"Updated Inbox","email_username":"updated_username"}}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 26 Dec 2025 17:06:55 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '147' + Cache-Control: + - no-cache + X-Request-Id: + - ce0d14b7-59d3-4f9c-9b7d-78929a424c7f + X-Runtime: + - '0.009525' + X-Cloud-Trace-Context: + - abec98fdb6ef4e5285b4b3d107c90003;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b422bea9bfadcc2-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"error":"Not Found"}' + recorded_at: Fri, 26 Dec 2025 17:06:55 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/with_hash_request/maps_response_data_to_Inbox_object.yml b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/with_hash_request/maps_response_data_to_Inbox_object.yml new file mode 100644 index 0000000..8c16920 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailtrap_InboxesAPI/_update/with_hash_request/maps_response_data_to_Inbox_object.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: patch + uri: https://mailtrap.io/api/accounts/1111111/inboxes/4278175 + body: + encoding: UTF-8 + string: '{"inbox":{"name":"Updated Inbox"}}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby) + Host: + - mailtrap.io + Authorization: + - Bearer + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Dec 2025 17:06:55 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Server: + - cloudflare + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Accept + X-Mailtrap-Version: + - v2 + X-Ratelimit-Limit: + - '150' + X-Ratelimit-Remaining: + - '148' + Etag: + - W/"b806febaa0d1508c418fc9aa248e543f" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 7468d5ca-c753-4a3f-8940-0a44990b8518 + X-Runtime: + - '0.032751' + X-Cloud-Trace-Context: + - 14fb309a195c4fff8b2200d270f3f8c0;o=0 + Strict-Transport-Security: + - max-age=0 + Cf-Cache-Status: + - DYNAMIC + Cf-Ray: + - 9b422be70c87578b-FRA + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: '{"id":4278175,"name":"Updated Inbox","username":"xxxxxx","status":"active","email_username":"xxxxxx","email_username_enabled":false,"used":false,"forward_from_email_address":"xyzxyz-i4278175@forward.mailtrap.info","project_id":2379735,"password":"b5bf6ce98dcfd9","domain":"sandbox.smtp.mailtrap.io","pop3_domain":"pop3.mailtrap.io","email_domain":"inbox.mailtrap.io","smtp_ports":[25,465,587,2525],"pop3_ports":[1100,9950],"api_domain":"sandbox.api.mailtrap.io","sent_messages_count":0,"forwarded_messages_count":0,"emails_count":0,"emails_unread_count":0,"last_message_sent_at":null,"max_size":10,"max_message_size":5242880,"permissions":{"can_read":true,"can_update":true,"can_destroy":true,"can_leave":false}}' + recorded_at: Fri, 26 Dec 2025 17:06:55 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/mailtrap/inbox_spec.rb b/spec/mailtrap/inbox_spec.rb new file mode 100644 index 0000000..4e4ca00 --- /dev/null +++ b/spec/mailtrap/inbox_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +RSpec.describe Mailtrap::Inbox do + let(:attributes) do + { + id: 123, + name: 'Example Inbox', + username: 'example-username', + password: 'example-password', + max_size: 123, + status: 'active', + email_username: 'example-email-username', + email_username_enabled: true, + sent_messages_count: 123, + forwarded_messages_count: 123, + used: 123, + forward_from_email_address: 'asd@mail.com', + project_id: 123, + domain: 'example.com', + pop3_domain: 'example.com', + email_domain: 'example.com', + api_domain: 'example.com', + emails_count: 123, + emails_unread_count: 123, + last_message_sent_at: Date.today, + smtp_ports: 123, + pop3_ports: 123, + max_message_size: 123, + permissions: { + can_read: true, + can_update: true, + can_destroy: false, + can_leave: true + } + } + end + + describe '#initialize' do + subject(:inbox) { described_class.new(attributes) } + + it 'creates an Inbox with all attributes' do + expect(inbox).to have_attributes( + id: 123, + name: 'Example Inbox', + username: 'example-username', + password: 'example-password', + max_size: 123, + status: 'active', + email_username: 'example-email-username', + email_username_enabled: true, + sent_messages_count: 123, + forwarded_messages_count: 123, + used: 123, + forward_from_email_address: 'asd@mail.com', + project_id: 123, + domain: 'example.com', + pop3_domain: 'example.com', + email_domain: 'example.com', + api_domain: 'example.com', + emails_count: 123, + emails_unread_count: 123, + last_message_sent_at: Date.today, + smtp_ports: 123, + pop3_ports: 123, + max_message_size: 123, + permissions: { + can_read: true, + can_update: true, + can_destroy: false, + can_leave: true + } + ) + end + end +end diff --git a/spec/mailtrap/inboxes_api_spec.rb b/spec/mailtrap/inboxes_api_spec.rb new file mode 100644 index 0000000..8daa9e6 --- /dev/null +++ b/spec/mailtrap/inboxes_api_spec.rb @@ -0,0 +1,236 @@ +# frozen_string_literal: true + +RSpec.describe Mailtrap::InboxesAPI, :vcr do + subject(:inboxes_api) { described_class.new(account_id, client) } + + let(:account_id) { ENV.fetch('MAILTRAP_ACCOUNT_ID', 1_111_111) } + let(:client) { Mailtrap::Client.new(api_key: ENV.fetch('MAILTRAP_API_KEY', 'local-api-key')) } + + describe '#list' do + subject(:list) { inboxes_api.list } + + it 'maps response data to Inboxes objects' do + expect(list).to all(be_a(Mailtrap::Inbox)) + end + + context 'when api key is incorrect' do + let(:client) { Mailtrap::Client.new(api_key: 'incorrect-api-key') } + + it 'raises authorization error' do + expect { list }.to raise_error do |error| + expect(error).to be_a(Mailtrap::AuthorizationError) + expect(error.message).to include('Incorrect API token') + expect(error.messages.any? { |msg| msg.include?('Incorrect API token') }).to be true + end + end + end + end + + describe '#get' do + subject(:get) { inboxes_api.get(inbox_id) } + + let(:inbox_id) { 4_278_175 } + + it 'maps response data to Inbox object' do + expect(get).to be_a(Mailtrap::Inbox) + expect(get).to have_attributes( + id: inbox_id, + name: 'Test Inbox' + ) + end + + context 'when inbox does not exist' do + let(:inbox_id) { -1 } + + it 'raises not found error' do + expect { get }.to raise_error do |error| + expect(error).to be_a(Mailtrap::Error) + expect(error.message).to include('Not Found') + expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true + end + end + end + end + + describe '#create' do + subject(:create) { inboxes_api.create(**request) } + + let(:request) do + { + name: 'Test Inbox', + project_id: 2_379_735 + } + end + + it 'maps response data to Inbox object' do + expect(create).to be_a(Mailtrap::Inbox) + expect(create).to have_attributes( + name: 'Test Inbox' + ) + end + + context 'when API returns an error' do + let(:request) do + { + name: '', # Invalid value, but present + project_id: 2_379_735 + } + end + + it 'raises a Mailtrap::Error' do + expect { create }.to raise_error do |error| + expect(error).to be_a(Mailtrap::Error) + expect(error.message).to include('client error') + end + end + end + end + + describe '#update' do + subject(:update) { inboxes_api.update(inbox_id, **request) } + + let(:inbox_id) { 4_278_175 } + + let(:request) do + { + name: 'Updated Inbox', + email_username: 'updated_username' + } + end + + it 'maps response data to Inbox object' do + expect(update).to be_a(Mailtrap::Inbox) + expect(update).to have_attributes( + name: 'Updated Inbox', + email_username: '1234abcd' + ) + end + + context 'with hash request' do + let(:request) do + { + name: 'Updated Inbox' + } + end + + it 'maps response data to Inbox object' do + expect(update).to be_a(Mailtrap::Inbox) + expect(update).to have_attributes( + name: 'Updated Inbox' + ) + end + end + + context 'when inbox does not exist' do + let(:inbox_id) { -1 } + + it 'raises not found error' do + expect { update }.to raise_error do |error| + expect(error).to be_a(Mailtrap::Error) + expect(error.message).to include('Not Found') + expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true + end + end + end + end + + describe '#clean' do + subject(:clean) { inboxes_api.clean(inbox_id) } + + let(:inbox_id) { 4_278_175 } + + it 'cleans Inbox and returns Inbox object' do + expect(clean).to have_attributes( + id: inbox_id, + name: 'Updated Inbox' + ) + end + + context 'when inbox does not exist' do + let(:inbox_id) { -1 } + + it 'raises not found error' do + expect { clean }.to raise_error do |error| + expect(error).to be_a(Mailtrap::Error) + expect(error.message).to include('Not Found') + expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true + end + end + end + end + + describe '#mark_as_read' do + subject(:mark_as_read) { inboxes_api.mark_as_read(inbox_id) } + + let(:inbox_id) { 4_278_175 } + + it 'returns nil' do + expect(mark_as_read).to have_attributes( + id: inbox_id, + name: 'Updated Inbox' + ) + end + + context 'when inbox does not exist' do + let(:inbox_id) { -1 } + + it 'raises not found error' do + expect { mark_as_read }.to raise_error do |error| + expect(error).to be_a(Mailtrap::Error) + expect(error.message).to include('Not Found') + expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true + end + end + end + end + + describe '#reset_credentials' do + subject(:reset_credentials) { inboxes_api.reset_credentials(inbox_id) } + + let(:inbox_id) { 4_278_175 } + + it 'returns nil' do + expect(reset_credentials).to have_attributes( + id: inbox_id, + name: 'Updated Inbox' + ) + end + + context 'when inbox does not exist' do + let(:inbox_id) { -1 } + + it 'raises not found error' do + expect { reset_credentials }.to raise_error do |error| + expect(error).to be_a(Mailtrap::Error) + expect(error.message).to include('Not Found') + expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true + end + end + end + end + + describe '#delete' do + subject(:delete) { inboxes_api.delete(inbox_id) } + + let(:inbox_id) { 4_278_175 } + + it 'returns deleted inbox data' do + expect(delete).to include( + id: inbox_id, + name: 'Updated Inbox' + ) + end + + context 'when inbox does not exist' do + let(:inbox_id) { -1 } + + it 'raises not found error' do + expect { delete }.to raise_error do |error| + expect(error).to be_a(Mailtrap::Error) + expect(error.message).to include('Not Found') + expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true + end + end + end + end +end