Class: BlackStack::Enrichment

Inherits:
Object
  • Object
show all
Defined in:
lib/blackstack-enrichment.rb

Constant Summary collapse

@@apollo_apikey =
nil

Instance Method Summary collapse

Constructor Details

#initialize(h = {}) ⇒ Enrichment

Returns a new instance of Enrichment.



7
8
9
10
# File 'lib/blackstack-enrichment.rb', line 7

def initialize(h={})
    @apollo_apikey = h[:apollo_apikey]
    @findymail_apikey = h[:findymail_apikey]
end

Instance Method Details

#find_person_from_linkedin_url(url:) ⇒ Object

Retrieve the email of a person from a LinkedIn URL

Reference: apolloio.github.io/apollo-api-docs/?shell#enrichment-api



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/blackstack-enrichment.rb', line 17

def find_person_from_linkedin_url(url:)
    raise 'Error: apollo_apikey is required for find_person_from_linkedin_url operation.' if @apollo_apikey.nil?

    ret = `curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
        "api_key": "#{@apollo_apikey}",
        "reveal_personal_emails": true,
        "details": [
            {
                "linkedin_url": "#{url}"
            }
        ]
    }' "https://api.apollo.io/api/v1/people/bulk_match"`
    j = JSON.parse(ret)
    raise "Error: #{j['error']}" if j['error']
    raise "Error: #{j['error_message']}" if j['error_message']
    raise "Error: #{j['error_code']}" if j['error_code']
    match = j['matches'].first
    return nil if match.nil?
    match['email']
end

#find_person_from_name_and_company(name:, company:) ⇒ Object

Retrieve the email of a person from his name and company.

Reference: apolloio.github.io/apollo-api-docs/?shell#enrichment-api



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/blackstack-enrichment.rb', line 43

def find_person_from_name_and_company(name:, company:)
    raise 'Error: apollo_apikey is required for find_person_from_linkedin_url operation.' if @apollo_apikey.nil?

    ret = `curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
        "api_key": "#{@apollo_apikey}",
        "reveal_personal_emails": true,
        "details": [
            {
                "name": "#{name}",
                "organization_name": "#{company}"
            }
        ]
    }' "https://api.apollo.io/api/v1/people/bulk_match"`
    j = JSON.parse(ret)
    raise "Error: #{j['error_message']}" if j['error_message']
    raise "Error: #{j['error_code']}" if j['error_code']
    match = j['matches'].first
    return nil if match.nil?
    match['email']
end

#find_person_from_name_and_domain(name:, domain:) ⇒ Object

Retrieve the email of a person from his name and company.

Reference: apolloio.github.io/apollo-api-docs/?shell#enrichment-api



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/blackstack-enrichment.rb', line 69

def find_person_from_name_and_domain(name:, domain:)
    raise 'Error: apollo_apikey or findymail_apikey are required for find_person_from_linkedin_url operation.' if @apollo_apikey.nil? && @findymail_apikey.nil?

    if @findymail_apikey
        ret = `curl --request POST \
            "https://app.findymail.com/api/search/name" \
            --header "Authorization: Bearer #{@findymail_apikey}" \
            --header "Content-Type: application/json" \
            --header "Accept: application/json" \
            --data "{
                \\"name\\": \\"#{name}\\",
                \\"domain\\": \\"#{domain}\\"
            }"`
        j = JSON.parse(ret)
        raise "Error: #{j['error']}" if j['error']
        return nil if j['contact'].nil?
        return j['contact']['email']
    elsif @apollo_apikey
        ret = `curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
            "api_key": "#{@apollo_apikey}",
            "reveal_personal_emails": true,
            "details": [
                {
                    "name": "#{name}",
                    "domain": "#{domain}"
                }
            ]
        }' "https://api.apollo.io/api/v1/people/bulk_match"`
        j = JSON.parse(ret)
        raise "Error: #{j['error_message']}" if j['error_message']
        raise "Error: #{j['error_code']}" if j['error_code']
        match = j['matches'].first
        return nil if match.nil?
        return match['email']
    end
end