Last active
February 8, 2019 15:24
-
-
Save samschirmer/382c13e2adcb6a5b1b55af85f96eeb32 to your computer and use it in GitHub Desktop.
CLI script that accepts email addresses as arguments and parses a CSV of account names/api keys to returns matches within associated Hatchbuck accounts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'httparty' | |
# pulling csv into array so it only needs to be read once | |
accounts = CSV.open('./keys.csv', headers: :first_row, header_converters: :symbol) { |f| f.map(&:to_h) } | |
matches = Array.new | |
ARGV.each do |email| | |
accounts.each do |a| | |
payload = { emails: [ address: email ] }.to_json | |
res = HTTParty.post( | |
"https://api.hatchbuck.com/api/v1/contact/search?api_key=#{ a[:key] }", | |
headers: { 'Content-Type' => 'application/json' }, | |
body: payload | |
) | |
matches.push({ email: email, account: a[:name] }) if res.code == 200 | |
end | |
end | |
matches.each { |m| puts "#{ m[:email] }: #{ m[:account] }" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment