diff --git a/css/api-style.css b/css/api-style.css index c2dfb4c35e..109e9d64fd 100644 --- a/css/api-style.css +++ b/css/api-style.css @@ -87,7 +87,7 @@ h2 { margin:0; padding:0; } -#response { +#response, #response_body { min-height:100px; border-top-left-radius:0px !important; border-top-right-radius:0px !important; @@ -264,8 +264,9 @@ ul.toolbar li { /* JSON syntax highlighting */ -#request, -#response { +#request, #request_body, +#response, #response_body, +#rest_url_wrapper { font-family:'inconsolata',monospace; font-size:13px; line-height:20px; @@ -343,3 +344,33 @@ span.cm-number { span.cm-atom { color:#66327C !important; } + +/* Rest-tool-specific stuff */ + +#rest_method { + display: inline-block; + padding: 6px; + vertical-align: middle; + border: 1px dotted #aaa; + border-radius: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + margin-bottom: 3px; + background-color: #c7254e; + color: white; + appearance: none; + -moz-appearance: none; +} + +#rest_url_wrapper { + font-family: sans-serif; + display: inline-block; + margin-bottom: -11px; +} + +#rest_url { + width: auto; + border: 0; + background: none; + font-size:13px; +} diff --git a/js/apitool-rest.js b/js/apitool-rest.js new file mode 100644 index 0000000000..28b5ecaef5 --- /dev/null +++ b/js/apitool-rest.js @@ -0,0 +1,214 @@ +var commands = $("#command_list li"); +var GET = "GET"; +var POST = "POST"; +var PUT = "PUT"; +var DELETE = "DELETE"; + +var URL_BASE = "https://api.ripple.com:443"; + +//Build requests +var requests = { }; + +function slugify(str) { + str = str.replace(/^\s+|\s+$/g, ''); // trim + str = str.toLowerCase(); + + // remove accents, swap ñ for n, etc + var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;"; + var to = "aaaaeeeeiiiioooouuuunc------"; + for (var i=0, l=from.length ; i').attr('href', command.link).html(command.description)); + $(description).show(); + } else { + $(description).hide(); + } + + $('#selected_command').html($('') + .attr('href', command.link) + .text(command.name)); + + //$('#rest_url').val(command.path); + $('#rest_url').text(command.path); + + $("#rest_method").val(command.method); + $("#rest_method").change(); + + if (command.method == POST || command.method == PUT) { + cm_request.setValue(JSON.stringify(command.body, null, 2)); + } + + //reset response area + cm_response.setValue(""); + $("#rest_responsecode").text(""); +}; + + +function send_request() { + var method = $("#rest_method").val(); + if (method != GET && method != POST && method != PUT && method != DELETE) { + console.log("ERROR: unrecognized http method"); + return; + } + //var path = $("#rest_url").val(); + var path = $("#rest_url").text(); + + $(this).addClass('depressed'); + $("#response_body").addClass('obscured'); + + if (method == PUT || method == POST) { + var body = cm_request.getValue(); + $.ajax({ + type: method, + url: URL_BASE + path, + data: body + }).done(set_output).fail(error_output); + } else { + $.ajax({ + type: method, + url: URL_BASE + path + }).done(set_output).fail(error_output); + } +} + +function error_output(xhr,status,statusText) { + $("#rest_responsecode").text(xhr.status+" "+xhr.statusText); + cm_response.setValue(xhr.responseText); + $("#response_body").removeClass('obscured'); +} + +function set_output(body,status,xhr) { + $("#rest_responsecode").text(xhr.status+" "+xhr.statusText); + cm_response.setValue(JSON.stringify(body, null, 2)); + $("#response_body").removeClass('obscured'); +} + + + +$(document).ready(function() { + $("#request_button").click(send_request); + $("#rest_method").change(update_method); + + if (window.location.hash) { + var cmd = window.location.hash.slice(1).toLowerCase(); + var keys = Object.keys(requests); + var index = keys.indexOf(cmd); + + if (index === -1) return; + + var el = commands.eq(index); + + select_request(cmd); + + $(el).siblings().removeClass('selected'); + $(el).addClass('selected'); + } else { + select_request('generate-account'); + } +}); diff --git a/rest-api-tool.html b/rest-api-tool.html new file mode 100644 index 0000000000..abcc0cb3e5 --- /dev/null +++ b/rest-api-tool.html @@ -0,0 +1,229 @@ + + + + + + + + Ripple Developer Portal: Ripple-REST API Tool + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Ripple-REST API tool

+
+
+
    +
  • Generate Account
  • +
  • Get Account Balances
  • +
  • Get Account Settings
  • +
  • Update Account Settings
  • +
    +
  • Prepare Payment
  • +
  • Submit Payment
  • +
  • Confirm Payment
  • +
  • Get Payment History
  • +
    +
  • Get Trustlines
  • +
  • Grant Trustline
  • +
    +
  • Check Notifications
  • +
    +
  • Check Connection
  • +
  • Get Server Status
  • +
    +
  • Retrieve Ripple Transaction
  • +
  • Generate UUID
  • +
+
+
+
+

Request

+
+
Send request
+
+
+

+

+
Invalid JSON
+ +
+ https://api.ripple.com:443 +
+
+
+
+

Response

+

+
+
+
+
+
+
+
+
+ + + + + + + + + + + +