Created
February 19, 2015 19:11
-
-
Save jcarbaugh/096db3b233da2529a5d6 to your computer and use it in GitHub Desktop.
Tweet at the legislators that represent your ZIP code
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
<!doctype html> | |
<!-- | |
Replace YOUR-API-KEY-HERE with your API key. | |
Register for a key at http://sunlightfoundation.com/api/ | |
--> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Tweet at Congress</title> | |
</head> | |
<body> | |
<form id="tweet-form"> | |
<label for="zipcode-input">ZIP code</label> | |
<input type="text" name="zipcode" id="zipcode-input" value="20877"> | |
<button>Tweet your Legislators</button> | |
</form> | |
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<script> | |
$("#tweet-form").submit(function(ev) { | |
ev.preventDefault(); | |
var params = { | |
zip: $("input[name=zipcode]").val(), | |
apikey: "YOUR-API-KEY-HERE" | |
}; | |
var apiUrl = "https://congress.api.sunlightfoundation.com/legislators/locate"; | |
$.getJSON(apiUrl, params, function(data) { | |
var text = data.results.reduce(function(prev, item) { | |
return item.twitter_id ? prev + "@" + item.twitter_id + " " : prev; | |
}, "."); | |
var url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(text); | |
window.location = url; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is perfect, thanks so much!