Skip to content

Instantly share code, notes, and snippets.

@samschirmer
Last active February 8, 2019 15:24
Show Gist options
  • Save samschirmer/382c13e2adcb6a5b1b55af85f96eeb32 to your computer and use it in GitHub Desktop.
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.
#!/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