Class: Howitzer::MailtrapApi::Client

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeClient

Returns a new instance of Client.



10
11
12
# File 'lib/howitzer/mailtrap_api/client.rb', line 10

def initialize
  @api_token = Howitzer.mailtrap_api_token
end

Instance Method Details

#find_attachments(message) ⇒ Array

Finds attachments for message

Parameters:

  • message (Hash)

    which attachments should be extracted

Returns:

  • (Array)

    returns array of attachments



31
32
33
# File 'lib/howitzer/mailtrap_api/client.rb', line 31

def find_attachments(message)
  JSON.parse(RestClient.get("#{BASE_URL}/messages/#{message['id']}/attachments", 'Api-Token' => @api_token))
end

#find_message(recipient, subject) ⇒ Hash

Finds message according to given parameters

Parameters:

  • recipient (String)

    this is recipient mail address for message filtering

  • subject (String)

    this is subject of the message to filter particular message

Returns:

  • (Hash)

    json message parsed to ruby hash



20
21
22
23
24
# File 'lib/howitzer/mailtrap_api/client.rb', line 20

def find_message(recipient, subject)
  recipient = recipient.gsub('+', '%2B')
  messages = filter_by_subject(messages(recipient), subject)
  latest_message(messages)
end