Last active
August 29, 2015 14:12
-
-
Save ewilliam/66a63e86bd0cd094cd21 to your computer and use it in GitHub Desktop.
congress email sending. sendgrid not in yet
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
$(document).ready(function(){ | |
$("a.send").click(function() { | |
$address = $("#addy").val(); | |
$apiUrl = "https://congress.api.sunlightfoundation.com/legislators/locate?zip=" + $address | |
$.ajax({ | |
url: 'https://congress.api.sunlightfoundation.com/legislators/locate?zip=92506', // can't use apiUrl variable? | |
data: { | |
format: 'json', | |
apikey: 'xxxx' // use env variable | |
}, | |
error: function() { | |
$('.letter-form').html('<p>An error has occurred</p>'); | |
}, | |
dataType: 'jsonp', | |
success: function(data) { | |
var $congressPeople = data.results | |
var $emailList = $.map($congressPeople, function(obj, i) { | |
return obj.oc_email | |
}); | |
var $nameList = $congressPeople.map(function(obj, i) { | |
return " " + obj.first_name + " " + obj.last_name | |
}); | |
$('.letter-form') | |
.append('<h3>You have sent email to the following congresspeople:</h3>') | |
.append($('<p>').text($nameList)); | |
}, | |
type: 'GET' | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Neat!!