Class: Mailosaur::MailosaurClient

Inherits:
Object
  • Object
show all
Defined in:
lib/mailosaur.rb

Overview

The Mailosaur client — the main entry point to the Mailosaur API. Construct an instance with your API key (or set the MAILOSAUR_API_KEY environment variable), then use the operations namespaces (messages, servers, files, devices, analysis, previews, usage) to automate email and SMS testing.

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, base_url: 'https://mailosaur.com/') ⇒ MailosaurClient

Returns an instance of the Mailosaur client.

Parameters:

  • api_key (String) (defaults to: nil)

    Optional API key. Overrides the MAILOSAUR_API_KEY environment variable if set.

  • base_url (String) (defaults to: 'https://mailosaur.com/')

    Optionally overrides the base URL of the Mailosaur service.

Raises:

  • (ArgumentError)

    If no API key is provided and the MAILOSAUR_API_KEY environment variable is not set.



76
77
78
79
80
81
82
83
# File 'lib/mailosaur.rb', line 76

def initialize(api_key = nil, base_url: 'https://mailosaur.com/')
  resolved_api_key = api_key || ENV['MAILOSAUR_API_KEY']

  raise ArgumentError, "'api_key' must be set. Set the MAILOSAUR_API_KEY environment variable or pass it to the MailosaurClient constructor." unless resolved_api_key

  @api_key = resolved_api_key
  @base_url = base_url
end

Instance Method Details

#analysisAnalysis

Operations for analyzing email content and deliverability, including spam scoring.

Returns:

  • (Analysis)

    the analysis operations namespace.



87
88
89
# File 'lib/mailosaur.rb', line 87

def analysis
  @analysis ||= Analysis.new(connection, method(:handle_http_error))
end

#devicesDevices

Operations for managing virtual security devices and retrieving their one-time passwords.

Returns:

  • (Devices)

    the devices operations namespace.



117
118
119
# File 'lib/mailosaur.rb', line 117

def devices
  @devices ||= Devices.new(connection, method(:handle_http_error))
end

#filesFiles

Operations for downloading attachments, EML source, and email preview screenshots.

Returns:

  • (Files)

    the files operations namespace.



93
94
95
# File 'lib/mailosaur.rb', line 93

def files
  @files ||= Files.new(connection, method(:handle_http_error))
end

#messagesMessages

Operations for finding, retrieving, creating, and managing email and SMS messages.

Returns:

  • (Messages)

    the messages operations namespace.



99
100
101
# File 'lib/mailosaur.rb', line 99

def messages
  @messages ||= Messages.new(connection, method(:handle_http_error))
end

#previewsPreviews

Operations for discovering the email clients available for generating email previews.

Returns:

  • (Previews)

    the previews operations namespace.



123
124
125
# File 'lib/mailosaur.rb', line 123

def previews
  @previews ||= Previews.new(connection, method(:handle_http_error))
end

#serversServers

Operations for creating and managing your Mailosaur inboxes (servers).

Returns:

  • (Servers)

    the servers operations namespace.



105
106
107
# File 'lib/mailosaur.rb', line 105

def servers
  @servers ||= Servers.new(connection, method(:handle_http_error))
end

#usageUsage

Operations for inspecting account usage limits and recent transactional usage.

Returns:

  • (Usage)

    the usage operations namespace.



111
112
113
# File 'lib/mailosaur.rb', line 111

def usage
  @usage ||= Usage.new(connection, method(:handle_http_error))
end