Skip to content

Commit

Permalink
Updated ladder method and renamed to arenaLadder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Wesselhoeft committed Jan 27, 2013
1 parent 7a08d55 commit 25de60d
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions index.js
Expand Up @@ -48,6 +48,21 @@ armory.arena = function(options, callback) {
return this._get(path, 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 // Retrieves array of auction data file URLs
armory.auction = function(options, callback) { armory.auction = function(options, callback) {
Expand Down Expand Up @@ -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 // Retrieves array of realm objects with status info
armory.realmStatus = function(options, callback) { armory.realmStatus = function(options, callback) {
var path = '/realm/status' var path = '/realm/status'
Expand Down Expand Up @@ -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. // Returns a new instance of the module with a wrapper applied.
function wrap(target, wrapper, context) { function wrap(target, wrapper, context) {
var wrapped = { var wrapped = {
Expand Down

0 comments on commit 25de60d

Please sign in to comment.