Created
November 10, 2018 03:45
-
-
Save dwilkie/17ba7fbc8d97a513906bc1ad85a9ac64 to your computer and use it in GitHub Desktop.
SCFM contact import (Africa's Voices)
This file contains hidden or 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
require "csv" | |
require "httparty" | |
DATA_FILE = "tmp/maap_numbers.csv".freeze | |
API_ENDPOINT = "https://scfm.somleng.org/api/contact_data".freeze | |
API_KEY = "REPLACE_ME_WITH_SCFM_API_KEY".freeze | |
def create_contact!(row) | |
response = HTTParty.post( | |
API_ENDPOINT, | |
body: { | |
msisdn: row.fetch("tel"), | |
metadata: { | |
"retailer" => row.fetch("retailer"), | |
"district" => row.fetch("district"), | |
"scope_id" => row.fetch("scope_id"), | |
"location" => row.fetch("recipient_location") | |
} | |
}, | |
basic_auth: { username: API_KEY } | |
) | |
raise("Invalid Response #{response}") unless response.success? | |
end | |
csv_text = File.read(DATA_FILE) | |
csv = CSV.parse(csv_text, headers: true) | |
rows = [] | |
csv.each do |row| | |
create_contact!(row) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment