Skip to content

Instantly share code, notes, and snippets.

@bcherny
Last active December 28, 2015 22:29
Show Gist options
  • Save bcherny/7571653 to your computer and use it in GitHub Desktop.
Save bcherny/7571653 to your computer and use it in GitHub Desktop.
Sample CURL API request for contributor.io.
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