Class: Zerobounce::Response
- Inherits:
-
Object
- Object
- Zerobounce::Response
- Defined in:
- lib/zerobounce/response.rb,
lib/zerobounce/response/v1_response.rb,
lib/zerobounce/response/v2_response.rb
Overview
A Zerobounce response
Defined Under Namespace
Modules: V1Response, V2Response
Instance Attribute Summary collapse
-
#request ⇒ Zerobounce::Request
readonly
The request instance.
-
#response ⇒ Faraday::Response
readonly
The original Faraday::Response.
Instance Method Summary collapse
-
#account ⇒ String
The portion of the email address before the “@” symbol.
-
#address ⇒ String
The email address you are validating.
-
#city ⇒ String?
The city of the IP passed in.
-
#country ⇒ String?
The country of the IP passed in.
-
#domain ⇒ String
The portion of the email address after the “@” symbol.
-
#firstname ⇒ String?
The first name of the owner of the email when available.
-
#gender ⇒ String?
The gender of the owner of the email when available.
-
#initialize(response, request) ⇒ Response
constructor
A new instance of Response.
-
#inspect ⇒ String
Returns a string containing a human-readable representation.
-
#invalid? ⇒ Boolean
The opposite of #valid?.
-
#lastname ⇒ String?
The last name of the owner of the email when available.
-
#region ⇒ String?
The region/state of the IP passed in.
-
#to_h ⇒ Hash
Convert to a hash.
-
#valid? ⇒ Boolean
Is this email considered valid?.
-
#zipcode ⇒ String?
The zipcode of the IP passed in.
Constructor Details
#initialize(response, request) ⇒ Response
Returns a new instance of Response.
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
#request ⇒ Zerobounce::Request (readonly)
The request instance.
17 18 19 |
# File 'lib/zerobounce/response.rb', line 17 def request @request end |
#response ⇒ Faraday::Response (readonly)
The original Faraday::Response
17 18 19 |
# File 'lib/zerobounce/response.rb', line 17 def response @response end |
Instance Method Details
#account ⇒ String
The portion of the email address before the “@” symbol.
46 47 48 |
# File 'lib/zerobounce/response.rb', line 46 def account @account ||= @body[:account] end |
#address ⇒ String
The email address you are validating.
39 40 41 |
# File 'lib/zerobounce/response.rb', line 39 def address @address ||= @body[:address] end |
#city ⇒ String?
The city of the IP passed in.
95 96 97 |
# File 'lib/zerobounce/response.rb', line 95 def city @city ||= @body[:city] end |
#country ⇒ String?
The country of the IP passed in.
81 82 83 |
# File 'lib/zerobounce/response.rb', line 81 def country @country ||= @body[:country] end |
#domain ⇒ String
The portion of the email address after the “@” symbol.
53 54 55 |
# File 'lib/zerobounce/response.rb', line 53 def domain @domain ||= @body[:domain] end |
#firstname ⇒ String?
The first name of the owner of the email when available.
60 61 62 |
# File 'lib/zerobounce/response.rb', line 60 def firstname @firstname ||= @body[:firstname] end |
#gender ⇒ String?
The gender of the owner of the email when available.
74 75 76 |
# File 'lib/zerobounce/response.rb', line 74 def gender @gender ||= @body[:gender] end |
#inspect ⇒ 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?
118 119 120 |
# File 'lib/zerobounce/response.rb', line 118 def invalid? !valid? end |
#lastname ⇒ String?
The last name of the owner of the email when available.
67 68 69 |
# File 'lib/zerobounce/response.rb', line 67 def lastname @lastname ||= @body[:lastname] end |
#region ⇒ String?
The region/state of the IP passed in.
88 89 90 |
# File 'lib/zerobounce/response.rb', line 88 def region @region ||= @body[:region] end |
#to_h ⇒ Hash
Convert to a 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
Uses the values from Configuration#valid_statuses
Is this email considered valid?
111 112 113 |
# File 'lib/zerobounce/response.rb', line 111 def valid? @valid ||= Zerobounce.config.valid_statuses.include?(status) end |
#zipcode ⇒ String?
The zipcode of the IP passed in.
102 103 104 |
# File 'lib/zerobounce/response.rb', line 102 def zipcode @zipcode ||= @body[:zipcode] end |