Created
November 28, 2018 09:15
-
-
Save dwilkie/dcd0b8711852fea317cecf78f2eacae3 to your computer and use it in GitHub Desktop.
SCFM Modify Contacts
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
require "csv" | |
require "httparty" | |
DATA_FILE = "tmp/phone_test.csv".freeze | |
API_ENDPOINT = "https://scfm.somleng.org/api/contact_data".freeze | |
API_KEY = "REPLACE_ME".freeze | |
def update_contact!(row) | |
response = HTTParty.post( | |
API_ENDPOINT, | |
body: { | |
msisdn: row.fetch("URN:tel"), | |
metadata: { | |
"CHANGE_ME" => true | |
} | |
}, | |
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) | |
csv.each do |row| | |
update_contact!(row) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment