Class: Emailverify::Response

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

Overview

Generic Response wrapper for Emailverify API responses.

Provides a V1Response module with common helpers similar to the ZeroBounce response structure (status, sub_status, disposable?, …). Use by wrapping a parsed JSON Hash:

resp = Emailverify::Response.new(parsed_json) resp.status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Response

Returns a new instance of Response.



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

def initialize(body)
  # normalize keys to strings for convenient access
  @body = (body || {}).each_with_object({}) { |(k, v), h| h[k.to_s] = v }
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

Instance Method Details

#[](key) ⇒ Object

Generic accessor by key



58
59
60
# File 'lib/emailverify/response.rb', line 58

def [](key)
  @body[key.to_s]
end

#api_statusObject

For balance responses: api_status



47
48
49
# File 'lib/emailverify/response.rb', line 47

def api_status
  @api_status ||= @body["api_status"]
end

#available_creditsObject

For balance responses: available_credits as Integer



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

def available_credits
  val = @body["available_credits"] || @body["availableCredits"] || @body["credits"]
  val.nil? ? nil : val.to_i
end

#emailObject

Email address returned by the API (if present)



32
33
34
# File 'lib/emailverify/response.rb', line 32

def email
  @email ||= @body["email"] || @body["email_address"]
end

#statusObject

Status field as returned by the API (string)



37
38
39
# File 'lib/emailverify/response.rb', line 37

def status
  @status ||= @body["status"]
end

#sub_statusObject

Sub-status (string) if present



42
43
44
# File 'lib/emailverify/response.rb', line 42

def sub_status
  @sub_status ||= @body["sub_status"] || @body["sub-status"] || @body["substatus"]
end

#to_hObject

Return underlying hash



23
24
25
# File 'lib/emailverify/response.rb', line 23

def to_h
  @body.dup
end