Class: Zerobounce::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/zerobounce/response.rb

Overview

A Zerobounce response

Author:

  • Aaron Frase

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, request) ⇒ Response

Returns a new instance of Response.

Parameters:



21
22
23
24
25
# File 'lib/zerobounce/response.rb', line 21

def initialize(response, request)
  @response = response
  @request = request
  @body = response.body
end

Instance Attribute Details

#requestZerobounce::Request (readonly)

The request instance.

Returns:



15
16
17
# File 'lib/zerobounce/response.rb', line 15

def request
  @request
end

#responseFaraday::Response (readonly)

The original Faraday::Response

Returns:

  • (Faraday::Response)

    the current value of response



15
16
17
# File 'lib/zerobounce/response.rb', line 15

def response
  @response
end

Instance Method Details

#accountString

The portion of the email address before the “@” symbol.

Returns:

  • (String)


82
83
84
# File 'lib/zerobounce/response.rb', line 82

def 
  @account ||= @body[:account]
end

#addressString

The email address you are validating.

Returns:

  • (String)


75
76
77
# File 'lib/zerobounce/response.rb', line 75

def address
  @address ||= @body[:address]
end

#cityString?

The city of the IP passed in.

Returns:

  • (String, nil)


138
139
140
# File 'lib/zerobounce/response.rb', line 138

def city
  @city ||= @body[:city]
end

#countryString?

The country of the IP passed in.

Returns:

  • (String, nil)


124
125
126
# File 'lib/zerobounce/response.rb', line 124

def country
  @country ||= @body[:country]
end

#creation_dateTime?

The creation date of the email when available.

Returns:

  • (Time, nil)


196
197
198
# File 'lib/zerobounce/response.rb', line 196

def creation_date
  @creation_date ||= @body[:creationdate] && Time.parse(@body[:creationdate])
end

#disposable?Boolean

Note:

If you have valid emails with this flag set to true, you shouldn’t email them.

If the email domain is disposable, which are usually temporary email addresses.

These are temporary emails created for the sole purpose to sign up to websites without giving their real email address. These emails are short lived from 15 minutes to around 6 months.

Returns:

  • (Boolean)


173
174
175
# File 'lib/zerobounce/response.rb', line 173

def disposable?
  @disposable ||= @body[:disposable] || false
end

#domainString

The portion of the email address after the “@” symbol.

Returns:

  • (String)


89
90
91
# File 'lib/zerobounce/response.rb', line 89

def domain
  @domain ||= @body[:domain]
end

#firstnameString?

The first name of the owner of the email when available.

Returns:

  • (String, nil)


96
97
98
# File 'lib/zerobounce/response.rb', line 96

def firstname
  @firstname ||= @body[:firstname]
end

#genderString?

The gender of the owner of the email when available.

Returns:

  • (String, nil)


110
111
112
# File 'lib/zerobounce/response.rb', line 110

def gender
  @gender ||= @body[:gender]
end

#inspectString

Note:

Overriding inspect to hide the #request/#response instance variables

Returns a string containing a human-readable representation.

Returns:

  • (String)


205
206
207
# File 'lib/zerobounce/response.rb', line 205

def inspect
  "#<#{self.class.name}:#{object_id}>"
end

#invalid?Boolean

The opposite of #valid?

Returns:

  • (Boolean)


161
162
163
# File 'lib/zerobounce/response.rb', line 161

def invalid?
  !valid?
end

#lastnameString?

The last name of the owner of the email when available.

Returns:

  • (String, nil)


103
104
105
# File 'lib/zerobounce/response.rb', line 103

def lastname
  @lastname ||= @body[:lastname]
end

#locationString?

The location of the owner of the email when available.

Returns:

  • (String, nil)


117
118
119
# File 'lib/zerobounce/response.rb', line 117

def location
  @location ||= @body[:location]
end

#process_dateTime?

The UTC time the email was validated.

Returns:

  • (Time, nil)


189
190
191
# File 'lib/zerobounce/response.rb', line 189

def process_date
  @process_date ||= @body[:processedat] && Time.parse(@body[:processedat])
end

#regionString?

The region/state of the IP passed in.

Returns:

  • (String, nil)


131
132
133
# File 'lib/zerobounce/response.rb', line 131

def region
  @region ||= @body[:region]
end

#statusSymbol

Deliverability status

Possible values:

:valid
:invalid
:catch_all
:unknown
:spamtrap
:abuse
:do_not_mail

Returns:

  • (Symbol)

    The status as a Symbol.



39
40
41
# File 'lib/zerobounce/response.rb', line 39

def status
  @status ||= underscore(@body[:status])&.to_sym
end

#sub_statusSymbol

A more detailed status

Possible values:

:antispam_system
:greylisted
:mail_server_temporary_error
:forcible_disconnect
:mail_server_did_not_respond
:timeout_exceeded
:failed_smtp_connection
:mailbox_quota_exceeded
:exception_occurred
:possible_traps
:role_based
:global_suppression
:mailbox_not_found
:no_dns_entries
:failed_syntax_check
:possible_typo
:unroutable_ip_address
:leading_period_removed
:does_not_accept_mail
:alias_address

Returns:

  • (Symbol)

    The sub_status as a Symbol.



68
69
70
# File 'lib/zerobounce/response.rb', line 68

def sub_status
  @sub_status ||= underscore(@body[:sub_status])&.to_sym
end

#to_hHash

Convert to a hash.

Returns:

  • (Hash)


212
213
214
215
216
217
# File 'lib/zerobounce/response.rb', line 212

def to_h
  public_methods(false).each_with_object({}) do |meth, memo|
    next if i[request response inspect to_h].include?(meth)
    memo[meth] = send(meth)
  end
end

#toxic?Boolean

Note:

If you have a valid email with this flag set to true, you shouldn’t email them.

These domains are known for abuse, spam, or are bot created.

Returns:

  • (Boolean)


182
183
184
# File 'lib/zerobounce/response.rb', line 182

def toxic?
  @toxic ||= @body[:toxic] || false
end

#valid?Boolean

Note:

Uses the values from Configuration#valid_statuses

Is this email considered valid?

Returns:

  • (Boolean)


154
155
156
# File 'lib/zerobounce/response.rb', line 154

def valid?
  @valid ||= Zerobounce.config.valid_statuses.include?(status)
end

#zipcodeString?

The zipcode of the IP passed in.

Returns:

  • (String, nil)


145
146
147
# File 'lib/zerobounce/response.rb', line 145

def zipcode
  @zipcode ||= @body[:zipcode]
end