Class: Verifalia::EmailValidations::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/verifalia/email_validation/job.rb

Overview

Represents a snapshot of an email validation job, along with its overview and eventually validated entries.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(overview, entries) ⇒ Job

Returns a new instance of Job.



44
45
46
47
# File 'lib/verifalia/email_validation/job.rb', line 44

def initialize(overview, entries)
  @overview = overview
  @entries = entries
end

Instance Attribute Details

#entriesObject (readonly)

The eventually validated items for this email validation job.



42
43
44
# File 'lib/verifalia/email_validation/job.rb', line 42

def entries
  @entries
end

#overviewObject (readonly)

Overview information for this email validation job.



39
40
41
# File 'lib/verifalia/email_validation/job.rb', line 39

def overview
  @overview
end

Class Method Details

.from_json(data) ⇒ Object

Parse a Job from a JSON string.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/verifalia/email_validation/job.rb', line 50

def self.from_json(data)
  progress = nil

  # Parse the eventual progress information

  if data['overview'].respond_to?('progress')
    progress = Progress.new data['overview']['progress']['percentage'].to_f,
                            data['overview']['estimatedTimeRemaining']
  end

  # Parse the job overview

  overview = Overview.new data['overview']['id'],
                          DateTime.iso8601(data['overview']['submittedOn']),
                          (if data['overview'].key?('completedOn')
                             DateTime.iso8601(data['overview']['completedOn'])
                           end),
                          data['overview']['priority'],
                          data['overview']['name'],
                          data['overview']['owner'],
                          IPAddr.new(data['overview']['clientIP']),
                          DateTime.iso8601(data['overview']['createdOn']),
                          data['overview']['quality'],
                          data['overview']['retention'],
                          data['overview']['deduplication'],
                          data['overview']['status'],
                          data['overview']['noOfEntries'],
                          progress

  # Parse the eventual entries

  if data.key?('entries')
    entries = data['entries']['data'].map do |entry|
      Entry.new entry['inputData'],
                entry['classification'],
                entry['status'],
                entry['emailAddress'],
                entry['emailAddressLocalPart'],
                entry['emailAddressDomainPart'],
                (entry['hasInternationalMailboxName'] if entry.key?('hasInternationalMailboxName')),
                (entry['hasInternationalDomainName'] if entry.key?('hasInternationalDomainName')),
                (entry['isDisposableEmailAddress'] if entry.key?('isDisposableEmailAddress')),
                (entry['isRoleAccount'] if entry.key?('isRoleAccount')),
                (entry['isFreeEmailAddress'] if entry.key?('isFreeEmailAddress')),
                (entry['syntaxFailureIndex'] if entry.key?('syntaxFailureIndex')),
                entry['custom'],
                (entry['duplicateOf'] if entry.key?('duplicateOf')),
                DateTime.iso8601(entry['completedOn']),
                entry['asciiEmailAddressDomainPart'],
                (entry['suggestions'] if entry.key?('suggestions')) || []
    end
  end

  Job.new overview, entries
end