Class: Mailtrap::InboundMessagesAPI
- Inherits:
-
Object
- Object
- Mailtrap::InboundMessagesAPI
- Includes:
- BaseAPI
- Defined in:
- lib/mailtrap/inbound_messages_api.rb
Constant Summary collapse
- SEND_OPTIONS =
%i[from to cc bcc reply_to text html category attachments headers custom_variables].freeze
Instance Attribute Summary
Attributes included from BaseAPI
Instance Method Summary collapse
-
#delete(inbox_id, message_id) ⇒ Object
Deletes a message.
-
#forward(inbox_id, message_id, options) ⇒ InboundSendResult
Forwards a message to new recipients.
-
#get(inbox_id, message_id) ⇒ InboundMessage
Fetches a single message with its full body and attachment download URLs.
-
#initialize(client = Mailtrap::Client.new) ⇒ InboundMessagesAPI
constructor
A new instance of InboundMessagesAPI.
-
#list(inbox_id, last_id: nil) ⇒ InboundMessagesListResponse
Lists messages in an inbox (cursor-paginated).
-
#reply(inbox_id, message_id, options) ⇒ InboundSendResult
Replies to a message (sends to the original sender).
-
#reply_all(inbox_id, message_id, options) ⇒ InboundSendResult
Replies to a message and copies the original's other recipients.
Methods included from BaseAPI
Constructor Details
#initialize(client = Mailtrap::Client.new) ⇒ InboundMessagesAPI
Returns a new instance of InboundMessagesAPI.
18 19 20 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 18 def initialize(client = Mailtrap::Client.new) @client = client end |
Instance Method Details
#delete(inbox_id, message_id) ⇒ Object
Deletes a message
52 53 54 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 52 def delete(inbox_id, ) client.delete("#{(inbox_id)}/#{}") end |
#forward(inbox_id, message_id, options) ⇒ InboundSendResult
Forwards a message to new recipients
81 82 83 84 85 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 81 def forward(inbox_id, , ) raise ArgumentError, 'to is required for forward' if Array([:to]).empty? send_action(inbox_id, , 'forward', ) end |
#get(inbox_id, message_id) ⇒ InboundMessage
Fetches a single message with its full body and attachment download URLs
43 44 45 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 43 def get(inbox_id, ) (client.get("#{(inbox_id)}/#{}")) end |
#list(inbox_id, last_id: nil) ⇒ InboundMessagesListResponse
Lists messages in an inbox (cursor-paginated)
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 27 def list(inbox_id, last_id: nil) query_params = last_id ? { last_id: } : {} response = client.get((inbox_id), query_params) InboundMessagesListResponse.new( data: Array(response[:data]).map { |item| (item) }, total_count: response[:total_count], last_id: response[:last_id] ) end |
#reply(inbox_id, message_id, options) ⇒ InboundSendResult
Replies to a message (sends to the original sender)
63 64 65 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 63 def reply(inbox_id, , ) send_action(inbox_id, , 'reply', ) end |
#reply_all(inbox_id, message_id, options) ⇒ InboundSendResult
Replies to a message and copies the original's other recipients
72 73 74 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 72 def reply_all(inbox_id, , ) send_action(inbox_id, , 'reply_all', ) end |