There was a library already. But I didn't quite like it. So I created my own library, with blackjack and generics.
The code covers most methods described in the Recurly Developer Hub.
You can configure xml2js
parser, that lives under the hood. Like this:
new Recurly({
/* API key, subdomain */
}, {
/* xml2js conf! */
})
The library doesn't check weird callback length whatsoever (as neighboring does). Who need those things?
npm install --save node-recurly-client
var Recurly = require('node-recurly-client');
var recurly = new Recurly({
apiKey: 'api-key-goes-here',
subdomain: 'subdomain-goes-there'
});
recurly.accounts.create({
account_code: '0xdeadbeef',
email: 'deadbeef.is@watching.you'
}, function (err, response) {/* processing etc. */});
You may notice, that library doesn't have any methods explicitly defined, that call Recurly resource. Isn't it lovely?
Roughly saying, the library does the following:
- Get the request library.
- Set the default headers.
- Magically create methods by provided JSON files.
The JSON files live in the library under lib/schemas
path. Usually, you don't need to worry about them.
All request parameters subordinate to the following logic:
- URI parameters go as separate parameters.
- Body object if any goes after all URI parameters.
- The callback is obligatory and is the last parameter.
Let's take as an example update subscription call. It wants one parameter in URI and a body. The call would look like this:
recurly.subscription.update('uuid-string', {/* body */}, callback);
How would another random call would look like, if there would be multiple URI parameters? Easy!
recurly.random.call(uriParamString1, uriParamString2, bodyObj, callback);
If there are no modifiers in URI, those parameters have to be omitted. If there is no body, body parameter has to be omitted.
recurly.accounts.list(cb);
recurly.accounts.create(body, cb);
recurly.accounts.lookup(accountCode, body, cb);
recurly.accounts.update(accountCode, body, cb);
recurly.accounts.close(accountCode, cb);
recurly.accounts.reopen(accountCode, body, cb);
recurly.accounts.balance(accountCode, cb);
recurly.accounts.notes(accountCode, cb);
recurly.accountAcquisition.create(accountCode, body, cb);
recurly.accountAcquisition.lookup(accountCode, cb);
recurly.accountAcquisition.update(accountCode, body, cb);
recurly.accountAcquisition.clear(accountCode, cb);
recurly.adjustments.list(accountCode, cb);
recurly.adjustments.create(accountCode, body, cb);
recurly.adjustments.lookup(uuid, cb);
recurly.adjustments.delete(uuid, cb);
recurly.billingInfo.create(accountCode, body, cb);
recurly.billingInfo.lookup(accountCode, cb);
recurly.billingInfo.update(accountCode, body, cb);
recurly.billingInfo.clear(accountCode, cb);
recurly.coupons.list(cb);
recurly.coupons.create(body, cb);
recurly.coupons.lookup(couponCode, cb);
recurly.coupons.generate(couponCode, body, cb);
recurly.coupons.expire(couponCode, cb);
recurly.coupons.edit(couponCode, body, cb);
recurly.coupons.restore(couponCode, body, cb);
recurly.coupons.listUnique(couponCode, cb);
recurly.couponRedemptions.account(accountCode, cb);
recurly.couponRedemptions.coupon(accountCode, redemptionUuid, cb);
recurly.couponRedemptions.invoice(invoiceNumber, cb);
recurly.couponRedemptions.subscription(uuid, cb);
recurly.couponRedemptions.redeem(couponCode, cb);
recurly.couponRedemptions.remove(accountCode, uuid, cb);
recurly.giftCards.list(cb);
recurly.giftCards.preview(body, cb);
recurly.giftCards.create(body, cb);
recurly.giftCards.lookup(id, cb);
recurly.giftCards.redeem(redemptionCode, body, cb);
recurly.giftCards.previewSubscription(body, cb);
recurly.giftCards.createSubscription(body, cb);
recurly.invoices.list(cb);
recurly.invoices.listAccount(accountCode, cb);
recurly.invoices.preview(accountCode, body, cb);
recurly.invoices.post(accountCode, body, cb);
recurly.invoices.lookup(invoiceNumber, cb);
recurly.invoices.markAsPaid(invoiceNumber, cb);
recurly.invoices.markAsFailed(invoiceNumber, cb);
recurly.invoices.refundLineItem(invoiceNumber, body, cb);
recurly.invoices.refundOpenAmount(invoiceNumber, body, cb);
recurly.invoices.offlinePayment(invoiceNumber, body, cb);
recurly.plans.list(cb);
recurly.plans.create(body, cb);
recurly.plans.lookup(planCode, cb);
recurly.plans.update(planCode, cb);
recurly.plans.delete(planCode, cb);
recurly.planAddOns.list(planCode, cb);
recurly.planAddOns.create(planCode, body, cb);
recurly.planAddOns.lookup(planCode, addOnCode, cb);
recurly.planAddOns.update(planCode, addOnCode, body, cb);
recurly.planAddOns.delete(planCode, addOnCode, cb);
recurly.measuredUnits.list(cb);
recurly.measuredUnits.create(body, cb);
recurly.measuredUnits.lookup(measuredUnitId, cb);
recurly.measuredUnits.update(measuredUnitId, body, cb);
recurly.measuredUnits.delete(measuredUnitId, cb);
recurly.subscriptions.list(accountCode, cb);
recurly.subscriptions.preview(body, cb);
recurly.subscriptions.create(body, cb);
recurly.subscriptions.lookup(uuid, cb);
recurly.subscriptions.previewChange(uuid, body, cb);
recurly.subscriptions.update(uuid, body, cb);
recurly.subscriptions.updateNotes(uuid, body, cb);
recurly.subscriptions.cancel(uuid, cb);
recurly.subscriptions.reactivate(uuid, cb);
recurly.subscriptions.terminate(uuid, refundType, charge, cb);
recurly.subscriptions.postpone(uuid, nextRenewalDate, bulk, cb);