[TASK] Rest API tool through submit payment

This commit is contained in:
mDuo13
2014-09-18 18:49:08 -07:00
parent a46a2a5a05
commit fd4be275ab
3 changed files with 477 additions and 3 deletions

View File

@@ -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;
}

214
js/apitool-rest.js Normal file
View File

@@ -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<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes
return str;
}
$(commands).click(function() {
var cmd = slugify($(this).text().trim());
if (!requests[cmd]) return;
select_request(cmd, true);
window.location.hash = cmd;
$(this).siblings().removeClass('selected');
$(this).addClass('selected');
});
function Request(name, obj) {
obj.name = name;
requests[slugify(name)] = obj;
return obj;
};
//---------- List of requests ------------------------//
Request('Generate Account', {
method: GET,
path: "/v1/accounts/new",
description: 'Generate the keys for a potential new account',
link: 'ripple-rest.html#generating-accounts'
});
Request('Get Account Balances', {
method: GET,
path: '/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/balances',
description: 'Retrieve the current balances for the given Ripple account',
link: 'ripple-rest.html#account-balances'
});
Request('Get Account Settings', {
method: GET,
path: '/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/settings',
description: 'Retrieve the current settings for the given Ripple account',
link: 'ripple-rest.html#account-settings'
});
Request('Update Account Settings', {
method: POST,
path: '/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/settings',
body: {
secret: "sssssssssssssssssssssssssssss",
settings: {
transfer_rate: 100,
password_spent: false,
require_destination_tag: false,
require_authorization: false,
disallow_xrp: false,
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', {
method: GET,
path: '/v1/accounts/rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn/payments/paths/ra5nK24KXen9AHvsdFTKHSANinZseWnPcX/1+USD+rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn',
description: 'Change the current settings for the given Ripple account',
link: 'ripple-rest.html#preparing-a-payment'
});
//---------- End req. List ---------------------------//
var cm_request = CodeMirror($("#request_body").get(0), {
mode: 'javascript',
json: true,
smartIndent: false
});
var cm_response = CodeMirror($("#response_body").get(0), {
mode: 'javascript',
json: true,
smartIndent: false,
readOnly: true
});
function update_method() {
method = $(this).val();
if (method == GET || method == DELETE) {
$("#request_body").hide();
} else {
$("#request_body").show();
}
}
function select_request(request) {
command = requests[request];
if (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));
//$('#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');
}
});

229
rest-api-tool.html Normal file
View File

