Skip to content
Extraits de code Groupes Projets
Valider 310f5299 rédigé par maxwell's avatar maxwell Validation de danielgrippi
Parcourir les fichiers

dumb api console

parent ea3d839e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -38,7 +38,7 @@ class ApisController < ActionController::Metal
##people
def people_index
set_defaults
people = Person.search(params[:q]).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
people = Person.search(params[:q], nil).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
render :json => people.as_json
end
......
......@@ -39,3 +39,14 @@
= "invite token: #{accept_invitation_url(user, :invitation_token => user.invitation_token)}" if user.invitation_token
%br
%br
= javascript_include_tag 'apiconsole'
#query
%h3 api console
= text_field_tag :api
= submit_tag 'ping this api', :id => 'api_submit'
response:
%br
%br
#resp
var ApiConsole = {
prettyPrint: function(obj, indent)
{
var result = "";
if (indent == null) indent = "";
for (var property in obj)
{
var value = obj[property];
if (typeof value == 'string')
value = "'" + value + "'";
else if (typeof value == 'object')
{
if (value instanceof Array)
{
// Just let JS convert the Array to a string!
value = "[ " + value + " ]";
}
else
{
// Recursive dump
// (replace " " by "\t" or something else if you prefer)
var od = ApiConsole.prettyPrint(value, indent + " ");
// If you like { on the same line as the key
//value = "{\n" + od + "\n" + indent + "}";
// If you prefer { and } to be aligned
value = "\n" + indent + "{\n" + od + "\n" + indent + "}";
}
}
result += indent + "'" + property + "' : " + value + ",\n";
}
return result.replace(/,\n$/, "");
},
init: function(field, query_box, button){
this.field = $(field);
this.query = $(query_box);
this.button = $(button);
this.button.click(function(){
$.getJSON(ApiConsole.query.val(), function(data){
var json = ApiConsole.prettyPrint(data, '');
console.dir(json);
ApiConsole.field.html(json);
});
});
}
}
$(document).ready(function(){
ApiConsole.init('#resp', 'input[name=api]', '#api_submit:input');
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter