Class: Trumail::Lookup
- Inherits:
-
Object
- Object
- Trumail::Lookup
- Defined in:
- lib/trumail/lookup.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #address ⇒ Object
- #catch_all? ⇒ Boolean
- #deliverable? ⇒ Boolean
- #disposable? ⇒ Boolean
- #domain ⇒ Object
- #error? ⇒ Boolean
- #free? ⇒ Boolean
- #full_inbox? ⇒ Boolean
- #gravatar? ⇒ Boolean
- #host_exists? ⇒ Boolean
-
#initialize(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT) ⇒ Lookup
constructor
A new instance of Lookup.
- #md5_hash ⇒ Object
- #role? ⇒ Boolean
- #success? ⇒ Boolean
- #suggestion ⇒ Object
- #url ⇒ Object
- #username ⇒ Object
- #valid_format? ⇒ Boolean
- #verify ⇒ Object
Constructor Details
#initialize(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT) ⇒ Lookup
Returns a new instance of Lookup.
14 15 16 17 18 19 20 |
# File 'lib/trumail/lookup.rb', line 14 def initialize(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT) @email = email @host = host @format = format.to_sym @response = nil @hash = {} end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
12 13 14 |
# File 'lib/trumail/lookup.rb', line 12 def email @email end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/trumail/lookup.rb', line 12 def format @format end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
12 13 14 |
# File 'lib/trumail/lookup.rb', line 12 def hash @hash end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
12 13 14 |
# File 'lib/trumail/lookup.rb', line 12 def host @host end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
12 13 14 |
# File 'lib/trumail/lookup.rb', line 12 def response @response end |
Class Method Details
.verify(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT) ⇒ Object
22 23 24 25 26 |
# File 'lib/trumail/lookup.rb', line 22 def self.verify(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT) klass = new(email, host: host, format: format) klass.verify klass end |
Instance Method Details
#address ⇒ Object
49 50 51 |
# File 'lib/trumail/lookup.rb', line 49 def address @hash['address'] end |
#catch_all? ⇒ Boolean
53 54 55 |
# File 'lib/trumail/lookup.rb', line 53 def catch_all? @hash['catchAll'] end |
#deliverable? ⇒ Boolean
57 58 59 |
# File 'lib/trumail/lookup.rb', line 57 def deliverable? @hash['deliverable'] end |
#disposable? ⇒ Boolean
61 62 63 |
# File 'lib/trumail/lookup.rb', line 61 def disposable? @hash['disposable'] end |
#domain ⇒ Object
65 66 67 |
# File 'lib/trumail/lookup.rb', line 65 def domain @hash['domain'] end |
#error? ⇒ Boolean
41 42 43 |
# File 'lib/trumail/lookup.rb', line 41 def error? !success? end |
#free? ⇒ Boolean
69 70 71 |
# File 'lib/trumail/lookup.rb', line 69 def free? @hash['free'] end |
#full_inbox? ⇒ Boolean
73 74 75 |
# File 'lib/trumail/lookup.rb', line 73 def full_inbox? @hash['fullInbox'] end |
#gravatar? ⇒ Boolean
77 78 79 |
# File 'lib/trumail/lookup.rb', line 77 def gravatar? @hash['gravatar'] end |
#host_exists? ⇒ Boolean
81 82 83 |
# File 'lib/trumail/lookup.rb', line 81 def host_exists? @hash['hostExists'] end |
#md5_hash ⇒ Object
85 86 87 |
# File 'lib/trumail/lookup.rb', line 85 def md5_hash @hash['md5Hash'] end |
#role? ⇒ Boolean
89 90 91 |
# File 'lib/trumail/lookup.rb', line 89 def role? @hash['role'] end |
#success? ⇒ Boolean
45 46 47 |
# File 'lib/trumail/lookup.rb', line 45 def success? @hash.key?('address') end |
#suggestion ⇒ Object
93 94 95 |
# File 'lib/trumail/lookup.rb', line 93 def suggestion @hash['suggestion'] end |
#url ⇒ Object
37 38 39 |
# File 'lib/trumail/lookup.rb', line 37 def url "#{@host}/v2/lookups/#{@format}?email=#{@email}" end |
#username ⇒ Object
97 98 99 |
# File 'lib/trumail/lookup.rb', line 97 def username @hash['username'] end |
#valid_format? ⇒ Boolean
101 102 103 |
# File 'lib/trumail/lookup.rb', line 101 def valid_format? @hash['validFormat'] end |
#verify ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/trumail/lookup.rb', line 28 def verify return @hash unless @response.nil? Typhoeus::Config.user_agent = Agents.random_user_agent(:desktop) @response = Typhoeus.get(url, accept_encoding: 'gzip,deflate').response_body parse_by_format end |