Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated ladder method and renamed to arenaLadder.

  • Loading branch information...
commit 25de60d7717a267bc7e20d99d499b76a0bedf904 1 parent 7a08d55
Christian Wesselhoeft authored

Showing 1 changed file with 33 additions and 14 deletions. Show diff stats Hide diff stats

  1. +33 14 index.js
47 index.js
@@ -48,6 +48,21 @@ armory.arena = function(options, callback) {
48 48 return this._get(path, options, callback)
49 49 }
50 50
  51 +// Retrieves an array of arena ladder information.
  52 +armory.arenaLadder = function(options, callback) {
  53 + var path = '/pvp/arena/' + options.battlegroup + '/' + options.id
  54 +
  55 + options.query = buildQuery(['asc', 'page', 'size'], options)
  56 +
  57 + if (callback) {
  58 + var cb = function(err, body, res) {
  59 + var data = getKey(body, 'arenateam')
  60 + callback.call(this, err, data, res)
  61 + }
  62 + }
  63 +
  64 + return this._get(path, options, cb)
  65 +}
51 66
52 67 // Retrieves array of auction data file URLs
53 68 armory.auction = function(options, callback) {
@@ -99,20 +114,6 @@ armory.item = function(options, callback) {
99 114 }
100 115
101 116
102   -// Retrieves array of objects describing the teams in a given arena ladder
103   -armory.ladder = function(options, callback) {
104   - var path = '/pvp/arena/' + options.battlegroup + '/' + options.name
105   -
106   - this._get(path, options, function(err, res) {
107   - if (err || !res) {
108   - return callback(err)
109   - }
110   -
111   - callback(null, res.arenateam)
112   - })
113   -}
114   -
115   -
116 117 // Retrieves array of realm objects with status info
117 118 armory.realmStatus = function(options, callback) {
118 119 var path = '/realm/status'
@@ -208,6 +209,24 @@ armory.realmStatus = function(options, callback) {
208 209 }
209 210 })
210 211
  212 +// Returns array of query-string parameters from options.
  213 +function buildQuery(params, options) {
  214 + return params.map(function(param) {
  215 + if (options[param] != null) {
  216 + return param + '=' + options[param]
  217 + }
  218 + })
  219 +}
  220 +
  221 +// Returns the value of an object's key if it exists.
  222 +function getKey(obj, key) {
  223 + if (obj && obj[key] != null) {
  224 + return obj[key]
  225 + } else {
  226 + return obj
  227 + }
  228 +}
  229 +
211 230 // Returns a new instance of the module with a wrapper applied.
212 231 function wrap(target, wrapper, context) {
213 232 var wrapped = {

0 comments on commit 25de60d

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