Skip to content

Instantly share code, notes, and snippets.

@codebutler
Created August 29, 2010 10:06
Show Gist options
  • Select an option

  • Save codebutler/556172 to your computer and use it in GitHub Desktop.

Select an option

Save codebutler/556172 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import urllib
import hashlib
import hmac
import json
URL = 'http://stumble.to/api/update'
API_KEY = 'YOUR_KEY_GOES_HERE'
API_SECRET = 'YOUR_SECRET_GOES_HERE'
devices = [
{ 'identifier': 'MYSHOE', 'type': 'shoe' },
{ 'identifier': '00:00:00:00:00:00', 'type': 'wifi' }
]
params = {
'api_key': API_KEY,
'devices': json.dumps(devices)
}
msg = []
for k, v in sorted(params.iteritems()):
msg.append('%s=%s' % (k, urllib.quote_plus(v)))
msg = '&'.join(msg)
hmac = hmac.new(API_SECRET, msg, hashlib.sha512)
params['signature'] = hmac.hexdigest()
params = urllib.urlencode(params)
f = urllib.urlopen(URL, params)
print f.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment