Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Refactor attaching URL to notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Cohen committed Apr 21, 2015
1 parent 4934c5b commit 6bf8e2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
10 changes: 9 additions & 1 deletion api/lib/notification_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var ripple = require('ripple-lib');
*/
function NotificationParser() {}

NotificationParser.prototype.parse = function(notification_details) {
NotificationParser.prototype.parse = function(notification_details, urlBase) {
var transaction = notification_details.transaction;
var account = notification_details.account;
var previous_transaction_identifier =
Expand Down Expand Up @@ -87,6 +87,14 @@ NotificationParser.prototype.parse = function(notification_details) {
previous_transaction_identifier;
}

// Add urlBase to each url in notification
Object.keys(notification).forEach(function(key) {
if (/url/.test(key) && notification[key]) {
notification[key] = urlBase +
notification[key];
}
});

return notification;
};

Expand Down
22 changes: 6 additions & 16 deletions api/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ var validate = require('./lib/validate.js');
*
* @callback
* @param {Error} error
* @param {Object with fields "account", "transaction",
* "next_transaction_identifier", "next_hash",
* "previous_transaction_identifier", "previous_hash"} notificationDetails
*/
* @param {Object} notificationDetails
**/

function attachPreviousAndNextTransactionIdentifiers(api,
notificationDetails, topCallback) {

Expand Down Expand Up @@ -168,7 +167,7 @@ function attachPreviousAndNextTransactionIdentifiers(api,
* @param {Error} error
* @param {Notification} notification
*/
function getNotificationHelper(api, account, identifier, topCallback) {
function getNotificationHelper(api, account, identifier, urlBase, topCallback) {

function getTransaction(callback) {
try {
Expand Down Expand Up @@ -214,7 +213,7 @@ function getNotificationHelper(api, account, identifier, topCallback) {

// Parse the Notification object from the notificationDetails
function parseNotificationDetails(notificationDetails, callback) {
callback(null, NotificationParser.parse(notificationDetails));
callback(null, NotificationParser.parse(notificationDetails, urlBase));
}

var steps = [
Expand All @@ -227,7 +226,6 @@ function getNotificationHelper(api, account, identifier, topCallback) {
async.waterfall(steps, topCallback);
}


/**
* Get a notification corresponding to the specified
* account and transaction identifier. Uses the res.json
Expand All @@ -243,7 +241,7 @@ function getNotification(account, identifier, urlBase, callback) {
validate.address(account);
validate.paymentIdentifier(identifier);

getNotificationHelper(this, account, identifier,
getNotificationHelper(this, account, identifier, urlBase,
function(error, notification) {
if (error) {
return callback(error);
Expand All @@ -253,14 +251,6 @@ function getNotification(account, identifier, urlBase, callback) {
notification: notification
};

// Add urlBase to each url in notification
Object.keys(responseBody.notification).forEach(function(key) {
if (/url/.test(key) && responseBody.notification[key]) {
responseBody.notification[key] = urlBase +
responseBody.notification[key];
}
});

// Move client_resource_id to response body instead of inside
// the Notification
var client_resource_id = responseBody.notification.client_resource_id;
Expand Down
6 changes: 5 additions & 1 deletion api/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,11 @@ function transactionFilter(transactions, options) {
* @param {Array of transactions in JSON format} transactions
*/
function getAccountTransactions(api, options, callback) {
validate.address(options.account);
try {
validate.address(options.account);
} catch(err) {
return callback(err);
}

if (!options.min) {
options.min = module.exports.DEFAULT_RESULTS_PER_PAGE;
Expand Down

0 comments on commit 6bf8e2b

Please sign in to comment.