Skip to content

Commit

Permalink
add get-latest-statement method.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Nov 24, 2012
1 parent fe16fef commit 5d8375e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/charged.js
Expand Up @@ -206,6 +206,26 @@ Charged.prototype.getSubscriptionStatements = function(name, options, callback)
return this.get(path, options, callback, 'statement');
};

Charged.prototype.getLatestStatement =
Charged.prototype.getLatestSubscriptionStatement = function(sub, callback) {
var self = this;

var opt = {
per_page: 100000
// order: 'oldest_first'
};

return this.getSubscriptionStatementIds(sub, opt, function(err, ids) {
if (err) return callback(err);

if (!ids.length) {
return callback(new Error('Not found.'));
}

return self.getStatement(ids.pop(), callback);
});
};

Charged.prototype.getStatement = function(name, callback) {
var path = '/statements/' + escape(name);
return this.get(path, callback, 'statement');
Expand Down

0 comments on commit 5d8375e

Please sign in to comment.