Class: VerifyAnyEmail::VerificationResult

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

Overview

Immutable wrapper around a single verification result object returned by POST /v1/verify.

Access the raw hash with #to_h, or use the reader methods below. Boolean helpers such as #deliverable? classify the #status field.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ VerificationResult

Returns a new instance of VerificationResult.

Parameters:

  • data (Hash)

    The result object from the API response.



14
15
16
# File 'lib/verifyanyemail/verification_result.rb', line 14

def initialize(data)
  @raw = data.is_a?(Hash) ? data : {}
end

Instance Attribute Details

#rawHash (readonly)

Returns The raw parsed result hash (string keys).

Returns:

  • (Hash)

    The raw parsed result hash (string keys).



11
12
13
# File 'lib/verifyanyemail/verification_result.rb', line 11

def raw
  @raw
end

Instance Method Details

#accountString?

Returns Local part (before the @).

Returns:

  • (String, nil)

    Local part (before the @).



29
30
31
# File 'lib/verifyanyemail/verification_result.rb', line 29

def 
  @raw["account"]
end

#catch_all?Boolean?

Returns:

  • (Boolean, nil)


131
132
133
# File 'lib/verifyanyemail/verification_result.rb', line 131

def catch_all?
  checks["catchAll"]
end

#checked_atString?

Returns ISO-8601 timestamp of when the check ran.

Returns:

  • (String, nil)

    ISO-8601 timestamp of when the check ran.



74
75
76
# File 'lib/verifyanyemail/verification_result.rb', line 74

def checked_at
  @raw["checkedAt"]
end

#checksHash

Returns The checks sub-object (string keys), or {} when absent.

Returns:

  • (Hash)

    The checks sub-object (string keys), or {} when absent.



54
55
56
# File 'lib/verifyanyemail/verification_result.rb', line 54

def checks
  @raw["checks"] || {}
end

#deliverable?Boolean

Returns status == "deliverable".

Returns:

  • (Boolean)

    status == "deliverable"



79
80
81
# File 'lib/verifyanyemail/verification_result.rb', line 79

def deliverable?
  status == "deliverable"
end

#disposable?Boolean?

Returns:

  • (Boolean, nil)


141
142
143
# File 'lib/verifyanyemail/verification_result.rb', line 141

def disposable?
  checks["disposable"]
end

#domainString?

Returns Domain part (after the @).

Returns:

  • (String, nil)

    Domain part (after the @).



34
35
36
# File 'lib/verifyanyemail/verification_result.rb', line 34

def domain
  @raw["domain"]
end

#duration_msInteger?

Returns Wall-clock verification time in milliseconds.

Returns:

  • (Integer, nil)

    Wall-clock verification time in milliseconds.



69
70
71
# File 'lib/verifyanyemail/verification_result.rb', line 69

def duration_ms
  @raw["durationMs"]
end

#emailString?

Returns The address exactly as submitted.

Returns:

  • (String, nil)

    The address exactly as submitted.



19
20
21
# File 'lib/verifyanyemail/verification_result.rb', line 19

def email
  @raw["email"]
end

#free_provider?Boolean?

Returns:

  • (Boolean, nil)


146
147
148
# File 'lib/verifyanyemail/verification_result.rb', line 146

def free_provider?
  checks["freeProvider"]
end

#gibberish?Boolean?

Returns:

  • (Boolean, nil)


156
157
158
# File 'lib/verifyanyemail/verification_result.rb', line 156

def gibberish?
  checks["gibberish"]
end

#has_mx_records?Boolean?

Returns:

  • (Boolean, nil)


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

def has_mx_records?
  checks["hasMxRecords"]
end

#mailbox_exists?Boolean?

Returns:

  • (Boolean, nil)


126
127
128
# File 'lib/verifyanyemail/verification_result.rb', line 126

def mailbox_exists?
  checks["mailboxExists"]
end

#normalizedString?

Returns Normalized (lowercased/trimmed) address.

Returns:

  • (String, nil)

    Normalized (lowercased/trimmed) address.



24
25
26
# File 'lib/verifyanyemail/verification_result.rb', line 24

