mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-04 20:05:50 +00:00
[TASK] REST apitool - all methods specced, some structural cleanup
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
var commands = $("#command_list li");
|
||||
var request_body = $("#request_body");
|
||||
var request_button = $("#request_button");
|
||||
var response_body = $("#response_body");
|
||||
var response_code = $("#rest_responsecode");
|
||||
var rest_url = $('#rest_url');
|
||||
var rest_method = $("#rest_method");
|
||||
var selected_command = $("#selected_command");
|
||||
|
||||
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
|
||||
@@ -27,6 +32,15 @@ function slugify(str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
//Build requests
|
||||
var requests = { };
|
||||
function Request(name, obj) {
|
||||
obj.name = name;
|
||||
requests[slugify(name)] = obj;
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
$(commands).click(function() {
|
||||
var cmd = slugify($(this).text().trim());
|
||||
|
||||
@@ -40,13 +54,6 @@ $(commands).click(function() {
|
||||
});
|
||||
|
||||
|
||||
function Request(name, obj) {
|
||||
obj.name = name;
|
||||
requests[slugify(name)] = obj;
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
//---------- List of requests ------------------------//
|
||||
|
||||
Request('Generate Account', {
|
||||
@@ -73,6 +80,8 @@ Request('Get Account Settings', {
|
||||
Request('Update Account Settings', {
|
||||
method: POST,
|
||||
path: '/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/settings',
|
||||
description: 'Change the current settings for the given Ripple account',
|
||||
link: 'ripple-rest.html#updating-account-settings',
|
||||
body: {
|
||||
secret: "sssssssssssssssssssssssssssss",
|
||||
settings: {
|
||||
@@ -84,9 +93,7 @@ Request('Update Account Settings', {
|
||||
disable_master: false,
|
||||
transaction_sequence: 22
|
||||
}
|
||||
},
|
||||
description: 'Change the current settings for the given Ripple account',
|
||||
link: 'ripple-rest.html#updating-account-settings'
|
||||
}
|
||||
});
|
||||
|
||||
Request('Prepare Payment', {
|
||||
@@ -149,15 +156,87 @@ Request('Submit Payment', {
|
||||
}
|
||||
});
|
||||
|
||||
Request("Confirm Payment", {
|
||||
method: GET,
|
||||
path: "/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/payments/9D591B18EDDD34F0B6CF4223A2940AEA2C3CC778925BABF289E0011CD8FA056E",
|
||||
description: "Retrieve details of a payment and its status",
|
||||
link: "ripple-rest.html#confirming-a-payment"
|
||||
});
|
||||
|
||||
Request("Get Payment History", {
|
||||
method: GET,
|
||||
path: "/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/payments",
|
||||
description: "Browse through the history of payments sent and received by an account",
|
||||
link: "ripple-rest.html#payment-history",
|
||||
});
|
||||
|
||||
Request("Get Trustlines", {
|
||||
method: GET,
|
||||
path: "/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/trustlines?currency=USD",
|
||||
description: "Check the status of one or more trustlines attached to an account",
|
||||
link: "ripple-rest.html#reviewing-trustlines"
|
||||
});
|
||||
|
||||
Request("Grant Trustline", {
|
||||
method: POST,
|
||||
path: "/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/trustlines",
|
||||
description: "Add or modify a trustline from this account",
|
||||
link: "ripple-rest.html#granting-a-trustline",
|
||||
body: {
|
||||
"secret": "sneThnzgBgxc3zXPG....",
|
||||
"trustline": {
|
||||
"limit": "110",
|
||||
"currency": "USD",
|
||||
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
|
||||
"allows_rippling": false
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Request("Check Notifications", {
|
||||
method: GET,
|
||||
path: "/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/notifications/9D591B18EDDD34F0B6CF4223A2940AEA2C3CC778925BABF289E0011CD8FA056E",
|
||||
description: "Browse through the history of payments sent and received by an account",
|
||||
link: "ripple-rest.html#checking-notifications"
|
||||
});
|
||||
|
||||
Request("Check Connection", {
|
||||
method: GET,
|
||||
path: "/v1/server/connected",
|
||||
description: "Check whether the REST server is connected to a rippled server",
|
||||
link: "ripple-rest.html#check-connection-state"
|
||||
});
|
||||
|
||||
Request("Get Server Status", {
|
||||
method: GET,
|
||||
path: "/v1/server",
|
||||
description: "Retrieve information about the current status of the Ripple-REST server and the rippled server it is connected to",
|
||||
link: "ripple-rest.html#get-server-status"
|
||||
});
|
||||
|
||||
Request("Retrieve Ripple Transaction", {
|
||||
method: GET,
|
||||
path: "/v1/tx/85C5E6762DE7969DC1BD69B3C8C7387A5B8FCE6A416AA1F74C0ED5D10F08EADD",
|
||||
description: "Retrieve a raw Ripple transaction",
|
||||
link: "ripple-rest.html#retrieve-ripple-transaction"
|
||||
});
|
||||
|
||||
Request("Generate UUID", {
|
||||
method: GET,
|
||||
path: "/v1/uuid",
|
||||
description: "Create a universally-unique identifier (UUID) to use as the client resource ID for a payment",
|
||||
link: "ripple-rest.html#create-client-resource-id"
|
||||
});
|
||||
|
||||
//---------- End req. List ---------------------------//
|
||||
|
||||
var cm_request = CodeMirror($("#request_body").get(0), {
|
||||
var cm_request = CodeMirror(request_body.get(0), {
|
||||
mode: 'javascript',
|
||||
json: true,
|
||||
smartIndent: false
|
||||
});
|
||||
|
||||
var cm_response = CodeMirror($("#response_body").get(0), {
|
||||
var cm_response = CodeMirror(response_body.get(0), {
|
||||
mode: 'javascript',
|
||||
json: true,
|
||||
smartIndent: false,
|
||||
@@ -167,9 +246,9 @@ var cm_response = CodeMirror($("#response_body").get(0), {
|
||||
function update_method() {
|
||||
method = $(this).val();
|
||||
if (method == GET || method == DELETE) {
|
||||
$("#request_body").hide();
|
||||
request_body.hide();
|
||||
} else {
|
||||
$("#request_body").show();
|
||||
request_body.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,43 +256,47 @@ function select_request(request) {
|
||||
command = requests[request];
|
||||
|
||||
if (command.description) {
|
||||
$(description).html($('<a>').attr('href', command.link).html(command.description));
|
||||
$(description).html($('<a>')
|
||||
.attr('href', command.link)
|
||||
.html(command.description));
|
||||
$(description).show();
|
||||
} else {
|
||||
$(description).hide();
|
||||
}
|
||||
|
||||
$('#selected_command').html($('<a>')
|
||||
.attr('href', command.link)
|
||||
.text(command.name));
|
||||
selected_command.html($('<a>')
|
||||
.attr('href', command.link)
|
||||
.text(command.name));
|
||||
|
||||
//$('#rest_url').val(command.path);
|
||||
$('#rest_url').text(command.path);
|
||||
//rest_url.val(command.path);
|
||||
rest_url.text(command.path);
|
||||
|
||||
$("#rest_method").val(command.method);
|
||||
$("#rest_method").change();
|
||||
rest_method.val(command.method);
|
||||
rest_method.change();
|
||||
|
||||
if (command.method == POST || command.method == PUT) {
|
||||
cm_request.setValue(JSON.stringify(command.body, null, 2));
|
||||
} else {
|
||||
//No body, so wipe out the current contents.
|
||||
//This prevents confusion if the user toggles the HTTP method dropdown
|
||||
cm_request.setValue("");
|
||||
}
|
||||
|
||||
//reset response area
|
||||
cm_response.setValue("");
|
||||
$("#rest_responsecode").text("");
|
||||
reset_response_area();
|
||||
};
|
||||
|
||||
|
||||
function send_request() {
|
||||
var method = $("#rest_method").val();
|
||||
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();
|
||||
//var path = rest_url.val();
|
||||
var path = rest_url.text();
|
||||
|
||||
$(this).addClass('depressed');
|
||||
$("#response_body").addClass('obscured');
|
||||
response_body.addClass('obscured');
|
||||
|
||||
if (method == PUT || method == POST) {
|
||||
var body = cm_request.getValue();
|
||||
@@ -226,27 +309,33 @@ function send_request() {
|
||||
$.ajax({
|
||||
type: method,
|
||||
url: URL_BASE + path
|
||||
}).done(set_output).fail(error_output);
|
||||
}).done(success_output).fail(error_output).always(reset_sending_status);
|
||||
}
|
||||
}
|
||||
|
||||
function error_output(xhr,status,statusText) {
|
||||
$("#rest_responsecode").text(xhr.status+" "+xhr.statusText);
|
||||
response_code.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);
|
||||
function success_output(body,status,xhr) {
|
||||
response_code.text(xhr.status+" "+xhr.statusText);
|
||||
cm_response.setValue(JSON.stringify(body, null, 2));
|
||||
$("#response_body").removeClass('obscured');
|
||||
}
|
||||
|
||||
function reset_sending_status() {
|
||||
response_body.removeClass('obscured');
|
||||
request_button.removeClass('depressed');
|
||||
}
|
||||
|
||||
function reset_response_area() {
|
||||
cm_response.setValue("");
|
||||
response_code.text("");
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#request_button").click(send_request);
|
||||
$("#rest_method").change(update_method);
|
||||
request_button.click(send_request);
|
||||
rest_method.change(update_method);
|
||||
|
||||
if (window.location.hash) {
|
||||
var cmd = window.location.hash.slice(1).toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user