Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated ladder method and renamed to arenaLadder.

  • Loading branch information...
commit 25de60d7717a267bc7e20d99d499b76a0bedf904 1 parent 7a08d55
@xtian authored
Showing with 33 additions and 14 deletions.
  1. +33 −14 index.js
View
47 index.js
@@ -48,6 +48,21 @@ armory.arena = function(options, callback) {
return this._get(path, options, callback)
}
+// Retrieves an array of arena ladder information.
+armory.arenaLadder = function(options, callback) {
+ var path = '/pvp/arena/' + options.battlegroup + '/' + options.id
+
+ options.query = buildQuery(['asc', 'page', 'size'], options)
+
+ if (callback) {
+ var cb = function(err, body, res) {
+ var data = getKey(body, 'arenateam')
+ callback.call(this, err, data, res)
+ }
+ }
+
+ return this._get(path, options, cb)
+}
// Retrieves array of auction data file URLs
armory.auction = function(options, callback) {
@@ -99,20 +114,6 @@ armory.item = function(options, callback) {
}
-// 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
-
- this._get(path, options, function(err, res) {
- if (err || !res) {
- return callback(err)
- }
-
- callback(null, res.arenateam)
- })
-}
-
-
// Retrieves array of realm objects with status info
armory.realmStatus = function(options, callback) {
var path = '/realm/status'
@@ -208,6 +209,24 @@ armory.realmStatus = function(options, callback) {
}
})
+// Returns array of query-string parameters from options.
+function buildQuery(params, options) {
+ return params.map(function(param) {
+ if (options[param] != null) {
+ return param + '=' + options[param]
+ }
+ })
+}
+
+// Returns the value of an object's key if it exists.
+function getKey(obj, key) {
+ if (obj && obj[key] != null) {
+ return obj[key]
+ } else {
+ return obj
+ }
+}
+
// Returns a new instance of the module with a wrapper applied.
function wrap(target, wrapper, context) {
var wrapped = {
Please sign in to comment.
Something went wrong with that request. Please try again.