Class: Trumail::Lookup

Inherits:
Object
  • Object
show all
Defined in:
lib/trumail/lookup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#emailObject (readonly)

Returns the value of attribute email.



12
13
14
# File 'lib/trumail/lookup.rb', line 12

def email
  @email
end

#formatObject (readonly)

Returns the value of attribute format.



12
13
14
# File 'lib/trumail/lookup.rb', line 12

def format
  @format
end

#hashObject (readonly)

Returns the value of attribute hash.



12
13
14
# File 'lib/trumail/lookup.rb', line 12

def hash
  @hash
end

#hostObject (readonly)

Returns the value of attribute host.



12
13
14
# File 'lib/trumail/lookup.rb', line 12

def host
  @host
end

#responseObject (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

#addressObject



45
46
47
# File 'lib/trumail/lookup.rb', line 45

def address
  @hash['address']
end

#catch_all?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/trumail/lookup.rb', line 49

def catch_all?
  @hash['catchAll']
end

#deliverable?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/trumail/lookup.rb', line 53

def deliverable?
  @hash['deliverable']
end

#disposable?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/trumail/lookup.rb', line 57

def disposable?
  @hash['disposable']
end

#domainObject



61
62
63
# File 'lib/trumail/lookup.rb', line 61

def domain
  @hash['domain']
end

#full_inbox?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/trumail/lookup.rb', line 65

def full_inbox?
  @hash['fullInbox']
end

#gravatar?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/trumail/lookup.rb', line 69

def gravatar?
  @hash['gravatar']
end

#host_exists?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/trumail/lookup.rb', line 73

def host_exists?
  @hash['hostExists']
end

#to_hObject



41
42
43
# File 'lib/trumail/lookup.rb', line 41

def to_h
  @hash
end

#urlObject



37
38
39
# File 'lib/trumail/lookup.rb', line 37

def url
  "#{@host}/#{@format}/#{@email}"
end

#usernameObject



77
78
79
# File 'lib/trumail/lookup.rb', line 77

def username
  @hash['username']
end

#verifyObject



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 = UserAgentDB.random
  @response = Typhoeus.get(url, accept_encoding: 'gzip,deflate').response_body

  parse_by_format
end