dumb api console
This commit is contained in:
parent
ea3d839e1c
commit
310f529914
3 changed files with 66 additions and 1 deletions
|
|
@ -38,7 +38,7 @@ class ApisController < ActionController::Metal
|
||||||
##people
|
##people
|
||||||
def people_index
|
def people_index
|
||||||
set_defaults
|
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
|
render :json => people.as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,3 +39,14 @@
|
||||||
= "invite token: #{accept_invitation_url(user, :invitation_token => user.invitation_token)}" if user.invitation_token
|
= "invite token: #{accept_invitation_url(user, :invitation_token => user.invitation_token)}" if user.invitation_token
|
||||||
%br
|
%br
|
||||||
%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
|
||||||
|
|
||||||
|
|
|
||||||
54
public/javascripts/apiconsole.js
Normal file
54
public/javascripts/apiconsole.js
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
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');
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue