2012-04-13 11:24:57 +02:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) and Chrome Frame -->
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
<title> {{ apiName }} </title>
<style type="text/css">
{{ css | raw }}
</style>
2012-07-18 12:52:56 +02:00
<script type="text/javascript">
{{ js | raw }}
</script>
2012-04-13 11:24:57 +02:00
</head>
<body>
<div id="header">
2013-06-13 12:05:01 +02:00
<a href=" {{ path ( 'nelmio_api_doc_index' ) }} "><h1> {{ apiName }} </h1></a>
2014-05-14 22:05:03 +02:00
{% if enableSandbox %}
<div id="sandbox_configuration">
2014-05-21 15:59:55 +02:00
{% if bodyFormats | length > 0 %}
2014-05-14 22:05:03 +02:00
body format:
<select id="body_format">
2014-05-21 15:59:55 +02:00
{% if 'form' in bodyFormats %} <option value="form" {{ defaultBodyFormat == 'form' ? ' selected' : '' }} >Form Data</option> {% endif %}
{% if 'json' in bodyFormats %} <option value="json" {{ defaultBodyFormat == 'json' ? ' selected' : '' }} >JSON</option> {% endif %}
2014-05-14 22:05:03 +02:00
</select>
2014-05-21 15:59:55 +02:00
{% endif %}
2014-08-21 22:44:19 +02:00
{% if requestFormats | length > 0 %}
2014-05-14 22:05:03 +02:00
request format:
<select id="request_format">
2014-05-17 22:45:30 +02:00
{% for format , header in requestFormats %}
<option value=" {{ header }} " {{ defaultRequestFormat == format ? ' selected' : '' }} > {{ format }} </option>
{% endfor %}
2014-08-21 04:43:44 +02:00
{% endif %}
2014-05-14 22:05:03 +02:00
</select>
2014-07-25 12:08:00 +02:00
{% if authentication %}
{% if authentication .delivery == 'http' and authentication .type == 'basic' %}
api login: <input type="text" id="api_login" value=""/>
api password: <input type="text" id="api_pass" value=""/>
{% elseif authentication .delivery in [ 'query' , 'http' , 'header' ] %}
api key: <input type="text" id="api_key" value=""/>
{% endif %}
{% if authentication .custom_endpoint %}
api endpoint: <input type="text" id="api_endpoint" value=""/>
{% endif %}
2014-08-23 12:24:50 +01:00
<button id="save_api_auth" type="button">Save</button>
<button id="clear_api_auth" type="button">Clear</button>
2014-05-14 22:05:03 +02:00
{% endif %}
</div>
{% endif %}
2012-08-10 13:55:35 +02:00
<br style="clear: both;" />
2012-04-13 11:24:57 +02:00
</div>
2013-04-08 11:44:43 +02:00
{% include motdTemplate %}
2012-04-13 11:24:57 +02:00
<div class="container" id="resources_container">
<ul id="resources">
{% block content %} {% endblock %}
</ul>
</div>
<p id="colophon">
Documentation auto-generated on {{ date }}
</p>
<script type="text/javascript">
2013-09-05 19:04:17 +02:00
2014-05-18 01:24:52 +02:00
var getHash = function() {
return window.location.hash || '';
};
var setHash = function(hash) {
window.location.hash = hash;
};
var clearHash = function() {
var scrollTop, scrollLeft;
if(typeof history === 'object' && typeof history.pushState === 'function') {
history.replaceState('', document.title, window.location.pathname + window.location.search);
} else {
scrollTop = document.body.scrollTop;
scrollLeft = document.body.scrollLeft;
setHash('');
document.body.scrollTop = scrollTop;
document.body.scrollLeft = scrollLeft;
}
};
2013-12-09 18:01:31 +01:00
$(window).load(function() {
2015-06-17 11:48:31 +02:00
var id = getHash().substr(1).replace( /([:\.\[\]\ { \}|])/g, "\\$1");
2013-12-09 18:01:31 +01:00
var elem = $('#' + id);
if (elem.length) {
setTimeout(function() {
$('body,html').scrollTop(elem.position().top);
});
2014-04-24 23:02:56 +02:00
elem.find('.toggler').click();
2014-08-23 16:57:40 +02:00
var section = elem.parents('.section').first();
if (section) {
section.addClass('active');
section.find('.section-list').slideDown('fast');
}
2013-09-05 19:04:17 +02:00
}
2014-08-23 12:24:50 +01:00
{% if enableSandbox %}
loadStoredAuthParams();
{% endif %}
2013-09-05 19:04:17 +02:00
});
2014-05-18 01:24:52 +02:00
$('.toggler').click(function(event) {
var contentContainer = $(this).next();
if(contentContainer.is(':visible')) {
clearHash();
} else {
2014-07-23 13:21:33 +02:00
setHash($(this).data('href'));
2014-05-18 01:24:52 +02:00
}
contentContainer.slideToggle('fast');
return false;
2012-04-13 11:24:57 +02:00
});
2012-05-24 01:22:45 +02:00
2014-08-23 16:57:40 +02:00
$('.action-show-hide, .section > h1').on('click', function() {
var section = $(this).parents('.section').first();
if (section.hasClass('active')) {
section.removeClass('active');
section.find('.section-list').slideUp('fast');
} else {
section.addClass('active');
section.find('.section-list').slideDown('fast');
}
});
$('.action-list').on('click', function() {
var section = $(this).parents('.section').first();
if (!section.hasClass('active')) {
section.addClass('active');
}
section.find('.section-list').slideDown('fast');
2014-09-05 11:40:06 +02:00
section.find('.operation > .content').slideUp('fast');
2014-08-23 16:57:40 +02:00
});
$('.action-expand').on('click', function() {
var section = $(this).parents('.section').first();
if (!section.hasClass('active')) {
section.addClass('active');
}
$(section).find('ul').slideDown('fast');
2014-09-05 11:40:06 +02:00
$(section).find('.operation > .content').slideDown('fast');
2014-08-23 16:57:40 +02:00
});
2012-07-18 13:18:26 +02:00
{% if enableSandbox %}
2014-08-23 12:24:50 +01:00
var getStoredValue, storeValue, deleteStoredValue;
var apiAuthKeys = ['api_key', 'api_login', 'api_pass', 'api_endpoint'];
2014-06-17 00:10:34 -04:00
2014-08-23 12:24:50 +01:00
if ('localStorage' in window) {
var buildKey = function (key) {
return 'nelmio_' + key;
}
getStoredValue = function (key) {
return localStorage.getItem(buildKey(key));
}
storeValue = function (key, value) {
localStorage.setItem(buildKey(key), value);
}
deleteStoredValue = function (key) {
localStorage.removeItem(buildKey(key));
}
2014-06-17 00:10:34 -04:00
} else {
2014-08-23 12:24:50 +01:00
getStoredValue = storeValue = deleteStoredValue = function () { };
2014-06-17 00:10:34 -04:00
}
2014-08-23 12:24:50 +01:00
var loadStoredAuthParams = function() {
$.each(apiAuthKeys, function(_, value) {
var elm = $('#' + value);
if (elm.length) {
elm.val(getStoredValue(value));
}
});
2014-06-17 00:10:34 -04:00
}
2014-08-23 12:24:50 +01:00
var setParameterType = function ($context,setType) {
// no 2nd argument, use default from parameters
if (typeof setType == "undefined") {
setType = $context.parent().attr("data-dataType");
$context.val(setType);
}
$context.parent().find('.value').remove();
var placeholder = "";
if ($context.parent().attr("data-dataType") != "" && typeof $context.parent().attr("data-dataType") != "undefined") {
placeholder += "[" + $context.parent().attr("data-dataType") + "] ";
}
if ($context.parent().attr("data-format") != "" && typeof $context.parent().attr("data-format") != "undefined") {
2016-03-18 21:23:22 +03:00
placeholder += $context.parent().attr("data-format");
2014-08-23 12:24:50 +01:00
}
if ($context.parent().attr("data-description") != "" && typeof $context.parent().attr("data-description") != "undefined") {
placeholder += $context.parent().attr("data-description");
} else {
placeholder += "Value";
}
switch(setType) {
case "boolean":
$('<select class="value"><option value=""></option><option value="1">True</option><option value="0">False</option></select>').insertAfter($context);
break;
case "file":
$('<input type="file" class="value" placeholder="'+ placeholder +'">').insertAfter($context);
break;
2016-01-08 20:34:15 +02:00
case "textarea":
$('<textarea class="value" placeholder="'+ placeholder +'" />').insertAfter($context);
break;
2014-08-23 12:24:50 +01:00
default:
$('<input type="text" class="value" placeholder="'+ placeholder +'">').insertAfter($context);
}
};
2014-06-17 00:10:34 -04:00
2012-07-18 13:18:26 +02:00
var toggleButtonText = function ($btn) {
2012-10-17 15:15:35 +04:00
if ($btn.text() === 'Default') {
$btn.text('Raw');
} else {
$btn.text('Default');
}
2012-07-18 13:18:26 +02:00
};
2012-06-28 10:37:35 +02:00
2012-07-18 13:18:26 +02:00
var renderRawBody = function ($container) {
2012-10-17 15:15:35 +04:00
var rawData, $btn;
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
rawData = $container.data('raw-response');
$btn = $container.parents('.pane').find('.to-raw');
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
$container.addClass('prettyprinted');
$container.html($('<div/>').text(rawData).html());
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
$btn.removeClass('to-raw');
$btn.addClass('to-prettify');
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
toggleButtonText($btn);
2012-07-18 13:18:26 +02:00
};
2012-06-28 10:37:35 +02:00
2012-07-18 13:18:26 +02:00
var renderPrettifiedBody = function ($container) {
2012-10-17 15:15:35 +04:00
var rawData, $btn;
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
rawData = $container.data('raw-response');
$btn = $container.parents('.pane').find('.to-prettify');
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
$container.removeClass('prettyprinted');
2015-03-29 14:37:06 +02:00
$container.html(attachCollapseMarker(prettifyResponse(rawData)));
2012-10-17 15:15:35 +04:00
prettyPrint && prettyPrint();
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
$btn.removeClass('to-prettify');
$btn.addClass('to-raw');
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
toggleButtonText($btn);
2012-07-18 13:18:26 +02:00
};
2012-06-28 10:37:35 +02:00
2013-06-05 18:51:01 -07:00
var unflattenDict = function (body) {
var found = true;
while(found) {
found = false;
for (var key in body) {
var okey;
var value = body[key];
var dictMatch = key.match(/^(.+)\[([^\]]+)\]$/);
if(dictMatch) {
found = true;
okey = dictMatch[1];
var subkey = dictMatch[2];
body[okey] = body[okey] || { };
body[okey][subkey] = value;
delete body[key];
} else {
body[key] = value;
}
}
}
return body;
2015-03-29 14:37:06 +02:00
};
2013-06-05 18:51:01 -07:00
2014-08-23 12:24:50 +01:00
$('#save_api_auth').click(function(event) {
$.each(apiAuthKeys, function(_, value) {
var elm = $('#' + value);
if (elm.length) {
storeValue(value, elm.val());
}
});
});
$('#clear_api_auth').click(function(event) {
$.each(apiAuthKeys, function(_, value) {
deleteStoredValue(value);
var elm = $('#' + value);
if (elm.length) {
elm.val('');
}
});
});
2012-07-18 13:18:26 +02:00
$('.tabs li').click(function() {
var contentGroup = $(this).parents('.content');
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
$('.pane.selected', contentGroup).removeClass('selected');
$('.pane.' + $(this).data('pane'), contentGroup).addClass('selected');
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
$('li', $(this).parent()).removeClass('selected');
$(this).addClass('selected');
});
2012-05-24 01:22:45 +02:00
2015-03-29 14:37:06 +02:00
var getJsonCollapseHtml = function(sectionOpenCharacter) {
var $toggler = $('<span>').addClass('json-collapse-section').
attr('data-section-open-character', sectionOpenCharacter).
append($('<span>').addClass('json-collapse-marker')
.html('▿')
).append(sectionOpenCharacter);
return $('<div>').append($toggler).html();
};
var attachCollapseMarker = function (prettifiedJsonString) {
prettifiedJsonString = prettifiedJsonString.replace(/(\ { |\[)\n/g, function(match, sectionOpenCharacter) {
return getJsonCollapseHtml(sectionOpenCharacter) + '<span class="json-collapse-content">\n';
});
2015-04-14 17:10:09 +02:00
return prettifiedJsonString.replace(/([^\[][\}\]],?)\n/g, '$1</span>\n');
2015-03-29 14:37:06 +02:00
};
2012-07-18 13:18:26 +02:00
var prettifyResponse = function(text) {
try {
var data = typeof text === 'string' ? JSON.parse(text) : text;
2012-10-17 15:15:35 +04:00
text = JSON.stringify(data, undefined, ' ');
2012-07-18 13:18:26 +02:00
} catch (err) {
}
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
// HTML encode the result
return $('<div>').text(text).html();
};
2012-05-24 01:22:45 +02:00
2014-08-26 12:29:16 +02:00
var displayFinalUrl = function(xhr, method, url, data, container) {
2016-03-17 16:09:47 +01:00
container.text(method + ' ' + getFinalUrl(method, url, data));
};
2014-08-26 12:29:16 +02:00
2016-03-17 16:09:47 +01:00
var displayRequestBody = function(method, data, container, header) {
if ('GET' != method && !jQuery.isEmptyObject(data) && data !== "" && data !== undefined) {
if (jQuery.type(data) !== 'string') {
data = decodeURIComponent(jQuery.param(data));
}
container.text(data);
container.show();
header.show();
} else {
container.hide();
header.hide();
}
2012-07-18 13:18:26 +02:00
};
2012-05-24 01:22:45 +02:00
2014-03-11 07:07:35 +07:00
var displayProfilerUrl = function(xhr, link, container) {
var profilerUrl = xhr.getResponseHeader('X-Debug-Token-Link');
if (profilerUrl) {
link.attr('href', profilerUrl);
container.show();
} else {
link.attr('href', '');
container.hide();
}
2016-03-17 16:09:47 +01:00
};
2014-03-11 07:07:35 +07:00
2012-07-18 13:18:26 +02:00
var displayResponseData = function(xhr, container) {
var data = xhr.responseText;
2012-06-28 10:37:35 +02:00
2012-07-18 13:18:26 +02:00
container.data('raw-response', data);
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
renderPrettifiedBody(container);
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
container.parents('.pane').find('.to-prettify').text('Raw');
container.parents('.pane').find('.to-raw').text('Raw');
};
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
var displayResponseHeaders = function(xhr, container) {
var text = xhr.status + ' ' + xhr.statusText + "\n\n";
text += xhr.getAllResponseHeaders();
2012-05-24 01:22:45 +02:00
2013-04-08 21:19:24 +01:00
container.text(text);
2012-07-18 13:18:26 +02:00
};
2012-05-24 01:22:45 +02:00
2016-03-17 16:09:47 +01:00
var displayCurl = function(method, url, headers, data, result_container) {
var escapeShell = function(param) {
param = "" + param;
return '"' + param.replace(/(["\s'$`\\])/g,'\\$1') + '"';
};
url = getFinalUrl(method, url, data);
var command = "curl";
command += " -X " + escapeShell(method);
if (method != "GET" && !jQuery.isEmptyObject(data) && data !== "" && data !== undefined) {
if (jQuery.type(data) !== 'string') {
data = decodeURIComponent(jQuery.param(data));
}
command += " -d " + escapeShell(data);
}
for (headerKey in headers) {
if (headers.hasOwnProperty(headerKey)) {
command += " -H " + escapeShell(headerKey + ': ' + headers[headerKey]);
}
}
command += " " + url;
result_container.text(command);
};
var getFinalUrl = function(method, url, data) {
if ('GET' == method && !jQuery.isEmptyObject(data)) {
var separator = url.indexOf('?') >= 0 ? '&' : '?';
url = url + separator + decodeURIComponent(jQuery.param(data));
}
return url;
};
var displayResponse = function(xhr, method, url, headers, data, result_container) {
2014-08-26 12:29:16 +02:00
displayFinalUrl(xhr, method, url, data, $('.url', result_container));
2016-03-17 16:09:47 +01:00
displayRequestBody(method, data, $('.request-body', result_container), $('.request-body-header', result_container));
2014-03-11 07:07:35 +07:00
displayProfilerUrl(xhr, $('.profiler-link', result_container), $('.profiler', result_container));
2012-07-18 13:18:26 +02:00
displayResponseData(xhr, $('.response', result_container));
displayResponseHeaders(xhr, $('.headers', result_container));
2016-03-17 16:09:47 +01:00
displayCurl(method, url, headers, data, $('.curl-command', result_container));
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
result_container.show();
2012-05-24 01:22:45 +02:00
};
2012-07-18 13:18:26 +02:00
$('.pane.sandbox form').submit(function() {
var url = $(this).attr('action'),
2014-10-26 12:28:50 +01:00
method = $('[name="header_method"]', this).val(),
2012-07-18 13:18:26 +02:00
self = this,
2012-10-16 23:41:16 +04:00
params = { },
2014-06-17 02:02:35 -04:00
formData = new FormData(),
2014-05-22 16:49:01 +00:00
doubledParams = { },
2012-07-18 13:18:26 +02:00
headers = { },
2012-10-17 15:15:35 +04:00
content = $(this).find('textarea.content').val(),
2012-07-18 13:18:26 +02:00
result_container = $('.result', $(this).parent());
2012-11-07 22:34:08 +01:00
if (method === 'ANY') {
method = 'POST';
}
2014-05-17 22:45:30 +02:00
// set requestFormat
2012-10-17 15:15:35 +04:00
var requestFormatMethod = ' {{ requestFormatMethod }} ';
if (requestFormatMethod == 'format_param') {
2014-05-17 22:45:30 +02:00
params['_format'] = $('#request_format option:selected').text();
2014-06-17 02:02:35 -04:00
formData.append('_format',$('#request_format option:selected').text());
2012-10-17 15:15:35 +04:00
} else if (requestFormatMethod == 'accept_header') {
2014-05-17 22:45:30 +02:00
headers['Accept'] = $('#request_format').val();
2012-10-16 23:41:16 +04:00
}
2013-06-04 15:30:07 -07:00
// set default bodyFormat
2014-05-21 15:59:55 +02:00
var bodyFormat = $('#body_format').val() || ' {{ defaultBodyFormat }} ';
2013-06-04 15:30:07 -07:00
if(!('Content-type' in headers)) {
2014-05-21 15:59:55 +02:00
if (bodyFormat == 'form') {
headers['Content-type'] = 'application/x-www-form-urlencoded';
} else {
headers['Content-type'] = 'application/json';
}
2013-06-04 15:30:07 -07:00
}
2013-06-03 19:11:42 -07:00
2014-06-17 02:02:35 -04:00
var hasFileTypes = false;
$('.parameters .tuple_type', $(this)).each(function() {
if ($(this).val() == 'file') {
hasFileTypes = true;
}
});
if (hasFileTypes && method != 'POST') {
alert("Sorry, you can only submit files via POST.");
return false;
}
2014-08-28 01:48:10 -04:00
if (hasFileTypes && bodyFormat != 'form') {
alert("Body Format must be set to 'Form Data' when utilizing file upload type parameters.\nYour current bodyFormat is '" + bodyFormat + "'. Change your BodyFormat or do not use file type\nparameters.");
return false;
}
2014-06-17 02:02:35 -04:00
if (hasFileTypes) {
// retrieve all the parameters to send for file upload
$('.parameters .tuple', $(this)).each(function() {
var key, value;
key = $('.key', $(this)).val();
if ($('.value', $(this)).attr('type') === 'file' ) {
value = $('.value', $(this)).prop('files')[0];
2016-04-08 15:26:31 +03:00
if(!value) {
value = new File([], '');
}
2014-06-17 02:02:35 -04:00
} else {
value = $('.value', $(this)).val();
}
if (value) {
formData.append(key,value);
}
});
}
2012-07-18 13:18:26 +02:00
// retrieve all the parameters to send
$('.parameters .tuple', $(this)).each(function() {
2012-10-17 15:15:35 +04:00
var key, value;
2012-07-18 13:18:26 +02:00
2012-10-17 15:15:35 +04:00
key = $('.key', $(this)).val();
value = $('.value', $(this)).val();
2012-07-18 13:18:26 +02:00
2012-10-17 15:15:35 +04:00
if (value) {
2014-05-22 16:49:01 +00:00
// temporary save all additional/doubled parameters
if (key in params) {
doubledParams[key] = value;
} else {
params[key] = value;
}
2012-10-17 15:15:35 +04:00
}
2012-07-18 13:18:26 +02:00
});
2012-05-24 01:22:45 +02:00
2014-06-17 02:02:35 -04:00
2012-07-18 13:18:26 +02:00
// retrieve the additional headers to send
$('.headers .tuple', $(this)).each(function() {
2012-10-17 15:15:35 +04:00
var key, value;
2012-05-24 01:22:45 +02:00
2012-10-17 15:15:35 +04:00
key = $('.key', $(this)).val();
value = $('.value', $(this)).val();
2012-06-28 10:37:35 +02:00
2012-10-17 15:15:35 +04:00
if (value) {
headers[key] = value;
}
2013-06-03 19:11:42 -07:00
2012-07-18 13:18:26 +02:00
});
// fix parameters in URL
for (var key in $.extend( { }, params)) {
if (url.indexOf(' { ' + key + '}') !== -1) {
2012-10-17 15:15:35 +04:00
url = url.replace(' { ' + key + '}', params[key]);
delete params[key];
2012-07-18 13:18:26 +02:00
}
};
2014-05-22 16:49:01 +00:00
// merge additional params back to real params object
if (!$.isEmptyObject(doubledParams)) {
$.extend(params, doubledParams);
}
// disable all the fiels and buttons
2012-07-18 13:18:26 +02:00
$('input, button', $(this)).attr('disabled', 'disabled');
2013-04-10 20:23:10 +02:00
// append the query authentication
2015-03-25 14:53:31 +02:00
var api_key_val = $('#api_key').val();
if (authentication_delivery == 'query' && api_key_val.length>0) {
2012-08-10 13:55:35 +02:00
url += url.indexOf('?') > 0 ? '&' : '?';
2015-03-25 14:53:31 +02:00
url += api_key_parameter + '=' + api_key_val;
2012-08-10 13:55:35 +02:00
}
2013-04-10 20:23:10 +02:00
// prepare the api enpoint
2014-02-06 15:12:26 +01:00
{% if endpoint == '' and app .request is not null and app .request .host -%}
2013-04-10 20:23:10 +02:00
var endpoint = ' {{ app .request .getBaseUrl ( ) }} ';
{% else -%}
var endpoint = ' {{ endpoint }} ';
2013-06-03 19:11:42 -07:00
{% endif -%}
2014-08-18 11:55:01 +02:00
{% if authentication and authentication .custom_endpoint %}
2014-08-07 16:45:46 +02:00
if ($('#api_endpoint') && typeof($('#api_endpoint').val()) != 'undefined') {
2013-04-10 20:23:10 +02:00
endpoint = $('#api_endpoint').val();
}
2014-08-08 09:51:05 +02:00
{% endif %}
2013-03-01 21:24:54 +01:00
2013-06-03 19:11:42 -07:00
// prepare final parameters
2013-06-05 18:51:01 -07:00
var body = { };
2013-06-14 16:15:43 -07:00
if(bodyFormat == 'json' && method != 'GET') {
2013-06-05 18:51:01 -07:00
body = unflattenDict(params);
2013-06-05 19:20:12 -07:00
body = JSON.stringify(body);
2013-06-05 18:51:01 -07:00
} else {
body = params;
2013-06-03 19:11:42 -07:00
}
var data = content.length ? content : body;
2014-06-17 02:02:35 -04:00
var ajaxOptions = {
2014-12-30 00:00:27 +01:00
url: (url.indexOf('http')!=0?endpoint:'') + url,
2015-09-21 16:59:47 +02:00
xhrFields: { withCredentials: true },
2012-10-17 15:15:35 +04:00
type: method,
2013-06-03 19:11:42 -07:00
data: data,
2012-10-17 15:15:35 +04:00
headers: headers,
2013-04-10 20:23:10 +02:00
crossDomain: true,
2013-06-03 19:11:42 -07:00
beforeSend: function (xhr) {
2014-07-25 12:08:00 +02:00
if (authentication_delivery) {
var value;
if ('http' == authentication_delivery) {
if ('basic' == authentication_type) {
value = 'Basic ' + btoa($('#api_login').val() + ':' + $('#api_pass').val());
} else if ('bearer' == authentication_type) {
value = 'Bearer ' + $('#api_key').val();
}
} else if ('header' == authentication_delivery) {
value = $('#api_key').val();
}
xhr.setRequestHeader(api_key_parameter, value);
2013-04-10 20:23:10 +02:00
}
},
2012-10-17 15:15:35 +04:00
complete: function(xhr) {
2016-03-17 16:09:47 +01:00
displayResponse(xhr, method, url, headers, data, result_container);
2012-10-17 15:15:35 +04:00
// and enable them back
$('input:not(.content-type), button', $(self)).removeAttr('disabled');
}
2014-06-17 02:02:35 -04:00
};
// overrides body format to send data properly
if (hasFileTypes) {
ajaxOptions.data = formData;
ajaxOptions.processData = false;
ajaxOptions.contentType = false;
2014-10-22 12:38:44 -04:00
delete(headers['Content-type']);
2014-06-17 02:02:35 -04:00
}
// and trigger the API call
$.ajax(ajaxOptions);
2012-06-28 10:37:35 +02:00
2012-07-18 13:18:26 +02:00
return false;
});
2012-06-28 10:37:35 +02:00
2014-04-24 23:02:56 +02:00
$('.operations').on('click', '.operation > .heading', function(e) {
2013-12-09 18:01:31 +01:00
if (history.pushState) {
2014-04-24 23:02:56 +02:00
history.pushState(null, null, $(this).data('href'));
2013-12-09 18:01:31 +01:00
e.preventDefault();
}
});
2015-03-29 15:06:58 +02:00
$(document).on('click', '.json-collapse-section', function() {
2015-03-29 14:37:06 +02:00
var openChar = $(this).data('section-open-character'),
closingChar = (openChar == ' { ' ? '}' : ']');
if ($(this).next('.json-collapse-content').is(':visible')) {
$(this).html('⊕' + openChar + '...' + closingChar);
} else {
$(this).html('▿' + $(this).data('section-open-character'));
}
$(this).next('.json-collapse-content').toggle();
});
$(document).on('copy', '.prettyprinted', function () {
var $toggleMarkers = $(this).find('.json-collapse-marker');
$toggleMarkers.hide();
setTimeout(function () {
$toggleMarkers.show();
}, 100);
});
2013-12-09 18:01:31 +01:00
$('.pane.sandbox').on('click', '.to-raw', function(e) {
2012-07-18 13:18:26 +02:00
renderRawBody($(this).parents('.pane').find('.response'));
2012-06-28 10:37:35 +02:00
2012-07-18 13:18:26 +02:00
e.preventDefault();
});
2012-07-04 16:31:06 +02:00
2013-12-09 18:01:31 +01:00
$('.pane.sandbox').on('click', '.to-prettify', function(e) {
2012-07-18 13:18:26 +02:00
renderPrettifiedBody($(this).parents('.pane').find('.response'));
2012-07-04 16:31:06 +02:00
2012-07-18 13:18:26 +02:00
e.preventDefault();
});
2012-07-04 16:31:06 +02:00
2013-12-09 18:01:31 +01:00
$('.pane.sandbox').on('click', '.to-expand, .to-shrink', function(e) {
2012-07-18 13:18:26 +02:00
var $headers = $(this).parents('.result').find('.headers');
var $label = $(this).parents('.result').find('a.to-expand');
if ($headers.hasClass('to-expand')) {
$headers.removeClass('to-expand');
$headers.addClass('to-shrink');
$label.text('Shrink');
} else {
$headers.removeClass('to-shrink');
$headers.addClass('to-expand');
$label.text('Expand');
}
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
e.preventDefault();
});
2012-05-24 01:22:45 +02:00
2014-06-17 00:10:34 -04:00
// sets the correct parameter type on load
$('.pane.sandbox .tuple_type').each(function() {
setParameterType($(this));
});
// handles parameter type change
$('.pane.sandbox').on('change', '.tuple_type', function() {
setParameterType($(this),$(this).val());
});
$('.pane.sandbox').on('click', '.add_parameter', function() {
var html = $(this).parents('.pane').find('.parameters_tuple_template').html();
$(this).before(html);
return false;
});
$('.pane.sandbox').on('click', '.add_header', function() {
var html = $(this).parents('.pane').find('.headers_tuple_template').html();
2012-05-24 01:22:45 +02:00
2012-07-18 13:18:26 +02:00
$(this).before(html);
return false;
});
2012-07-05 19:38:22 +02:00
2012-07-18 13:18:26 +02:00
$('.pane.sandbox').on('click', '.remove', function() {
$(this).parent().remove();
});
2012-07-05 19:38:22 +02:00
2012-07-18 13:18:26 +02:00
$('.pane.sandbox').on('click', '.set-content-type', function(e) {
var html;
var $element;
var $headers = $(this).parents('form').find('.headers');
var content_type = $(this).prev('input.value').val();
2012-07-05 19:38:22 +02:00
2012-07-18 13:18:26 +02:00
e.preventDefault();
2012-07-05 19:38:22 +02:00
2012-07-18 13:18:26 +02:00
if (content_type.length === 0) {
return;
2012-07-05 19:38:22 +02:00
}
2012-07-18 13:18:26 +02:00
$headers.find('input.key').each(function() {
if ($.trim($(this).val().toLowerCase()) === 'content-type') {
$element = $(this).parents('p');
return false;
}
});
2012-07-05 19:38:22 +02:00
2012-07-18 13:18:26 +02:00
if (typeof $element === 'undefined') {
html = $(this).parents('.pane').find('.tuple_template').html();
2012-07-05 19:38:22 +02:00
2012-07-18 13:18:26 +02:00
$element = $headers.find('legend').after(html).next('p');
}
2012-07-05 19:38:22 +02:00
2012-07-18 13:18:26 +02:00
$element.find('input.key').val('Content-Type');
$element.find('input.value').val(content_type);
});
2012-08-10 13:55:35 +02:00
2014-07-25 12:08:00 +02:00
{% if authentication and authentication .delivery == 'http' %}
2013-04-10 20:23:10 +02:00
var authentication_delivery = ' {{ authentication .delivery }} ';
2014-07-25 12:08:00 +02:00
var api_key_parameter = ' {{ authentication .name }} ';
var authentication_type = ' {{ authentication .type }} ';
2013-04-10 20:23:10 +02:00
{% elseif authentication and authentication .delivery == 'query' %}
var authentication_delivery = ' {{ authentication .delivery }} ';
2012-08-10 13:55:35 +02:00
var api_key_parameter = ' {{ authentication .name }} ';
var search = window.location.search;
var api_key_start = search.indexOf(api_key_parameter) + api_key_parameter.length + 1;
2013-06-03 19:11:42 -07:00
2012-08-10 13:55:35 +02:00
if (api_key_start > 0 ) {
var api_key_end = search.indexOf('&', api_key_start);
var api_key = -1 == api_key_end
? search.substr(api_key_start)
: search.substring(api_key_start, api_key_end);
$('#api_key').val(api_key);
}
2013-07-19 10:05:57 +02:00
{% elseif authentication and authentication .delivery == 'header' %}
var authentication_delivery = ' {{ authentication .delivery }} ';
var api_key_parameter = ' {{ authentication .name }} ';
2012-08-10 13:55:35 +02:00
{% else %}
2013-04-10 20:23:10 +02:00
var authentication_delivery = false;
2012-08-10 13:55:35 +02:00
{% endif %}
2012-07-18 13:18:26 +02:00
{% endif %}
2012-04-13 11:24:57 +02:00
</script>
</body>
</html>