class Zerobounce::Response

A Zerobounce response

@author Aaron Frase

@attr_reader [Zerobounce::Request] request

The request instance.

@attr_reader [Faraday::Response] response

The original {https://www.rubydoc.info/gems/faraday/1.4.2/Faraday/Response Faraday::Response}

Attributes

request[R]
response[R]

Public Class Methods

new(response, request) click to toggle source

@param [Faraday::Response] response @param [Zerobounce::Request::V2Response, Zerobounce::Request::V1Response] request

# File lib/zerobounce/response.rb, line 23
def initialize(response, request)
  @response = response
  @request = request
  @body = response.body

  case request.api_version
  when 'v2'
    extend(V2Response)
  else
    extend(V1Response)
  end
end

Public Instance Methods

account() click to toggle source

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

@return [String]

# File lib/zerobounce/response.rb, line 46
def account
  @account ||= @body[:account]
end
address() click to toggle source

The email address you are validating.

@return [String]

# File lib/zerobounce/response.rb, line 39
def address
  @address ||= @body[:address]
end
city() click to toggle source

The city of the IP passed in.

@return [String, nil]

# File lib/zerobounce/response.rb, line 95
def city
  @city ||= @body[:city]
end
country() click to toggle source

The country of the IP passed in.

@return [String, nil]

# File lib/zerobounce/response.rb, line 81
def country
  @country ||= @body[:country]
end
domain() click to toggle source

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

@return [String]

# File lib/zerobounce/response.rb, line 53
def domain
  @domain ||= @body[:domain]
end
firstname() click to toggle source

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

@return [String, nil]

# File lib/zerobounce/response.rb, line 60
def firstname
  @firstname ||= @body[:firstname]
end
gender() click to toggle source

The gender of the owner of the email when available.

@return [String, nil]

# File lib/zerobounce/response.rb, line 74
def gender
  @gender ||= @body[:gender]
end
inspect() click to toggle source

Returns a string containing a human-readable representation.

@note Overriding inspect to hide the {#request}/{#response} instance variables

@return [String]

# File lib/zerobounce/response.rb, line 127
def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)} @address=#{address}>"
end
invalid?() click to toggle source

The opposite of {#valid?}

@return [Boolean]

# File lib/zerobounce/response.rb, line 118
def invalid?
  !valid?
end
lastname() click to toggle source

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

@return [String, nil]

# File lib/zerobounce/response.rb, line 67
def lastname
  @lastname ||= @body[:lastname]
end
region() click to toggle source

The region/state of the IP passed in.

@return [String, nil]

# File lib/zerobounce/response.rb, line 88
def region
  @region ||= @body[:region]
end
to_h() click to toggle source

Convert to a hash.

@return [Hash]

# File lib/zerobounce/response.rb, line 134
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
valid?() click to toggle source

Is this email considered valid?

@note Uses the values from {Zerobounce::Configuration#valid_statuses}

@return [Boolean]

# File lib/zerobounce/response.rb, line 111
def valid?
  @valid ||= Zerobounce.config.valid_statuses.include?(status)
end
zipcode() click to toggle source

The zipcode of the IP passed in.

@return [String, nil]

# File lib/zerobounce/response.rb, line 102
def zipcode
  @zipcode ||= @body[:zipcode]
end