k4ever/k4ever/api2/urls.py

61 lines
2.4 KiB
Python

from django.conf.urls.defaults import *
from piston.resource import Resource
from piston.authentication import HttpBasicAuthentication
from api2.authentication import DjangoAuthentication, MultiAuthentication
from api2.handlers import *
from api2.decorators import fix_mime
import piston.utils
# piston does not understand mimetypes with charsets, HACK: fix content_type
piston.utils.Mimer.content_type = fix_mime(piston.utils.Mimer.content_type)
class CsrfExemptResource(Resource):
""" Except a :class:`Resource` from djangos CSRF-Framework.
This idea is taken from
http://www.robertshady.com/content/creating-very-basic-api-using-python-django-and-piston
"""
def __init__(self, handler, authentication = None):
super( CsrfExemptResource, self ).__init__( handler, authentication )
self.csrf_exempt = getattr( self.handler, 'csrf_exempt', True )
# build authenticatiooors
basicAuth = HttpBasicAuthentication(realm="Freitagsrundenkassensystemapi")
djangoAuth = DjangoAuthentication()
multiAuth = MultiAuthentication([basicAuth, djangoAuth])
ad = {'authentication': multiAuth}
buyableItemRes = CsrfExemptResource(handler=BuyableItemHandler, **ad)
buyableTypeRes = CsrfExemptResource(handler=BuyableTypeHandler, **ad)
historyRes = CsrfExemptResource(handler=HistoryHandler, **ad)
transactionTransactRes = CsrfExemptResource(handler=TransactionTransactHandler, **ad)
transactionTypeRes = CsrfExemptResource(handler=TransactionTypeHandler, **ad)
transactionVirtualRes = CsrfExemptResource(handler=TransactionVirtualHandler, **ad)
accountBalanceRes = CsrfExemptResource(handler=AccountBalanceHandler, **ad)
authBlobRes = CsrfExemptResource(handler=AuthBlobHandler, **ad)
authUserRes = CsrfExemptResource(handler=AuthUserHandler, **ad)
configRes = CsrfExemptResource(handler=ConfigHandler, **ad)
urlpatterns = patterns('',
url(r'buyable/item/?$', buyableItemRes),
url(r'buyable/item/(?P<itemId>\d+)/?$', buyableItemRes),
url(r'buyable/item/bulkbuy/?$', buyableItemRes, {'bulkBuy': True}),
url(r'buyable/types/?$', buyableTypeRes),
url(r'buyable/history/?$', historyRes),
url(r'account/transactions/transact/?$', transactionTransactRes),
url(r'account/transactions/types/?$', transactionTypeRes),
url(r'account/transactions/virtual/?$', transactionVirtualRes),
url(r'account/balance/?$', accountBalanceRes),
url(r'auth/blob/?$', authBlobRes),
url(r'auth/user/?$', authUserRes),
url(r'config/?$', configRes),
)