Class: Emailverify::Response
- Inherits:
-
Object
- Object
- Emailverify::Response
- 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
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Generic accessor by key.
-
#api_status ⇒ Object
For balance responses: api_status.
-
#available_credits ⇒ Object
For balance responses: available_credits as Integer.
-
#email ⇒ Object
Email address returned by the API (if present).
-
#initialize(body) ⇒ Response
constructor
A new instance of Response.
-
#status ⇒ Object
Status field as returned by the API (string).
-
#sub_status ⇒ Object
Sub-status (string) if present.
-
#to_h ⇒ Object
Return underlying hash.
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
#body ⇒ Object (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_status ⇒ Object
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_credits ⇒ Object
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 |
#email ⇒ Object
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 |
#status ⇒ Object
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_status ⇒ Object
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_h ⇒ Object
Return underlying hash
23 24 25 |
# File 'lib/emailverify/response.rb', line 23 def to_h @body.dup end |