Class: Howitzer::MailtrapApi::Client
- Inherits:
-
Object
- Object
- Howitzer::MailtrapApi::Client
- Defined in:
- lib/howitzer/mailtrap_api/client.rb
Overview
A Mailtrap::Client object is used to communicate with the Mailtrap API.
Constant Summary collapse
- BASE_URL =
:nodoc:
"https://mailtrap.io/api/v1/inboxes/#{Howitzer.mailtrap_inbox_id}".freeze
Instance Method Summary collapse
-
#find_attachments(message) ⇒ Array
Finds attachments for message.
-
#find_message(recipient, subject) ⇒ Hash
Finds message according to given parameters.
- #get_html_body(message) ⇒ Object
- #get_raw_body(message) ⇒ Object
- #get_txt_body(message) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
Instance Method Details
#find_attachments(message) ⇒ Array
Finds attachments for message
31 32 33 |
# File 'lib/howitzer/mailtrap_api/client.rb', line 31 def () JSON.parse(RestClient.get("#{BASE_URL}/messages/#{['id']}/attachments", 'Api-Token' => @api_token)) end |
#find_message(recipient, subject) ⇒ Hash
Finds message according to given parameters
20 21 22 23 24 |
# File 'lib/howitzer/mailtrap_api/client.rb', line 20 def (recipient, subject) recipient = recipient.gsub('+', '%2B') = filter_by_subject((recipient), subject) () end |
#get_html_body(message) ⇒ Object
35 36 37 38 39 |
# File 'lib/howitzer/mailtrap_api/client.rb', line 35 def get_html_body() RestClient.get("#{BASE_URL}/messages/#{['id']}/body.html", 'Api-Token' => @api_token).body rescue => e raise Howitzer::CommunicationError, e. end |
#get_raw_body(message) ⇒ Object
47 48 49 50 51 |
# File 'lib/howitzer/mailtrap_api/client.rb', line 47 def get_raw_body() RestClient.get("#{BASE_URL}/messages/#{['id']}/body.raw", 'Api-Token' => @api_token).body rescue => e raise Howitzer::CommunicationError, e. end |
#get_txt_body(message) ⇒ Object
41 42 43 44 45 |
# File 'lib/howitzer/mailtrap_api/client.rb', line 41 def get_txt_body() RestClient.get("#{BASE_URL}/messages/#{['id']}/body.txt", 'Api-Token' => @api_token).body rescue => e raise Howitzer::CommunicationError, e. end |