Class: Mailtrap::SandboxMessagesAPI
- Inherits:
-
Object
- Object
- Mailtrap::SandboxMessagesAPI
- Includes:
- BaseAPI
- Defined in:
- lib/mailtrap/sandbox_messages_api.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#inbox_id ⇒ Object
readonly
Returns the value of attribute inbox_id.
Instance Method Summary collapse
-
#delete(message_id) ⇒ SandboxMessage
Deletes a sandbox message.
-
#eml_body(message_id) ⇒ String
Get message as EML.
-
#forward_message(message_id, email:) ⇒ String
Forward message to an email address.
-
#get(message_id) ⇒ SandboxMessage
Retrieves a specific sandbox message from inbox.
-
#html_analysis(message_id) ⇒ Hash
Get message HTML analysis.
-
#html_body(message_id) ⇒ String
Get formatted HTML email body.
-
#html_source(message_id) ⇒ String
Get message source.
-
#initialize(account_id, inbox_id, client = Mailtrap::Client.new) ⇒ SandboxMessagesAPI
constructor
A new instance of SandboxMessagesAPI.
-
#list(search: nil, last_id: nil, page: nil) ⇒ Array<SandboxMessage>
Lists all sandbox messages for the account, limited up to 30 at once Overrides page if both are given.
-
#mail_headers(message_id) ⇒ Hash
Get mail headers.
-
#mark_as_read(message_id, is_read: true) ⇒ SandboxMessage
Updates an existing sandbox message.
-
#raw_body(message_id) ⇒ String
Get raw message.
-
#spam_score(message_id) ⇒ Hash
Get message spam score.
-
#text_body(message_id) ⇒ String
Get text message.
Methods included from BaseAPI
Constructor Details
#initialize(account_id, inbox_id, client = Mailtrap::Client.new) ⇒ SandboxMessagesAPI
Returns a new instance of SandboxMessagesAPI.
21 22 23 24 25 26 27 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 21 def initialize(account_id, inbox_id, client = Mailtrap::Client.new) raise ArgumentError, 'inbox_id is required' if inbox_id.nil? @inbox_id = inbox_id super(account_id, client) end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
10 11 12 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 10 def account_id @account_id end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 10 def client @client end |
#inbox_id ⇒ Object (readonly)
Returns the value of attribute inbox_id.
10 11 12 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 10 def inbox_id @inbox_id end |
Instance Method Details
#delete(message_id) ⇒ SandboxMessage
Deletes a sandbox message
41 42 43 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 41 def delete() base_delete() end |
#eml_body(message_id) ⇒ String
Get message as EML
133 134 135 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 133 def eml_body() client.get("#{base_path}/#{message_id}/body.eml") end |
#forward_message(message_id, email:) ⇒ String
Forward message to an email address.
77 78 79 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 77 def (, email:) client.post("#{base_path}/#{message_id}/forward", { email: email }) end |
#get(message_id) ⇒ SandboxMessage
Retrieves a specific sandbox message from inbox
33 34 35 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 33 def get() base_get() end |
#html_analysis(message_id) ⇒ Hash
Get message HTML analysis
93 94 95 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 93 def html_analysis() client.get("#{base_path}/#{message_id}/analyze") end |
#html_body(message_id) ⇒ String
Get formatted HTML email body. Not applicable for plain text emails.
125 126 127 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 125 def html_body() client.get("#{base_path}/#{message_id}/body.html") end |
#html_source(message_id) ⇒ String
Get message source
117 118 119 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 117 def html_source() client.get("#{base_path}/#{message_id}/body.htmlsource") end |
#list(search: nil, last_id: nil, page: nil) ⇒ Array<SandboxMessage>
Lists all sandbox messages for the account, limited up to 30 at once Overrides page if both are given.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 61 def list(search: nil, last_id: nil, page: nil) raise ArgumentError, 'Provide either last_id or page, not both' unless last_id.nil? || page.nil? query_params = {} query_params[:search] = search unless search.nil? query_params[:last_id] = last_id unless last_id.nil? query_params[:page] = page unless page.nil? base_list(query_params) end |
#mail_headers(message_id) ⇒ Hash
Get mail headers
141 142 143 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 141 def mail_headers() client.get("#{base_path}/#{message_id}/mail_headers") end |
#mark_as_read(message_id, is_read: true) ⇒ SandboxMessage
Updates an existing sandbox message
50 51 52 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 50 def mark_as_read(, is_read: true) base_update(, { is_read: is_read }) end |
#raw_body(message_id) ⇒ String
Get raw message
109 110 111 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 109 def raw_body() client.get("#{base_path}/#{message_id}/body.raw") end |
#spam_score(message_id) ⇒ Hash
Get message spam score
85 86 87 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 85 def spam_score() client.get("#{base_path}/#{message_id}/spam_report") end |
#text_body(message_id) ⇒ String
Get text message
101 102 103 |
# File 'lib/mailtrap/sandbox_messages_api.rb', line 101 def text_body() client.get("#{base_path}/#{message_id}/body.txt") end |