Class: Zerobounce::Response

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

Overview

A Zerobounce response

Author:

  • Aaron Frase

Defined Under Namespace

Modules: V1Response, V2Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, request) ⇒ Response

Returns a new instance of Response.

Parameters:

  • response (Faraday::Response)
  • request (Zerobounce::Request::V2Response, Zerobounce::Request::V1Response)


23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Attribute Details

#requestZerobounce::Request (readonly)

The request instance.

Returns:



17
18
19
# File 'lib/zerobounce/response.rb', line 17

def request
  @request
end

#responseFaraday::Response (readonly)

The original Faraday::Response

Returns:

  • (Faraday::Response)

    the current value of response



17
18
19
# File 'lib/zerobounce/response.rb', line 17

def response
  @response
end

Instance Method Details

#accountString

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

Returns:

  • (String)


46
47
48
# File 'lib/zerobounce/response.rb', line 46

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

#addressString

The email address you are validating.

Returns:

  • (String)


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

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

#cityString?

The city of the IP passed in.

Returns:

  • (String, nil)


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

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

#countryString?

The country of the IP passed in.

Returns:

  • (String, nil)


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

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

#domainString

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

Returns:

  • (String)


53
54
55
# File 'lib/zerobounce/response.rb', line 53

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

#firstnameString?

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

Returns:

  • (String, nil)


60
61
62
# File 'lib/zerobounce/response.rb', line 60

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

#genderString?

The gender of the owner of the email when available.

Returns:

  • (String, nil)


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

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)


127
128
129
# File 'lib/zerobounce/response.rb', line 127

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)} @address=#{address}>"
end

#invalid?Boolean

The opposite of #valid?

Returns:

  • (Boolean)


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

def invalid?
  !valid?
end

#lastnameString?

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

Returns:

  • (String, nil)


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

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

#regionString?

The region/state of the IP passed in.

Returns:

  • (String, nil)


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

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

#to_hHash

Convert to a hash.

Returns:

  • (Hash)


134
135
136
137
138
139
140
# 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?Boolean

Note:

Uses the values from Configuration#valid_statuses

Is this email considered valid?

Returns:

  • (Boolean)


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

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

#zipcodeString?

The zipcode of the IP passed in.

Returns:

  • (String, nil)


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

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