Skip to content

Instantly share code, notes, and snippets.

@ewilliam
Last active August 29, 2015 14:12
Show Gist options
  • Save ewilliam/66a63e86bd0cd094cd21 to your computer and use it in GitHub Desktop.
Save ewilliam/66a63e86bd0cd094cd21 to your computer and use it in GitHub Desktop.
congress email sending. sendgrid not in yet
$(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'
});
});
});
@mbernier
Copy link

mbernier commented Jan 6, 2015

Neat!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment