// Dependencies
var request = require('request');

//Define
module.exports = function(group, rank, callbacks) {
  request.get('http://www.roblox.com/api/groups/' + group + '/RoleSets/', function(err, res, body) {
    if (callbacks.always)
      callbacks.always();
    if (err) {
      if (callbacks.failure)
        callbacks.failure(err);
      if (callbacks.always)
        callbacks.always();
      return console.error('GetRoles request failed:' + err);
    }
    var response = JSON.parse(body);
    if (rank) {
      for (var i = 0; i < body.length; i++) {
        if (response[i].Rank == rank) {
          response = response[i].ID;
          break;
        }
      }
    }
    if (callbacks.success)
      callbacks.success(response);
    return response;
  });
};

// Dependencies
var request = require('request');

// Define
module.exports = function(group, callbacks) {
  request.get('http://www.roblox.com/api/groups/' + group + '/RoleSets/', function(err, res, body) {
    if (callbacks.always)
      callbacks.always();
    if (err) {
      if (callbacks.failure)
        callbacks.failure(err);
      if (callbacks.always)
        callbacks.always();
      return console.error('GetRoles request failed:' + err);
    }
    if (callbacks.success)
      callbacks.success(JSON.parse(body));
  });
};

Move getRole to separate file
Move getRole to separate file

Work better with cache
