This is a simple client used to access the MySpace Apps REST APIs.
This project includes a modified version of the python oauth code (originally found at http://oauth.googlecode.com/svn/code/python/oauth/). The included version has been modified to run on python 2.4 and fixes a couple issues when working with the myspace urls.
Note: This library depends on the simplejson library (http://pypi.python.org/pypi/simplejson). Developed against version 1.7.3.
Usage:
from myspace.app import Consumer, MySpaceError
security_key = '...'
consumer = Consumer('http://example.com', security_key)
try:
user = consumer.user(user_id)
except MySpaceError, mse:
# handle error
print mse
print mse.responseApp data: Storage and retrieval of data from the MySpace persistent data store.
## Obtaining a handle on the data store # retrieving the global app data store reference globaldata = consumer.appdata() # retrieving user app data store reference appdata = consumer.appdata(user_id) ## Once you have a handle on the data store you can access ## and update values like any other dictionary # accessing values appdata['mykey'] # updating values appdata['mykey'] = myvalue ## Persisting changes: any updates you make ## to the data need to be explicitly saved. appdata.save() ## Accessing app data for a user's friends friend_appdata = consumer.appdata(user_id) friend_appdata[friend_id]['mykey'] friend_appdata[friend_id]['mykey'] = myvalue friend_appdata[friend_id].save()
Django: This project also includes some code to ease usage in django.
- Middleware class allowing you to access the current user (viewer) and pre-initialized consumer.
def myview (request): # current user request.myspace.user # another user request.myspace.consumer.user(123456) ...
- Decorator to validate signed requests
from myspace.djangoms.decorators import signed_required @signed_required def myview (request): ...
- Decorator to validate that user has the app installed
from myspace.djangoms.decorators import has_app @has_app def myview (request): ...