Skip to content

Commit

Permalink
Introduced deliverability reporting request/models
Browse files Browse the repository at this point in the history
  • Loading branch information
ey-mailosaur authored and jm-mailosaur committed Sep 30, 2024
1 parent 7e414f6 commit 7a921b8
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/Mailosaur/analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,21 @@ def spam(email)
model = JSON.parse(response.body)
Mailosaur::Models::SpamAnalysisResult.new(model)
end

#
# Perform a deliverability report
#
# Perform deliverability test on the specified email
#
# @param email The identifier of the email to be analyzed.
#
# @return [DeliverabilityReport] operation results.
#
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
end
end
18 changes: 18 additions & 0 deletions lib/Mailosaur/models/block_list_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Mailosaur
module Models
class BlockListResult < BaseModel
def initialize(data = {})
@id = data['id']
@name = data['name']
@result = data['result']
end

# @return [String]
attr_accessor :id
# @return [String]
attr_accessor :name
# @return [String]
attr_accessor :result
end
end
end
36 changes: 36 additions & 0 deletions lib/Mailosaur/models/content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Mailosaur
module Models
class Content < BaseModel
def initialize(data = {})
@embed = data['embed']
@iframe = data['iframe']
@object = data['object']
@script = data['script']
@short_urls = data['shortUrls']
@text_size = data['textSize']
@total_size = data['totalSize']
@missing_alt = data['missingAlt']
@missing_list_unsubscribe = data['missingListUnsubscribe']
end

# @return [Boolean]
attr_accessor :embed
# @return [Boolean]
attr_accessor :iframe
# @return [Boolean]
attr_accessor :object
# @return [Boolean]
attr_accessor :script
# @return [Boolean]
attr_accessor :short_urls
# @return [Integer]
attr_accessor :text_size
# @return [Integer]
attr_accessor :total_size
# @return [Boolean]
attr_accessor :missing_alt
# @return [Boolean]
attr_accessor :missing_list_unsubscribe
end
end
end
32 changes: 32 additions & 0 deletions lib/Mailosaur/models/deliverability_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Mailosaur
module Models
class DeliverabilityReport < BaseModel
def initialize(data = {})
@spf = Mailosaur::Models::EmailAuthenticationResult.new(data['spf'])
@dkim = []
(data['dkim'] || []).each { |i| @dkim << Mailosaur::Models::EmailAuthenticationResult.new(i) }
@dmarc = Mailosaur::Models::EmailAuthenticationResult.new(data['dmarc'])
@block_lists = []
(data['blockLists'] || []).each { |i| @block_lists << Mailosaur::Models::BlockListResult.new(i) }
@content = Mailosaur::Models::Content.new(data['content'])
@dns_records = Mailosaur::Models::DnsRecords.new(data['dnsRecords'])
@spam_assassin = Mailosaur::Models::SpamAssassinResult.new(data['spamAssassin'])
end

# @return [EmailAuthenticationResult]
attr_accessor :spf
# @return [Array<EmailAuthenticationResult>]
attr_accessor :dkim
# @return [EmailAuthenticationResult]
attr_accessor :dmarc
# @return [Array<BlockListResult>]
attr_accessor :block_lists
# @return [Content]
attr_accessor :content
# @return [DnsRecords]
attr_accessor :dns_records
# @return [SpamAssassinResult]
attr_accessor :spam_assassin
end
end
end
18 changes: 18 additions & 0 deletions lib/Mailosaur/models/dns_records.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Mailosaur
module Models
class DnsRecords < BaseModel
def initialize(data = {})
@a = data['a']
@mx = data['mx']
@ptr = data['ptr']
end

# @return [Array<String>]
attr_accessor :a
# @return [Array<String>]
attr_accessor :mx
# @return [Array<String>]
attr_accessor :ptr
end
end
end
21 changes: 21 additions & 0 deletions lib/Mailosaur/models/email_authentication_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Mailosaur
module Models
class EmailAuthenticationResult < BaseModel
def initialize(data = {})
@result = data['result']
@description = data['description']
@raw_value = data['rawValue']
@tags = data['tags']
end

# @return [String]
attr_accessor :result
# @return [String]
attr_accessor :description
# @return [String]
attr_accessor :raw_value
# @return [Hash<String,String>]
attr_accessor :tags
end
end
end
21 changes: 21 additions & 0 deletions lib/Mailosaur/models/spam_assassin_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Mailosaur
module Models
class SpamAssassinResult < BaseModel
def initialize(data = {})
@score = data['score']
@result = data['result']
@rules = []
(data['rules'] || []).each { |i| @rules << Mailosaur::Models::SpamAssassinRule.new(i) }
end

attr_accessor :spam_filter_results

# @return [Float]
attr_accessor :score
# @return [String]
attr_accessor :result
# @return [Array<SpamAssassinRule>]
attr_accessor :rules
end
end
end
6 changes: 6 additions & 0 deletions lib/mailosaur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ module Models
autoload :Code, 'Mailosaur/models/code.rb'
autoload :ServerListResult, 'Mailosaur/models/server_list_result.rb'
autoload :SpamFilterResults, 'Mailosaur/models/spam_filter_results.rb'
autoload :DeliverabilityReport, 'Mailosaur/models/deliverability_report.rb'
autoload :EmailAuthenticationResult, 'Mailosaur/models/email_authentication_result.rb'
autoload :BlockListResult, 'Mailosaur/models/block_list_result.rb'
autoload :Content, 'Mailosaur/models/content.rb'
autoload :DnsRecords, 'Mailosaur/models/dns_records.rb'
autoload :SpamAssassinResult, 'Mailosaur/models/spam_assassin_result.rb'
autoload :ServerCreateOptions, 'Mailosaur/models/server_create_options.rb'
autoload :UsageAccountLimits, 'Mailosaur/models/usage_account_limits.rb'
autoload :UsageAccountLimit, 'Mailosaur/models/usage_account_limit.rb'
Expand Down
34 changes: 34 additions & 0 deletions test/emails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,40 @@ def startup
end
end

context 'deliverability_report' do
should 'perform a deliverability report on an email' do
target_id = @@emails[0].id
result = @@client.analysis.deliverability(target_id)

assert_not_nil(result.spf)

result.dkim.each do |dkim|
assert_not_nil(dkim)
end

assert_not_nil(result.dmarc)

assert_not_nil(result.block_lists)
result.block_lists.each do |block_list|
assert_not_nil(block_list.id)
assert_not_nil(block_list.name)
end

assert_not_nil(result.content)

assert_not_nil(result.dns_records)
assert_not_nil(result.dns_records.a)
assert_not_nil(result.dns_records.mx)
assert_not_nil(result.dns_records.ptr)

result.spam_assassin.rules.each do |rule|
assert_instance_of(Float, rule.score)
assert_not_nil(rule.rule)
assert_not_nil(rule.description)
end
end
end

context 'delete' do
should 'delete an email' do
target_id = @@emails[4].id
Expand Down

0 comments on commit 7a921b8

Please sign in to comment.