From b5b167ef6db8ff208358d538287717da161be245 Mon Sep 17 00:00:00 2001 From: Geert Weening Date: Mon, 10 Nov 2014 10:14:11 -0800 Subject: [PATCH] [DOC] update README and GUIDES to match current API's --- README.md | 8 +++---- docs/GUIDES.md | 64 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0455e061..9f6b296d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #ripple-lib -JavaScript client for [rippled](https://github.com/ripple/rippled) +A JavaScript API for interacting with Ripple in Node.js and the browser [![Build Status](https://travis-ci.org/ripple/ripple-lib.svg?branch=develop)](https://travis-ci.org/ripple/ripple-lib) [![Coverage Status](https://coveralls.io/repos/ripple/ripple-lib/badge.png?branch=develop)](https://coveralls.io/r/ripple/ripple-lib?branch=develop) @@ -75,8 +75,8 @@ var remote = new Remote({ remote.connect(function() { /* remote connected */ - remote.request('server_info', function(err, info) { - + remote.requestServerInfo(function(err, info) { + // process err and info }); }); ``` @@ -87,7 +87,7 @@ remote.connect(function() { 2. `cd` into the repository and install dependencies with `npm install` -3. `npm test` or `node_modules/.bin/mocha test/*-test.js` +3. `npm test` **Generating code coverage** diff --git a/docs/GUIDES.md b/docs/GUIDES.md index 49c226e6..8669db4c 100644 --- a/docs/GUIDES.md +++ b/docs/GUIDES.md @@ -40,9 +40,19 @@ This file provides step-by-step walkthroughs for some of the most common usages ``` 3. Create a new `Remote` and connect to the network: ```js + + var options = { + trace : false, + trusted: true, + local_signing: true, + servers: [ + { host: 's-west.ripple.com', port: 443, secure: true } + ] + } + var remote = new Remote({options}); - remote.connect(function() { + remote.connect(function(err, res) { /* remote connected, use some remote functions here */ }); ``` @@ -57,11 +67,11 @@ This file provides step-by-step walkthroughs for some of the most common usages A `Request` is an `EventEmitter` so you can listen for success or failure events -- or, instead, you can provide a callback. -Here is an example, using [request_server_info](https://ripple.com/wiki/JSON_Messages#server_info). +Here is an example, using [requestServerInfo](https://ripple.com/wiki/JSON_Messages#server_info). + Constructing a `Request` with event listeners ```js -var request = remote.request('server_info'); +var request = remote.requestServerInfo(); request.on('success', function onSuccess(res) { //handle success @@ -102,23 +112,43 @@ See the [wiki](https://ripple.com/wiki/JSON_Messages#subscribe) for details on s var remote = new Remote({options}); remote.connect(function() { - var request = remote.request('subscribe'); - - request.addStream('ledger'); //remote will emit `ledger_closed` - request.addStream('transactions'); //remote will emit `transaction` - - request.on('ledger_closed', function onLedgerClosed(ledgerData) { - //handle ledger + var remote = new Remote({ + // see the API Reference for available options + servers: [ 'wss://s1.ripple.com:443' ] }); - request.on('transaction', function onTransacstion(transaction) { - //handle transaction - }); + remote.connect(function() { + console.log('Remote connected'); - request.request(function(err) { - if (err) { - } else { - } + var streams = [ + 'ledger', + 'transactions' + ]; + + var request = remote.requestSubscribe(streams); + + request.on('error', function(error) { + console.log('request error: ', error); + }); + + + // the `ledger_closed` and `transaction` will come in on the remote + // since the request for subscribe is finalized after the success return + // the streaming events will still come in, but not on the initial request + remote.on('ledger_closed', function(ledger) { + console.log('ledger_closed: ', JSON.stringify(ledger, null, 2)); + }); + + remote.on('transaction', function(transaction) { + console.log('transaction: ', JSON.stringify(transaction, null, 2)); + }); + + remote.on('error', function(error) { + console.log('remote error: ', error); + }); + + // fire the request + request.request(); }); }); ```