Created
June 30, 2012 22:08
-
-
Save domoritz/3025724 to your computer and use it in GitHub Desktop.
PopIt Python bindings
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
#!/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()) |
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
#!/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