Class: Mailosaur::Analysis

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

Overview

Operations for analyzing the content and deliverability of an email, including SpamAssassin scoring and per-provider deliverability reports. Accessed via client.analysis.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, handle_http_error) ⇒ Analysis

Creates and initializes a new instance of the Analysis class.

Parameters:

  • conn (Faraday::Connection)

    The client connection.

  • handle_http_error (Method)

    Callback used to convert HTTP error responses into errors.



10
11
12
13
# File 'lib/Mailosaur/analysis.rb', line 10

def initialize(conn, handle_http_error)
  @conn = conn
  @handle_http_error = handle_http_error
end

Instance Attribute Details

#connConnection (readonly)

Returns the client connection.

Returns:

  • (Connection)

    the client connection.



16
17
18
# File 'lib/Mailosaur/analysis.rb', line 16

def conn
  @conn
end

Instance Method Details

#deliverability(email) ⇒ Mailosaur::Models::DeliverabilityReport

Perform a deliverability report of an email.

Parameters:

  • email (String)

    The identifier of the message to be analyzed.

Returns:



39
40
41
42
43
44
# File 'lib/Mailosaur/analysis.rb', line 39

def deliverability(email)
  response = conn.get "api/analysis/deliverability/#{email}"
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  Mailosaur::Models::DeliverabilityReport.new(model)
end

#spam(email) ⇒ Mailosaur::Models::SpamAnalysisResult

Perform a spam analysis of an email.

Parameters:

  • email (String)

    The identifier of the message to be analyzed.

Returns:



25
26
27
28
29
30
# File 'lib/Mailosaur/analysis.rb', line 25

def spam(email)
  response = conn.get "api/analysis/spam/#{email}"
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  Mailosaur::Models::SpamAnalysisResult.new(model)
end