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
Inbound is scoped to the token's account, so no account_id is required.
-
#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
Inbound is scoped to the token's account, so no account_id is required.
19 20 21 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 19 def initialize(client = Mailtrap::Client.new) @client = client end |
Instance Method Details
#delete(inbox_id, message_id) ⇒ Object
Deletes a message
53 54 55 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 53 def delete(inbox_id, ) client.delete("#{(inbox_id)}/#{}") end |
#forward(inbox_id, message_id, options) ⇒ InboundSendResult
Forwards a message to new recipients
82 83 84 85 86 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 82 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
44 45 46 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 44 def get(inbox_id, ) (client.get("#{(inbox_id)}/#{}")) end |
#list(inbox_id, last_id: nil) ⇒ InboundMessagesListResponse
Lists messages in an inbox (cursor-paginated)
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 28 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)
64 65 66 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 64 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
73 74 75 |
# File 'lib/mailtrap/inbound_messages_api.rb', line 73 def reply_all(inbox_id, , ) send_action(inbox_id, , 'reply_all', ) end |