<commit_before>/* jslint node: true */
'use strict';

var request = require('request');
var jsonPath = require('JSONPath');
var select = require('xpath.js');
var dom = require('xmldom').DOMParser;
var fs = require('fs');

var accessToken;
var globalVariables = {};

var ATTRIBUTE = 2;

function BitterApple(scheme, domain) {
  this.domain = scheme + '://' + domain;
  this.headers = {};
  this.httpResponse = {};
  this.requestBody = '';
  this.scenarioVariables = {};
  this.realValue = null;
}

/**
 * Provides the value that was compared to the expected one
 */
BitterApple.prototype.getRealValue = function() {
  return this.realValue;
};

BitterApple.prototype.addRequestHeader = function(name, value) {
  this.headers[name] = value;
};

BitterApple.prototype.addRequestHeaderFromScenarioVariable = function(name, variable) {
  this.headers[name] = this.scenarioVariables[variable];
};

BitterApple.prototype.addRequestHeaderFromGlobalVariable = function(name, variable) {
  this.headers[name] = globalVariables[variable];
};

BitterApple.prototype.getResponseObject = function() {
  return this.httpResponse;
};

BitterApple.prototype.setRequestBody = function(body) {
  this.requestBody = body;
};

BitterApple.prototype.pipeFileContentsToRequestBody = function(file, callback) {
  var self = this;
  fs.readFile(file, 'utf8', function(err, data) {
    if (err) {
      callback(err);
    }

    self.setRequestBody(data);
    callback();
  });
};

BitterApple.prototype.get = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request.get({
      url: this.domain + resource,
      headers: this.headers
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });

};

BitterApple.prototype.post = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'POST'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.put = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'PUT'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.delete = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'DELETE'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.patch = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'PATCH'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.addHttpBasicAuthorizationHeader = function(username, password) {
  var b64EncodedValue = base64Encode(username + ':' + password);
  this.addRequestHeader('Authorization', 'Basic ' + b64EncodedValue);
};

BitterApple.prototype.assertResponseCode = function(responseCode) {
  this.realValue = this.getResponseObject();
  return (this.getResponseObject().statusCode == responseCode);<commit_msg>Fixed storing of real value for status code.<commit_after>/* jslint node: true */
'use strict';

var request = require('request');
var jsonPath = require('JSONPath');
var select = require('xpath.js');
var dom = require('xmldom').DOMParser;
var fs = require('fs');

var accessToken;
var globalVariables = {};

var ATTRIBUTE = 2;

function BitterApple(scheme, domain) {
  this.domain = scheme + '://' + domain;
  this.headers = {};
  this.httpResponse = {};
  this.requestBody = '';
  this.scenarioVariables = {};
  this.realValue = null;
}

/**
 * Provides the value that was compared to the expected one
 */
BitterApple.prototype.getRealValue = function() {
  return this.realValue;
};

BitterApple.prototype.addRequestHeader = function(name, value) {
  this.headers[name] = value;
};

BitterApple.prototype.addRequestHeaderFromScenarioVariable = function(name, variable) {
  this.headers[name] = this.scenarioVariables[variable];
};

BitterApple.prototype.addRequestHeaderFromGlobalVariable = function(name, variable) {
  this.headers[name] = globalVariables[variable];
};

BitterApple.prototype.getResponseObject = function() {
  return this.httpResponse;
};

BitterApple.prototype.setRequestBody = function(body) {
  this.requestBody = body;
};

BitterApple.prototype.pipeFileContentsToRequestBody = function(file, callback) {
  var self = this;
  fs.readFile(file, 'utf8', function(err, data) {
    if (err) {
      callback(err);
    }

    self.setRequestBody(data);
    callback();
  });
};

BitterApple.prototype.get = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request.get({
      url: this.domain + resource,
      headers: this.headers
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });

};

BitterApple.prototype.post = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'POST'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.put = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'PUT'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.delete = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'DELETE'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.patch = function(resource, callback) { // callback(error, response)
  resource = replaceVariables(resource, this.scenarioVariables);
  var self = this;
  request({
      url: this.domain + resource,
      headers: this.headers,
      body: this.requestBody,
      method: 'PATCH'
    },
    function(error, response) {
      if (error) {
        return callback(error);
      }

      self.httpResponse = response;
      callback(null, response);
    });
};

BitterApple.prototype.addHttpBasicAuthorizationHeader = function(username, password) {
  var b64EncodedValue = base64Encode(username + ':' + password);
  this.addRequestHeader('Authorization', 'Basic ' + b64EncodedValue);
};

BitterApple.prototype.assertResponseCode = function(responseCode) {
  this.realValue = this.getResponseObject().statusCode;
  return (this.getResponseObject().statusCode == responseCode);
{'fraction_non_alphanumeric': 0.1305987741631306, 'fraction_numerical': 0.001885902876001886, 'mean_word_length': 3.537433155080214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6522066', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2468, 'n_words': 526}