Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 7ad154f7560f583118ad1c92b79cc53d43259663 Christian Wesselhoeft committed Apr 17, 2011
Showing with 207 additions and 0 deletions.
  1. +19 −0 LICENSE.md
  2. +6 −0 Makefile
  3. +36 −0 README.md
  4. +1 −0 index.js
  5. +61 −0 lib/armory.js
  6. +20 −0 package.json
  7. +64 −0 tests/realm.test.js
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Christian Wesselhoeft
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,6 @@
+
+test:
+ @nodeunit tests
+
+lint:
+ @jshint ./lib/ ./tests/
@@ -0,0 +1,36 @@
+# node-armory
+
+A simple [node.js](http://github.com/joyent/node) wrapper around Blizzard's REST API for World of Warcraft.
+
+## Installation
+
+<pre>
+ npm install armory
+</pre>
+
+## Supported Methods
+
+* `realmStatus`
+ * `realms` _(optional)_: String or array containing realm name(s). Defaults to `''` which returns all realms.
+ * `region` _(optional)_: two-letter string containing region code. Defaults to `'us'`.
+ * `callback`
+
+## Usage
+
+<pre>
+ var armory = require('armory');
+
+ // All realms
+ armory.realmStatus(function(res) {
+ var realms = {};
+
+ for (var i = res.length; i--;) {
+ realms[res[i].slug] = res[i];
+ }
+ });
+
+ // Specific realms
+ armory.realmStatus(['Shadowmoon', 'Nazgrel'], function(res) {
+
+ });
+</pre>
@@ -0,0 +1 @@
+module.exports = require('./lib/armory');
@@ -0,0 +1,61 @@
+var request = require('request');
+
+// Makes request
+function api(options, callback) {
+
+ var uri = 'http://' + options.region + '.battle.net/api/wow/' +
+ options.path + '?' + options.query;
+
+ request({ uri: uri }, function(err, res, body) {
+ if (err) throw err;
+ callback(body);
+ });
+
+ return;
+}
+
+// Provides realm status information
+// Takes in optional realm(s) and region with callback. Returns parsed JSON.
+exports.realmStatus = function(realms, region, callback) {
+
+ var options = {
+ path: 'realm/status',
+ query: '',
+ region: region
+ };
+
+ if (typeof region === 'function') {
+ callback = region;
+ options.region = 'us';
+ }
+
+ if (Array.isArray(realms)) {
+
+ for (var i = realms.length; i--;) {
+ options.query += 'realm=' + escape(realms[i]) + '&';
+ }
+
+ } else if (typeof realms === 'function') {
+ callback = realms;
+ options.region = 'us';
+
+ } else if (realms.length === 2) {
+ options.region = realms;
+
+ } else {
+ options.query = 'realm=' + escape(realms);
+ }
+
+
+ api(options, function(response) {
+ response = JSON.parse(response);
+
+ if (!response.status) {
+ response = response.realms;
+ }
+
+ callback(response);
+ });
+
+ return;
+};
@@ -0,0 +1,20 @@
+{
+ "name": "armory",
+ "version": "0.1.0",
+ "description": "A simple wrapper for the WoW Armory API.",
+ "keywords": ["wow", "warcraft", "armory"],
+ "author": "Christian Wesselhoeft <christian@cwesselhoeft.com>",
+ "main": "./lib/armory",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/xtian/node-armory.git"
+ },
+ "dependencies": {
+ "request": ">=1.9.5"
+ },
+ "devDependencies": {
+ "nodeunit": ">=0.5.1",
+ "jshint": ">=0.2.0"
+ },
+ "engines": ["node >= 0.4.0"]
+}
@@ -0,0 +1,64 @@
+var assert = require('assert'),
+ armory = require('../lib/armory');
+
+
+module.exports = {
+
+ 'test: all US realms': function(test) {
+ armory.realmStatus(function(res) {
+ test.ok(Array.isArray(res));
+ test.equal(res[0].slug, 'aegwynn');
+ test.done();
+ });
+ },
+
+ 'test: all EU realms': function(test) {
+ armory.realmStatus('eu', function(res) {
+ test.ok(Array.isArray(res));
+ test.equal(res[0].slug, 'aegwynn');
+ test.done();
+ });
+ },
+
+ 'test: single US realm': function(test) {
+ armory.realmStatus('Shadowmoon', function(res) {
+ test.ok(Array.isArray(res));
+ test.equal(res[0].slug, 'shadowmoon');
+ test.done();
+ });
+ },
+
+ 'test: single EU realm': function(test) {
+ armory.realmStatus('Earthen Ring', 'eu', function(res) {
+ test.ok(Array.isArray(res));
+ test.equal(res[0].slug, 'earthen-ring');
+ test.done();
+ });
+ },
+
+ 'test: multiple US realms': function(test) {
+ armory.realmStatus(['Earthen Ring', 'Shadowmoon'], function(res) {
+ test.ok(Array.isArray(res));
+ test.equal(res[0].slug, 'shadowmoon');
+ test.equal(res[1].slug, 'earthen-ring');
+ test.done();
+ });
+ },
+
+ 'test: multiple EU realms': function(test) {
+ armory.realmStatus(['Earthen Ring', 'Tarren Mill'], 'eu', function(res) {
+ test.ok(Array.isArray(res));
+ test.equal(res[0].slug, 'tarren-mill');
+ test.equal(res[1].slug, 'earthen-ring');
+ test.done();
+ });
+ },
+
+ 'test: non-existent realm': function(test) {
+ armory.realmStatus('foo', function(res) {
+ test.equal(res.status, 'nok');
+ test.equal(res.reason, 'Invalid realm list');
+ test.done();
+ });
+ }
+};

0 comments on commit 7ad154f

Please sign in to comment.