Last active
December 28, 2015 22:29
-
-
Save bcherny/7571653 to your computer and use it in GitHub Desktop.
Sample CURL API request for contributor.io.
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
getCounts = (identities, callback) -> | |
encoded = '' | |
# encode identities | |
for key, identity of identities | |
encoded += "#{if encoded then '&' else ''}#{key}=#{identity}" | |
xhr = new XMLHttpRequest | |
url = "http://www.contributor.io/api?#{encoded}" | |
xhr.onreadystatechange = -> | |
if req.readyState is 4 | |
response = xhr.responseText | |
status = xhr.status | |
if status < 400 | |
callback JSON.parse response | |
else | |
throw new Error response | |
# send request | |
xhr.open url | |
do xhr.send | |
getCounts | |
github: 'eighttrackmind' | |
npm: 'bcherny' | |
, (counts) -> | |
console.log counts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment