<commit_before>HandsomeTrello.api = {
  request: function (type, url, data, callback) {
    var self = this;

    var xhttp = new XMLHttpRequest();

    if (typeof data !== 'object') {
      data = {};
    }

    if (type.toLowerCase() !== 'get') {
      data.token = self.base.getCookie('token');
    } else if (Object.keys(data).length) {
      url += '?' + self.base.generateParamsStringFromObject(data);

      data = {};
    }

    xhttp.open(type.toUpperCase(), url, true);
    xhttp.setRequestHeader('Content-Type', 'application/json');
    xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

    xhttp.onreadystatechange = function () {
      if (xhttp.readyState === 4 && xhttp.status === 200 && typeof callback === 'function' && self.base.isJSONString(xhttp.responseText)) {
        callback(JSON.parse(xhttp.responseText));
      }
    };

    xhttp.send(JSON.stringify(data));
  },
  board: {
    get: function (boardId, callback) {
      var self = this.base;

      self.request('get', 'https://trello.com/1/boards/' + boardId, {
        lists: 'open',
        cards: 'all',
        card_checklists: 'all',
        members: 'all'
      }, callback);
    }
  },
  card: {
    get: function (cardId, callback) {
      var self = this.base;

      self.request('get', 'https://trello.com/1/cards/' + cardId, {
        checklists: 'all'
      }, callback);
    },
    create: function (title, columnId, pos, callback) {
      var self = this.base;

      var data = {
        name: title,
        pos: pos,
        dateLastActivity: Date.now(),
        closed: false,
        idLabels: [],
        idMembers: [],
        idBoard: self.base.data.boardId,
        idList: columnId
      };

      self.request('post', '/1/cards', data, callback);
    }
  },
  checklist: {
    getByCardId: function (cardId, callback) {
      var self = this.base;

      self.request('get', '/1/cards/' + cardId + '/checklists', {}, callback);
    },
    get: function (checklistId, callback) {
      var self = this.base;

      self.request('get', '/1/checklists/' + checklistId, {}, callback);
    },
    create: function (cardId, name, pos, callback) {
      var self = this.base;

      var data = {
        idCard: cardId,
        name: name,
        pos: pos
      };

      self.request('post', '/1/checklists', data, callback);
    },
    remove: function (checklistId, callback) {
      var self = this.base;

      self.request('delete', '/1/checklists/' + checklistId, {}, callback);
    },
    addItem: function (checklistId, name, pos, callback) {
      var self = this.base;

      var data = {
        name: name,
        pos: pos
      };

      self.request('post', '/1/checklists/' + checklistId + '/checkItems', data, callback);
    },
    deleteItem: function (checklistId, checkItemId, callback) {
      var self = this.base;

      var data = {
        idCheckItem: checkItemId
      };

      self.request('delete', '/1/checklists/' + checklistId + '/checkItems/' + checkItemId, data, callback);
    },
    nameItem: function (cardId, checklistId, checkItemId, name, callback) {
      var self = this.base;

      var data = {
        idChecklist: checklistId,
        idCheckItem: checkItemId,
        value: name
      };

      self.request('put', '/1/cards/' + cardId + '/checklist/' + checklistId + '/checkItem/' + checkItemId + '/name', data, callback);
    },
    posItem: function (cardId, checklistId, checkItemId, pos, callback) {
      var self = this.base;

      var data = {
        idChecklist: checklistId,
        idCheckItem: checkItemId,
        value: pos
      };

      self.request('put', '/1/cards/' + cardId + '/checklist/' + checklistId + '/checkItem/' + checkItemId + '/pos', data, callback);
    }
  },
  member: {
    get: function (username, data, callback) {
      var self = this.base;

      self.request('get', '/1/members/' + username, data, callback);
    }
  }
};<commit_msg>Add queue to api request method<commit_after>HandsomeTrello.api = {
  queue: [],

  running: false,

  request: function () {
    var self = this;

    if (!self.queue.length) {
      self.running = false;

      return false;
    }

    if (self.running) {
      return false;
    }

    self.running = true;

    var requestData = self.queue[0],
        xhttp = new XMLHttpRequest();

    if (typeof requestData.data !== 'object') {
      requestData.data = {};
    }

    if (requestData.type.toLowerCase() !== 'get') {
      requestData.data.token = self.base.getCookie('token');
    } else if (Object.keys(requestData.data).length) {
      requestData.url += '?' + self.base.generateParamsStringFromObject(requestData.data);

      requestData.data = {};
    }

    xhttp.open(requestData.type.toUpperCase(), requestData.url, true);
    xhttp.setRequestHeader('Content-Type', 'application/json');
    xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

    xhttp.onreadystatechange = function () {
      if (xhttp.readyState === 4) {
        if (xhttp.status === 200 && typeof requestData.callback === 'function' && self.base.isJSONString(xhttp.responseText)) {
          requestData.callback(JSON.parse(xhttp.responseText));
        }

        self.queue.splice(0, 1);

        self.running = false;

        self.request();
      }
    };

    xhttp.send(JSON.stringify(requestData.data));
  },

  addToQueue: function (type, url, data, callback) {
    var self = this;

    self.queue.push({
      type: type,
      url: url,
      data: data,
      callback: callback
    });

    self.request();
  },

  board: {
    get: function (boardId, callback) {
      var self = this.base;

      self.addToQueue('get', 'https://trello.com/1/boards/' + boardId, {
        lists: 'open',
        cards: 'all',
        card_checklists: 'all',
        members: 'all'
      }, callback);
    }
  },

  card: {
    get: function (cardId, callback) {
      var self = this.base;

      self.addToQueue('get', 'https://trello.com/1/cards/' + cardId, {
        checklists: 'all'
      }, callback);
    },
    create: function (title, columnId, pos, callback) {
      var self = this.base;

      var data = {
        name: title,
        pos: pos,
        dateLastActivity: Date.now(),
        closed: false,
        idLabels: [],
        idMembers: [],
        idBoard: self.base.data.boardId,
        idList: columnId
      };

      self.addToQueue('post', '/1/cards', data, callback);
    }
  },

  checklist: {
    getByCardId: function (cardId, callback) {
      var self = this.base;

      self.addToQueue('get', '/1/cards/' + cardId + '/checklists', {}, callback);
    },
    get: function (checklistId, callback) {
      var self = this.base;

      self.addToQueue('get', '/1/checklists/' + checklistId, {}, callback);
    },
    create: function (cardId, name, pos, callback) {
      var self = this.base;

      var data = {
        idCard: cardId,
        name: name,
        pos: pos
      };

      self.addToQueue('post', '/1/checklists', data, callback);
    },
    remove: function (checklistId, callback) {
      var self = this.base;

      self.addToQueue('delete', '/1/checklists/' + checklistId, {}, callback);
    },
    addItem: function (checklistId, name, pos, callback) {
      var self = this.base;

      var data = {
        name: name,
        pos: pos
      };

      self.addToQueue('post', '/1/checklists/' + checklistId + '/checkItems', data, callback);
    },
    deleteItem: function (checklistId, checkItemId, callback) {
      var self = this.base;

      var data = {
        idCheckItem: checkItemId
      };

      self.addToQueue('delete', '/1/checklists/' + checklistId + '/checkItems/' + checkItemId, data, callback);
    },
    nameItem: function (cardId, checklistId, checkItemId, name, callback) {
      var self = this.base;

      var data = {
        idChecklist: checklistId,
        idCheckItem: checkItemId,
        value: name
      };

      self.addToQueue('put', '/1/cards/' + cardId + '/checklist/' + checklistId + '/checkItem/' + checkItemId + '/name', data, callback);
    },
    posItem: function (cardId, checklistId, checkItemId, pos, callback) {
      var self = this.base;

      var data = {
        idChecklist: checklistId,
        idCheckItem: checkItemId,
        value: pos
      };

      self.addToQueue('put', '/1/cards/' + cardId + '/checklist/' + checklistId + '/checkItem/' + checkItemId + '/pos', data, callback);
    }
  },

  member: {
    get: function (username, data, callback) {
      var self = this.base;

      self.addToQueue('get', '/1/members/' + username, data, callback);
    }
  }
};
{'fraction_non_alphanumeric': 0.15621013568363679, 'fraction_numerical': 0.004058912211527311, 'mean_word_length': 2.3156478277585544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2522355', 'n_tokens_mistral': 2770, 'n_tokens_neox': 2672, 'n_words': 601}