Class: EmailHunter::People

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

Constant Summary collapse

API_URL =
'https://api.hunter.io/v2/people/find'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, key) ⇒ People



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

def initialize(email, key)
  @email = email
  @key = key
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



11
12
13
# File 'lib/email_hunter/people.rb', line 11

def email
  @email
end

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/email_hunter/people.rb', line 11

def key
  @key
end

Instance Method Details

#huntObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/email_hunter/people.rb', line 18

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

  # Convert nested data structure to a Struct
  data = response_data[:data]
  meta = response_data[:meta]

  result = OpenStruct.new(
    data: OpenStruct.new(data),
    meta: OpenStruct.new(meta)
  )

  # Recursively convert nested hashes to OpenStructs for deeper access
  convert_hash_to_struct(result.data, data)

  result
end