<commit_before>/*

  AlmQuery

  Usage reference:
  var query = new AlmQuery();

  query.getMediaReferences(['10.1371/journal.pone.0144197', '10.1371/journal.pone.0151227'])
  .then(function (almData) {

  })
  .fail(function (error) {

  });

 */

var AlmQuery;

(function ($) {
  AlmQuery = Class.extend({
    /*
     * Constructor function
     */

    init: function (config) {
      this.config = _.extend(ALM_CONFIG, config);
      this.hasSessionStorage = Modernizr.sessionstorage;
    },
    
    /*
     * DOI format and validation functions
     */

    isDOIValid: function (doi) {
      return !_.isEmpty(doi) && (_.isString(doi) || _.isArray(doi));
    },

    formatDOI: function (doi) {
      doi = encodeURI(doi);
      return doi.replace(new RegExp('/', 'g'), '%2F').replace(new RegExp(':', 'g'), '%3A');
    },

    validateDOI: function (doi) {
      var that = this;
      if(this.isDOIValid(doi)) {
        if(_.isString(doi)) {
          return this.formatDOI(doi);
        }
        else if (_.isArray(doi)) {
          return _.map(doi, function (value) { return that.formatDOI(value); });
        }
      }
      else {
        throw new ErrorFactory('InvalidDOIError', '[AlmQuery::validateDOI] - Invalid DOI');
      }
    },

    isArticleNew: function () {
      var publishDate = moment(ArticleData.date, "MMM DD, YYYY").toDate();
      var todayMinus48Hours = (new Date()).getTime() - 172800000;
      return (todayMinus48Hours < publishDate.getTime());
    },
    
    /*
     * Request handling functions
     */

    getRequestBaseUrl: function () {
      return this.config.host + '?api_key=' + this.config.apiKey;
    },

    saveRequestCache: function (requestUrl, response) {
      if(this.hasSessionStorage) {
        window.sessionStorage.setItem(requestUrl, JSON.stringify(response));<commit_msg>DPRO-2267 - ALM Query using moment.js to calculate if the article is new<commit_after>/*

  AlmQuery

  Usage reference:
  var query = new AlmQuery();

  query.getMediaReferences(['10.1371/journal.pone.0144197', '10.1371/journal.pone.0151227'])
  .then(function (almData) {

  })
  .fail(function (error) {

  });

 */

var AlmQuery;

(function ($) {
  AlmQuery = Class.extend({
    /*
     * Constructor function
     */

    init: function (config) {
      this.config = _.extend(ALM_CONFIG, config);
      this.hasSessionStorage = Modernizr.sessionstorage;
    },
    
    /*
     * DOI format and validation functions
     */

    isDOIValid: function (doi) {
      return !_.isEmpty(doi) && (_.isString(doi) || _.isArray(doi));
    },

    formatDOI: function (doi) {
      doi = encodeURI(doi);
      return doi.replace(new RegExp('/', 'g'), '%2F').replace(new RegExp(':', 'g'), '%3A');
    },

    validateDOI: function (doi) {
      var that = this;
      if(this.isDOIValid(doi)) {
        if(_.isString(doi)) {
          return this.formatDOI(doi);
        }
        else if (_.isArray(doi)) {
          return _.map(doi, function (value) { return that.formatDOI(value); });
        }
      }
      else {
        throw new ErrorFactory('InvalidDOIError', '[AlmQuery::validateDOI] - Invalid DOI');
      }
    },

    isArticleNew: function () {
      var publishDate = moment(ArticleData.date, "MMM DD, YYYY").valueOf();
      var todayMinus48Hours = moment().subtract(2, 'days').valueOf();
      return (todayMinus48Hours < publishDate);
    },
    
    /*
     * Request handling functions
     */

    getRequestBaseUrl: function () {
      return this.config.host + '?api_key=' + this.config.apiKey;
    },

    saveRequestCache: function (requestUrl, response) {
      if(this.hasSessionStorage) {
        window.sessionStorage.setItem(requestUrl, JSON.stringify(response));
{'fraction_non_alphanumeric': 0.15217391304347827, 'fraction_numerical': 0.020933977455716585, 'mean_word_length': 2.580211335254563, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1696310', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1185, 'n_words': 233}