<commit_before>const Q             = require('q');
const {parseString} = require('xml2js');
const request       = require('request');
const BookValidator = require('../../model/goodreadsBookValidator');

function BookShow(key) {

  if (!key) {
    throw new Error('A valid goodreads API key is required.');
  }

  this.execute = (id) => {
    if (!id) {
      return Q.reject('The id of the book to show is required.');
    }

    return Q.nfcall(request, `https://www.goodreads.com/book/show/${id}.xml`, { qs: { key: key } })
            .spread((response, xmlData) => Q.nfcall(parseString, xmlData, { explicitArray: false, ignoreAttrs: true }))
            .then(({ GoodreadsResponse }) => {
              return BookValidator.validate(GoodreadsResponse.book).value;
            });
  };

}


module.exports = BookShow;<commit_msg>Manually construct the book object. Sanetizes <br /> tags.<commit_after>const Q             = require('q');
const {parseString} = require('xml2js');
const request       = require('request');

function BookShow(key) {

  if (!key) {
    throw new Error('A valid goodreads API key is required.');
  }

  this.execute = (id) => {
    if (!id) {
      return Q.reject('The id of the book to show is required.');
    }

    return Q.nfcall(request, `https://www.goodreads.com/book/show/${id}.xml`, { qs: { key: key } })
            .spread((response, xmlData) => Q.nfcall(parseString, xmlData, { explicitArray: false, ignoreAttrs: true }))
            .then(({ GoodreadsResponse }) => {

              const b = GoodreadsResponse.book;

              return {
                id: b.id,
                title: b.title,
                author: b.authors.author,
                rating: b.average_rating,
                thumb_url: b.image_url,
                description: b.description.replace(/\<br \/\>/g, '\n')
              };

            });
  };

}


module.exports = BookShow;
{'fraction_non_alphanumeric': 0.1554160125588697, 'fraction_numerical': 0.0010465724751439038, 'mean_word_length': 2.22972972972973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, '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': '740797', 'n_tokens_mistral': 588, 'n_tokens_neox': 561, 'n_words': 137}