{% autoescape None %}
<!doctype html>
<html>
	<head>
		<link rel="stylesheet" href="{{ Env.get('static_path') }}style/api.css" type="text/css">
		<title>API documentation</title>
	</head>
	<body>

		<h1>CouchPotato API Documentation</h1>
		<div class="api">
			You can access the API via <pre>{{ Env.get('api_base') }}</pre>
			To see it in action, have a look at the webinterface with Firebug (on firefox) or the development tools included in Chrome.
			All the data that you see there are from the API.
			<br />
			<br />
			A normal API call:
			<pre><a href="{{ Env.get('api_base') }}updater.info/">{{ Env.get('api_base') }}updater.info/</a></pre>
			<br />
			You can also use the API over another domain using JSONP, the callback function should be in 'callback_func'
			<pre><a href="{{ Env.get('api_base') }}updater.info/?callback_func=myfunction">{{ Env.get('api_base') }}updater.info/?callback_func=myfunction</a></pre>
			<br />
			<br />
			Get the API key:
			<pre><a href="{{ Env.get('web_base') }}getkey/?p=md5(password)&amp;u=md5(username)">{{ Env.get('web_base') }}getkey/?p=md5(password)&amp;u=md5(username)</a></pre>
			Will return {"api_key": "XXXXXXXXXX", "success": true}. When username or password is empty you don't need to md5 it.
			<br />
		</div>

		{% 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" cellspacing="0" cellpadding="0">
				{% 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>
				{% end %}
				</table>
				{% end %}

				{% 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', '') }}</pre>
					</div>
					{% end %}
				</div>
				{% end %}
			</div>
			{% end %}
		{% end %}

		<div class="missing">
			<h1>Missing documentation</h1>
			{{', '.join(api_docs_missing)}}
		</div>

	</body>
</html>
