Permalink
Browse files

add get-latest-statement method.

  • Loading branch information...
1 parent fe16fef commit 5d8375ebc55f2cf7df1f31f1a49b59bfc35de75d @chjj committed Nov 21, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 lib/charged.js
View
@@ -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');

0 comments on commit 5d8375e

Please sign in to comment.