Class: ApolloClient
- Inherits:
-
Object
- Object
- ApolloClient
- Defined in:
- lib/apollo-client.rb
Overview
module BlackStack
Constant Summary collapse
- @@apollo_apikey =
nil
Instance Method Summary collapse
-
#find_person_from_linkedin_url(url:) ⇒ Object
Retrieve the email of a person from a LinkedIn URL.
-
#find_person_from_name_and_company(name:, company:) ⇒ Object
Retrieve the email of a person from his name and company.
-
#find_person_from_name_and_domain(name:, domain:) ⇒ Object
Retrieve the email of a person from his name and company.
-
#find_persons_from_title_and_domain(titles:, domain:, limit: 1, calls_delay: 1) ⇒ Object
Retrieve the name, job position and email of a person from a list of allowed titles and company domain.
-
#initialize(h = {}) ⇒ ApolloClient
constructor
A new instance of ApolloClient.
Constructor Details
#initialize(h = {}) ⇒ ApolloClient
Returns a new instance of ApolloClient.
7 8 9 10 |
# File 'lib/apollo-client.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/apollo-client.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_message']}" if j['error_message'] raise "Error: #{j['error_code']}" if j['error_code'] raise "Error: #{j['error']}" if j['error'] 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 63 |
# File 'lib/apollo-client.rb', line 43 def find_person_from_name_and_company(name:, company:) raise 'Error: apollo_apikey is required for find_person_from_name_and_company 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'] raise "Error: #{j['error']}" if j['error'] 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
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 105 106 |
# File 'lib/apollo-client.rb', line 70 def find_person_from_name_and_domain(name:, domain:) raise 'Error: apollo_apikey or findymail_apikey are required for find_person_from_name_and_domain 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'] raise "Error: #{j['error']}" if j['error'] match = j['matches'].first return nil if match.nil? return match['email'] end end |
#find_persons_from_title_and_domain(titles:, domain:, limit: 1, calls_delay: 1) ⇒ Object
Retrieve the name, job position and email of a person from a list of allowed titles and company domain.
Reference: apolloio.github.io/apollo-api-docs/?shell#people-api
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/apollo-client.rb', line 113 def find_persons_from_title_and_domain(titles:, domain:, limit: 1, calls_delay: 1) raise 'Error: apollo_apikey is required for find_persons_from_title_and_domain operation.' if @apollo_apikey.nil? b = [] # search leads s = "curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -d '{ \"api_key\": \"#{@apollo_apikey}\", \"page\" : 1, \"per_page\": #{limit.to_s}, \"person_titles\": [\"#{titles.join('", "')}\"], \"q_organization_domains\": \"#{domain}\", \"contact_email_status\": [\"verified\"] }' \"https://api.apollo.io/v1/mixed_people/search\"" ret = `#{s}` j = JSON.parse(ret) raise "Error: #{j['error_message']}" if j['error_message'] raise "Error: #{j['error_message']}" if j['error_message'] raise "Error: #{j['error']}" if j['error'] a = j['people'] return ret if a.nil? a.each { |h| # add delay to don't oberload the API sleep calls_delay i = {} i['id'] = h['id'] i['first_name'] = h['first_name'] i['last_name'] = h['last_name'] i['title'] = h['title'] i['linkedin_url'] = h['linkedin_url'] i['facebook_url'] = h['facebook_url'] # find the email of the lead s = "curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -d '{ \"api_key\": \"#{@apollo_apikey}\", \"reveal_personal_emails\": true, \"id\": \"#{i['id']}\" }' \"https://api.apollo.io/v1/people/match\"" ret = `#{s}` j = JSON.parse(ret) raise "Error: #{j['error_message']}" if j['error_message'] raise "Error: #{j['error_code']}" if j['error_code'] raise "Error: #{j['error']}" if j['error'] next if j['person'].nil? k = j['person'] if j['person'] # append emails and phone numbers to the hash i['emails'] = [] i['emails'] << k['email'] if k['email'] i['emails'] += k['personal_emails'] if k['personal_emails'] i['phone_numbers'] = [] i['phone_numbers'] = k['phone_numbers'].map { |o| { 'value' => o['raw_number'], 'type' => o['type'] } } if k['phone_numbers'] i['raw'] = k b << i } # return b end |