Class: MelissaData::NativeObject::Email

Inherits:
Base
  • Object
show all
Defined in:
lib/melissadata/native_object/email.rb

Instance Attribute Summary

Attributes inherited from Base

#data_dir, #input, #obj, #output, #result_codes, #results_string

Instance Method Summary collapse

Methods inherited from Base

#license, #process, #process_result_codes, #valid_input?

Constructor Details

#initialize(opts = {}) ⇒ Email

Returns a new instance of Email.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/melissadata/native_object/email.rb', line 5

def initialize(opts={})
  @obj = MdEmailRubyWrapper::MdEmail.new
  obj.SetPathToEmailFiles(data_dir)
  obj.SetCorrectSyntax(1) # Enable/disable syntax correction
  obj.SetStandardizeCasing(1) # Enable/disable lowercasing of email
  obj.SetDatabaseLookup(1) # Enable/disable lookups against internal database of known domain names
  obj.SetMXLookup(0) # Enable/disable DNS lookups for MX records (slower - but can be more accurate)
  obj.SetUpdateDomain(1)

  @result_codes = [
    ['ES01', "Valid domain name"],
    ['ES02', "Invalid domain name"],
    ['ES03', "Domain name could not be verified"],
    ['ES10', "Syntax was changed/corrected"],
    ['ES11', "Top level domain was changed"],
    ['ES12', "Domain name spelling was corrected"],
    ['ES13', "Domain name was updated"],
    ['EE01', "Syntax error in email address"],
    ['EE02', "Top level domain not found"],
    ['EE03', "Mail server not found"]
  ]

  @defaults = {
    :email => ''
  }

  # At least one of these needs to be present
  @required_fields = [:email]

  super
end

Instance Method Details

#assign_valuesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/melissadata/native_object/email.rb', line 41

def assign_values
  @output = {
    :mailbox_name => obj.GetMailBoxName,
    :domain_name => obj.GetDomainName,
    :top_level_domain => obj.GetTopLevelDomain,
    :top_level_domain_description => obj.GetTopLevelDomainDescription,
    :email => obj.GetEmailAddress,
    :lookup_code => obj.GetStatusCode
  }

  # V - Verified
  # U - Unverified - not confirmed by lookup, but was not in the invalid domains list
  # X - Bad email address - either not located by MX lookup, or was on the invalid domains list
  if output[:lookup_code] == 'U'
    obj.SetMXLookup(1)
    obj.VerifyEmail(input[:email])
    obj.SetMXLookup(0)

    process_result_codes
  end
end

#parse_inputObject



37
38
39
# File 'lib/melissadata/native_object/email.rb', line 37

def parse_input
  obj.VerifyEmail(input[:email].to_s)
end