11 changed files with 280 additions and 22 deletions
@ -1,21 +1,30 @@ |
|||
from couchpotato.core.helpers.request import jsonified |
|||
from flask.blueprints import Blueprint |
|||
from flask.templating import render_template |
|||
|
|||
api = Blueprint('api', __name__) |
|||
api_docs = {} |
|||
api_docs_missing = [] |
|||
|
|||
def addApiView(route, func, static = False): |
|||
api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '-') if route else 'index', view_func = func) |
|||
def addApiView(route, func, static = False, docs = None): |
|||
api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '::') if route else 'index', view_func = func) |
|||
if docs: |
|||
api_docs[route[4:] if route[0:4] == 'api.' else route] = docs |
|||
else: |
|||
api_docs_missing.append(route) |
|||
|
|||
""" Api view """ |
|||
def index(): |
|||
from couchpotato import app |
|||
|
|||
from couchpotato import app |
|||
routes = [] |
|||
for route, x in sorted(app.view_functions.iteritems()): |
|||
if route[0:4] == 'api.': |
|||
routes += [route[4:]] |
|||
routes += [route[4:].replace('::', '.')] |
|||
|
|||
return jsonified({'routes': routes}) |
|||
if api_docs.get(''): |
|||
del api_docs[''] |
|||
del api_docs_missing[''] |
|||
return render_template('api.html', routes = sorted(routes), api_docs = api_docs, api_docs_missing = sorted(api_docs_missing)) |
|||
|
|||
addApiView('', index) |
|||
addApiView('default', index) |
|||
|
@ -0,0 +1,75 @@ |
|||
html { |
|||
font-size: 12px; |
|||
line-height: 1.5; |
|||
font-family: "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif; |
|||
font-size: 14px; |
|||
} |
|||
|
|||
h1, h2, h3, h4, h5 { |
|||
clear: both; |
|||
padding: 0; |
|||
margin: 0; |
|||
font-size: 14px; |
|||
} |
|||
|
|||
h1 { |
|||
font-size: 25px; |
|||
} |
|||
|
|||
h2 { |
|||
font-size: 20px; |
|||
} |
|||
|
|||
pre { |
|||
background: #ccc; |
|||
font-family: monospace; |
|||
margin: 0; |
|||
padding: 2%; |
|||
width: 96%; |
|||
display: block; |
|||
} |
|||
|
|||
.api { |
|||
margin-bottom: 20px; |
|||
overflow: hidden; |
|||
} |
|||
|
|||
.api .description { |
|||
color: #333; |
|||
padding: 0 0 5px; |
|||
} |
|||
|
|||
.api .params { |
|||
background: #f5f5f5; |
|||
width: 100%; |
|||
} |
|||
.api h3 { |
|||
clear: both; |
|||
float: left; |
|||
width: 100px; |
|||
} |
|||
|
|||
.api .params { |
|||
float: left; |
|||
width: 700px; |
|||
} |
|||
|
|||
.api .params .param { |
|||
vertical-align: top; |
|||
} |
|||
|
|||
.api .params .param th { |
|||
text-align: left; |
|||
width: 100px; |
|||
} |
|||
|
|||
.api .param .type { |
|||
font-style: italic; |
|||
margin-right: 10px; |
|||
width: 100px; |
|||
} |
|||
|
|||
.api .return { |
|||
float: left; |
|||
width: 700px; |
|||
} |
@ -0,0 +1,49 @@ |
|||
<!doctype html> |
|||
<html> |
|||
<head> |
|||
<link rel="stylesheet" href="{{ url_for('web.static', filename='style/api.css') }}" type="text/css"> |
|||
<title>API documentation</title> |
|||
</head> |
|||
<body> |
|||
|
|||
<h1>API</h1> |
|||
{% for route in routes %} |
|||
{% if api_docs.get(route) %} |
|||
<div class="api"> |
|||
<h2>{{route}}</h2> |
|||
<div class="description">{{api_docs[route].get('desc', '')}}</div> |
|||
|
|||
{% if api_docs[route].get('params') %} |
|||
<h3>Params</h3> |
|||
<table class="params"> |
|||
{% for param in api_docs[route]['params'] %} |
|||
<tr class="param"> |
|||
<th>{{param}}</th> |
|||
<td class="type">{{ api_docs[route]['params'][param].get('type', 'string') }}</td> |
|||
<td class="description">{{ api_docs[route]['params'][param]['desc'] }}</td> |
|||
</tr> |
|||
{% endfor %} |
|||
</table> |
|||
{% endif %} |
|||
|
|||
{% if api_docs[route].get('return') %} |
|||
<h3>Return</h3> |
|||
<div class="return"> |
|||
<div class="type">{{ api_docs[route]['return'].get('type', '{"success": True}') }}</div> |
|||
{% if api_docs[route]['return'].get('example') %} |
|||
<div class="example"> |
|||
<h4>Example</h4> |
|||
<pre>{{ api_docs[route]['return'].get('example', '')|safe }}</pre> |
|||
</div> |
|||
{% endif %} |
|||
</div> |
|||
{% endif %} |
|||
</div> |
|||
{% endif %} |
|||
{% endfor %} |
|||
|
|||
<h1>Missing documentation</h1> |
|||
<div class="missing">{{', '.join(api_docs_missing)}}</div> |
|||
|
|||
</body> |
|||
</html> |
Loading…
Reference in new issue