Skip to content

Instantly share code, notes, and snippets.

@dwilkie
Created November 28, 2018 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwilkie/dcd0b8711852fea317cecf78f2eacae3 to your computer and use it in GitHub Desktop.
Save dwilkie/dcd0b8711852fea317cecf78f2eacae3 to your computer and use it in GitHub Desktop.
SCFM Modify Contacts
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