Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding optional Wowhead fallback for item API.

  • Loading branch information...
commit 2658473295483b814e1d19d619b9a54822db8d64 1 parent c3a3f69
@xtian authored
Showing with 27 additions and 2 deletions.
  1. +7 −0 README.md
  2. +20 −2 index.js
View
7 README.md
@@ -5,6 +5,9 @@ A simple [node.js](http://github.com/joyent/node) wrapper around Blizzard's [RES
## Installation
npm install armory
+ npm install wowhead # optional
+
+If the [wowhead](http://github.com/xtian/node-wowhead) module is installed, it will be used as a fallback [when item requests fail](http://us.battle.net/wow/en/forum/topic/3657606329).
## Documentation
@@ -154,6 +157,10 @@ Retrieves an object containing data about a recipe.
});
});
+Additional options:
+
+* `fallback`: Setting to `false` disables Wowhead fallback.
+
[Item API Documentation](http://blizzard.github.com/api-wow-docs/#id3382086)
View
22 index.js
@@ -1,6 +1,10 @@
var request = require('request'),
crypto = require('crypto');
+try {
+ var wowhead = require('wowhead');
+} catch (e) {}
+
var armory = { privateKey: null, publicKey: null };
@@ -156,6 +160,20 @@ armory.defaults = function(defaults) {
};
+// Retrieves object describing an item with an optional fallback to Wowhead
+armory.item = function(options, callback) {
+ var path = '/item/' + options.name;
+
+ this._get(path, options, function(err, res) {
+ if (err && wowhead && options.fallback !== false) {
+ return wowhead(options.name, callback);
+ }
+
+ callback(err, res);
+ });
+};
+
+
// Retrieves array of objects describing the teams in a given arena ladder
armory.ladder = function(options, callback) {
var path = '/pvp/arena/' + options.battlegroup + '/' + options.name;
@@ -215,8 +233,8 @@ armory.realmStatus = function(options, callback) {
});
-// Export quest and item API
-['item', 'quest', 'recipe'].forEach(function(method) {
+// Export quest and recipe API
+['quest', 'recipe'].forEach(function(method) {
armory[method] = function(options, callback) {
var path = '/' + method + '/' + options.name;
this._get(path, options, callback);

0 comments on commit 2658473

Please sign in to comment.
Something went wrong with that request. Please try again.