@@ -0,0 +1,229 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>Ripple Developer Portal: Ripple-REST API Tool</title>
<!-- favicon -->
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Flatdoc -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src='https://dev.ripple.com/vendor/flatdoc/v/0.8.0/legacy.js'></script>
<script src='https://dev.ripple.com/vendor/flatdoc/v/0.8.0/flatdoc.js'></script>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<!-- Custom Stylesheet -->
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:600italic,400,700,300' rel='stylesheet' type='text/css'>
<link href='css/main.css' rel='stylesheet'>
<link href='css/custom.css' rel='stylesheet'>
<link rel="shortcut icon" href="favicon.ico?v=2" type="image/x-icon">
<link rel="icon" href="favicon.ico?v=2" type="image/x-icon">
<!-- start Mixpanel -->
<script type="text/javascript">(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===e.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f);b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==
typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");for(g=0;g<i.length;g++)f(c,i[g]);
b._i.push([a,e,d])};b.__SV=1.2}})(document,window.mixpanel||[]);
mixpanel.init("132d42885e094171f34467fc54da6fab");
</script>
<script>if (window.location.host == "dev.ripple.com") { mixpanel.track("ripple-api-tool"); }</script>
<!-- end Mixpanel -->
<!-- start google analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-49188512-1', 'ripple.com');
ga('send', 'pageview');
</script>
<!-- end google analytics -->
<!-- Temporary shims until I modify the css directly -->
<link type='text/css' rel='stylesheet' href='css/mod.css' />
<script src='js/expandcode.js'></script>
</head>
<body role='flatdoc' class='no-literate'>
<!--Draft warning would go here-->
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://dev.ripple.com/"><img class="small_logo" src="assets/img/ripple_logo_small.png"></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Resources</a></li>
<li><a href="https://www.bountysource.com/teams/ripple/bounties">Bounties</a></li>
<li><a href="https://ripplelabs.atlassian.net/">Bug Tracking</a></li>
<li><a href="https://ripple.com/dev/blog/">Dev Blog</a></li>
<li><a href="https://ripple.com/forum/viewforum.php?f=2&sid=c016bc6b934120b7117c0e136e74de98">Forums</a></li>
<li class="active"><a target="_self" href="ripple-api-tool.html">API Tool</a></li>
</ul>
<div class='right'>
<!-- GitHub buttons -->
<iframe src="https://dev.ripple.com/vendor/ghbtn.html?user=ripple&repo=ripple-dev-portal&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe>
</div>
</div><!--/.nav-collapse -->
</div>
</div>
<div class='content-root'>
<div id='wrapper'>
<h1>Ripple-REST API tool</h1>
<div style="clear:both;"></div>
<div id='command_wrapper'>
<ul id='command_list'>
<li class='selected'>Generate Account</li>
<li>Get Account Balances</li>
<li>Get Account Settings</li>
<li>Update Account Settings</li>
<br/>
<li>Prepare Payment</li>
<li>Submit Payment</li>
<li>Confirm Payment</li>
<li>Get Payment History</li>
<br/>
<li>Get Trustlines</li>
<li>Grant Trustline</li>
<br/>
<li>Check Notifications</li>
<br/>
<li>Check Connection</li>
<li>Get Server Status</li>
<br/>
<li>Retrieve Ripple Transaction</li>
<li>Generate UUID</li>
</ul>
<div id='command_table'>
<div id='io_wrapper'>
<div id='input' class='io'>
<h2>Request</h2>
<div id='request_options'>
<div class="button btn btn-primary api" id='request_button'>Send request</div>
</div>
<div style="clear:both;"></div>
<h3 id='selected_command' title='Reference information'></h3>
<p id='description'></p>
<div id='invalid'>Invalid JSON</div>
<select id='rest_method'>
<option value='GET'>GET</option>
<option value='POST'>POST</option>
</select>
<div id='rest_url_wrapper'>
<span id='rest_host'>https://api.ripple.com:443</span><span id='rest_url' contenteditable='true'></span>
</div>
<div id='request_body'></div>
</div>
<div id='output' class='io'>
<h2>Response</h2>
<p id='rest_responsecode'></p>
<div id='response_body'></div>
<div id='tooltip'></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<p class="text-muted">
<div class="row">
<div class="col-md-2">
<ul class="footer_links applications">
<li><a href="https://www.rippletrade.com">Ripple Trade</a>
<li><a href="https://www.ripplecharts.com">Ripple Charts</a>
<li><a href="https://ripple.com/graph">Ripple Graph</a>
<li><a href="http://codius.org/">Codius</a>
</ul>
</div>
<div class="col-md-2">
<ul class="footer_links middleware">
<li><a href="gatewayd.html">Gatewayd</a>
<li><a href="ripple-rest.html">Ripple REST</a>
<li><a href="https://github.com/ripple/ripple-lib">Ripple Lib</a>
</ul>
</div>
<div class="col-md-2">
<ul class="footer_links core_network">
<li><a href="rippled-apis.html">rippled</a>
</ul>
</div>
<div class="col-md-2">
<ul class="footer_links bounties">
<li><a href="https://www.bountysource.com/teams/ripple/bounties">Bounties</a>
<li><a href="https://ripplelabs.atlassian.net/">Bug tracking</a>
<li><a href="guidelines.html">Brand guidelines</a>
<li><a href="https://ripple.com/dev/blog/">Dev blog</a>
<li><a href="https://ripple.com/forum/viewforum.php?f=2&sid=c016bc6b934120b7117c0e136e74de98">Forums</a>
<li><a href="https://ripple.com/wiki/Main_Page">Wiki</a>
</ul>
</div>
<div class="col-md-4 mail_chimp">
<p>Join the mailing list!</p>
<label for="mce-EMAIL">Email address</label>
<!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
#mc_embed_signup{clear:left; font:14px; }
</style>
<div id="mc_embed_signup">
<form action="//ripple.us4.list-manage.com/subscribe/post?u=245dbc1c47849f034390dc5bf&amp;id=4dfbe160d0" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="" required>
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px; top: -50px;"><input type="text" name="b_245dbc1c47849f034390dc5bf_4dfbe160d0" tabindex="-1" value=""></div>
<input type="submit" value="Submit" name="subscribe" id="mc-embedded-subscribe" class="button btn btn-primary">
</form>
</div>
<!--End mc_embed_signup-->
</div>
</div>
</div>
</div>
<link rel='stylesheet' type='text/css' href='css/api-style.css'/>
<link rel='stylesheet' type='text/css' href='css/codemirror.css'/>
<script type='text/javascript' src='js/es5-shim.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/codemirror/3.16.0/codemirror.min.js'></script>
<script type='text/javascript' src='js/cm-javascript.min.js'></script>
<script type='text/javascript' src='js/apitool-rest.js'></script>
</body>
</html>