Skip to content

Instantly share code, notes, and snippets.

@domoritz
Created June 30, 2012 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domoritz/3025724 to your computer and use it in GitHub Desktop.
Save domoritz/3025724 to your computer and use it in GitHub Desktop.
PopIt Python bindings
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from popit import build_popit_api
from pprint import pprint
api = build_popit_api(instance = 'professors', user = 'your email', password = 'your password')
# Create
print("CREATE")
new = api.person.post({'name': 'Albert Keinstein'})
pprint(new)
id = new['result']['_id']
# Update
print("UPDATE")
result = api.person(id).put({"name": "Albert Einstein"})
pprint(result)
# Read
print("READ")
result = api.person(id).get()
pprint(result)
# Delete
print("DELETE")
result = api.person(id).delete()
pprint(result)
# META
print("META")
pprint(api.get())
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import slumber
def build_popit_api(instance = 'www', hostname = 'popit.mysociety.org', port = 80, api_version = 'v1', user = None, password = None):
url = 'http://' + '/'.join([instance.strip('/')+'.'+hostname.strip('/')+':'+str(port), 'api'])
slumber_api = slumber.API(url, auth=(user, password))
api = getattr(slumber_api, api_version)()
return api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment