Update the app API class methods, register the sources app main endpoint, add API doc strings
This commit is contained in:
@@ -2,25 +2,14 @@ from __future__ import absolute_import
|
||||
|
||||
from django.conf.urls import include, patterns, url
|
||||
|
||||
#from .classes import EndPoint
|
||||
from .views import APIBase, Version_0, EndPointView
|
||||
from .views import APIBase, Version_0, APIAppView
|
||||
|
||||
version_0_endpoints_urlpatterns = patterns('',
|
||||
version_0_urlpatterns = patterns('',
|
||||
url(r'^$', Version_0.as_view(), name='api-version-0'),
|
||||
url(r'^(?P<endpoint_name>\w+)$', EndPointView.as_view(), name='api-version-0-endpoint'),
|
||||
url(r'^(?P<app_name>\w+)$', APIAppView.as_view(), name='api-version-0-app'),
|
||||
)
|
||||
|
||||
"""
|
||||
for endpoint in EndPoint.get_all():
|
||||
endpoint_urlpatterns = patterns('')
|
||||
|
||||
for service in endpoint.services:
|
||||
endpoint_urlpatterns += patterns('', service['urlpattern'])
|
||||
|
||||
version_0_endpoints_urlpatterns += patterns('', url(r'^%s/' % endpoint.name, include(endpoint_urlpatterns)))
|
||||
"""
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', APIBase.as_view(), name='api-root'),
|
||||
url(r'^v0/', include(version_0_endpoints_urlpatterns)),
|
||||
url(r'^v0/', include(version_0_urlpatterns)),
|
||||
)
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user