Update the app API class methods, register the sources app main endpoint, add API doc strings

This commit is contained in:
Roberto Rosario
2014-07-08 18:51:39 -04:00
parent c4174f8020
commit 909dd582df
6 changed files with 56 additions and 43 deletions

View File

@@ -10,7 +10,7 @@ from rest_framework.generics import RetrieveAPIView
from rest_framework.response import Response
from rest_framework.reverse import reverse
from .classes import EndPoint
from .classes import APIEndPoint
logger = logging.getLogger(__name__)
@@ -19,6 +19,10 @@ registered_version_0_endpoints = [
class APIBase(generics.GenericAPIView):
"""
Main entry point of the API.
"""
def get(self, request, format=None):
return Response([
{'name': 'Version 0', 'url': reverse('api-version-0', request=request, format=format)}
@@ -26,27 +30,35 @@ class APIBase(generics.GenericAPIView):
class Version_0(generics.GenericAPIView):
"""
API version 0 entry points.
"""
def get(self, request, format=None):
return Response({
'endpoints': [
{'name': unicode(endpoint), 'url': reverse('api-version-0-endpoint', args=[unicode(endpoint)], request=request, format=format)} for endpoint in EndPoint.get_all()
'apps': [
{'name': unicode(endpoint), 'url': reverse('api-version-0-app', args=[unicode(endpoint)], request=request, format=format)} for endpoint in APIEndPoint.get_all()
],
})
class EndPointView(generics.GenericAPIView):
def get(self, request, endpoint_name, format=None):
class APIAppView(generics.GenericAPIView):
"""
Entry points of the selected app.
"""
def get(self, request, app_name, format=None):
result = []
endpoint = EndPoint.get(endpoint_name)
for service in endpoint.services:
api_app = APIEndPoint.get(app_name)
for endpoint in api_app.endpoints:
result.append(
{
'description': service['description'],
'name': service['urlpattern'].name,
'url': service['url'],
'description': endpoint['description'],
'url': reverse(endpoint['view_name'], request=request, format=format),
}
)
return Response({
'services': result
'endpoints': result
})