Class: EmailHunter::CombinedEnrichment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CombinedEnrichment.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
# File 'lib/email_hunter/combined_enrichment.rb', line 11

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.



9
10
11
# File 'lib/email_hunter/combined_enrichment.rb', line 9

def email
  @email
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/email_hunter/combined_enrichment.rb', line 9

def key
  @key
end

#linkedinObject (readonly)

Returns the value of attribute linkedin.



9
10
11
# File 'lib/email_hunter/combined_enrichment.rb', line 9

def linkedin
  @linkedin
end

Instance Method Details

#huntObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/email_hunter/combined_enrichment.rb', line 19

def hunt
  # First get lead enrichment data
  lead_data = LeadEnrichment.new(key, email: email, linkedin: linkedin).hunt
  return nil if lead_data.nil?

  # Extract domain from employment if available
  domain = lead_data.data.employment&.domain
  return lead_data if domain.nil?

  # Get company enrichment data
  company_data = CompanyEnrichment.new(domain, key).hunt

  # Combine the data
  OpenStruct.new(
    lead: lead_data,
    company: company_data,
    meta: OpenStruct.new(
      email: email,
      linkedin: linkedin,
      domain: domain
    )
  )
rescue StandardError => e
  # If company enrichment fails, just return lead data
  OpenStruct.new(
    lead: lead_data,
    company: nil,
    meta: OpenStruct.new(
      email: email,
      linkedin: linkedin,
      error: e.message
    )
  )
end