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



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

def address
  @hash['address']
end

#catch_all?Boolean

Returns:

  • (Boolean)


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

def catch_all?
  @hash['catchAll']
end

#deliverable?Boolean

Returns:

  • (Boolean)


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

def deliverable?
  @hash['deliverable']
end

#disposable?Boolean

Returns:

  • (Boolean)


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

def disposable?
  @hash['disposable']
end

#domainObject



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

def domain
  @hash['domain']
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !success?
end

#free?Boolean

Returns:

  • (Boolean)


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

def free?
  @hash['free']
end

#full_inbox?Boolean

Returns:

  • (Boolean)


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

def full_inbox?
  @hash['fullInbox']
end

#gravatar?Boolean

Returns:

  • (Boolean)


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

def gravatar?
  @hash['gravatar']
end

#host_exists?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/trumail/lookup.rb', line 81

def host_exists?
  @hash['hostExists']
end

#md5_hashObject



85
86
87
# File 'lib/trumail/lookup.rb', line 85

def md5_hash
  @hash['md5Hash']
end

#role?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/trumail/lookup.rb', line 89

def role?
  @hash['role']
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  @hash.key?('address')
end

#suggestionObject



93
94
95
# File 'lib/trumail/lookup.rb', line 93

def suggestion
  @hash['suggestion']
end

#urlObject



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

def url
  "#{@host}/v2/lookups/#{@format}?email=#{@email}"
end

#usernameObject



97
98
99
# File 'lib/trumail/lookup.rb', line 97

def username
  @hash['username']
end

#valid_format?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/trumail/lookup.rb', line 101

def valid_format?
  @hash['validFormat']
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 = Agents.random_user_agent(:desktop)
  @response = Typhoeus.get(url, accept_encoding: 'gzip,deflate').response_body

  parse_by_format
end