Class: EmailHunter::LeadEnrichment

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, email: nil, linkedin: nil) ⇒ LeadEnrichment

Returns a new instance of LeadEnrichment.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
# File 'lib/email_hunter/lead_enrichment.rb', line 13

def initialize(key, email: nil, linkedin: nil)
  @key = key
  @email = email
  @linkedin = linkedin

  raise ArgumentError, 'Either email or linkedin must be provided' if email.nil? && linkedin.nil?
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



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

def email
  @email
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#linkedinObject (readonly)

Returns the value of attribute linkedin.



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

def linkedin
  @linkedin
end

Instance Method Details

#huntObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/email_hunter/lead_enrichment.rb', line 21

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

  # Convert nested data structure to OpenStruct
  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