def normalized
  @raw["normalized"]
end

#null_mx?Boolean?

Returns:

  • (Boolean, nil)


116
117
118
# File 'lib/verifyanyemail/verification_result.rb', line 116

def null_mx?
  checks["nullMx"]
end

#possible_typo?Boolean?

Returns:

  • (Boolean, nil)


151
152
153
# File 'lib/verifyanyemail/verification_result.rb', line 151

def possible_typo?
  checks["possibleTypo"]
end

#risky?Boolean

Returns status == "risky".

Returns:

  • (Boolean)

    status == "risky"



89
90
91
# File 'lib/verifyanyemail/verification_result.rb', line 89

def risky?
  status == "risky"
end

#role_based?Boolean?

Returns:

  • (Boolean, nil)


136
137
138
# File 'lib/verifyanyemail/verification_result.rb', line 136

def role_based?
  checks["roleBased"]
end

#safe_to_sendBoolean?

Returns Whether the API recommends sending to this address.

Returns:

  • (Boolean, nil)

    Whether the API recommends sending to this address.



64
65
66
# File 'lib/verifyanyemail/verification_result.rb', line 64

def safe_to_send
  @raw["safeToSend"]
end

#safe_to_send?Boolean

Returns Convenience alias for the safeToSend flag.

Returns:

  • (Boolean)

    Convenience alias for the safeToSend flag.



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

def safe_to_send?
  safe_to_send == true
end

#scoreInteger?

Returns Confidence score, 0-100.

Returns:

  • (Integer, nil)

    Confidence score, 0-100.



49
50
51
# File 'lib/verifyanyemail/verification_result.rb', line 49

def score
  @raw["score"]
end

#smtp_connectable?Boolean?

Returns:

  • (Boolean, nil)


121
122
123
# File 'lib/verifyanyemail/verification_result.rb', line 121

def smtp_connectable?
  checks["smtpConnectable"]
end

#statusString?

Returns One of: deliverable, undeliverable, risky, unknown.

Returns:

  • (String, nil)

    One of: deliverable, undeliverable, risky, unknown.



39
40
41
# File 'lib/verifyanyemail/verification_result.rb', line 39

def status
  @raw["status"]
end

#sub_statusString?

Returns Finer-grained reason (e.g. valid_mailbox, catch_all).

Returns:

  • (String, nil)

    Finer-grained reason (e.g. valid_mailbox, catch_all).



44
45
46
# File 'lib/verifyanyemail/verification_result.rb', line 44

def sub_status
  @raw["subStatus"]
end

#suggestionString?

Returns "Did you mean" domain correction, when available.

Returns:

  • (String, nil)

    "Did you mean" domain correction, when available.



59
60
61
# File 'lib/verifyanyemail/verification_result.rb', line 59

def suggestion
  @raw["suggestion"]
end

#syntax?Boolean?

Returns:

  • (Boolean, nil)


106
107
108
# File 'lib/verifyanyemail/verification_result.rb', line 106

def syntax?
  checks["syntax"]
end

#to_hHash

Returns The raw underlying hash.

Returns:

  • (Hash)

    The raw underlying hash.



161
162
163
# File 'lib/verifyanyemail/verification_result.rb', line 161

def to_h
  @raw
end

#to_sString Also known as: inspect

Returns:

  • (String)


166
167
168
169
# File 'lib/verifyanyemail/verification_result.rb', line 166

def to_s
  "#<VerifyAnyEmail::VerificationResult #{normalized || email.inspect} " \
    "status=#{status.inspect} score=#{score.inspect}>"
end

#undeliverable?Boolean

Returns status == "undeliverable".

Returns:

  • (Boolean)

    status == "undeliverable"



84
85
86
# File 'lib/verifyanyemail/verification_result.rb', line 84

def undeliverable?
  status == "undeliverable"
end

#unknown?Boolean

Returns status == "unknown".

Returns:

  • (Boolean)

    status == "unknown"



94
95
96
# File 'lib/verifyanyemail/verification_result.rb', line 94

def unknown?
  status == "unknown"
end