Class: EmailHunter::Discover

Inherits:
Object
  • Object
show all
Defined in:
lib/email_hunter/discover.rb

Constant Summary collapse

API_URL =
'https://api.hunter.io/v2/discover'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, key, params = {}) ⇒ Discover

Returns a new instance of Discover.



12
13
14
15
16
# File 'lib/email_hunter/discover.rb', line 12

def initialize(query, key, params = {})
  @query = query
  @key = key
  @params = params
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/email_hunter/discover.rb', line 10

def key
  @key
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/email_hunter/discover.rb', line 10

def params
  @params
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'lib/email_hunter/discover.rb', line 10

def query
  @query
end

Instance Method Details

#huntObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/email_hunter/discover.rb', line 18

def hunt
  response_data = fetch_discover_data
  return nil if response_data.empty?

  # Convert to OpenStruct for easy access
  result = OpenStruct.new(response_data)

  # Recursively convert nested hashes to OpenStructs
  convert_hash_to_struct(result, response_data)

  result
end