const Router = require('express').Router;
const eH = require(__dirname + '/../lib/error_handler');
const request = require('superagent');
const EventEmitter = require('events');

var newsRouter = module.exports = exports = Router();

newsRouter.get('/news', (req, res) => {
  var trigger = new EventEmitter();
  request.get('https://gateway-a.watsonplatform.net/calls/data/GetNews?outputMode=json' +
  '&return=enriched.url.url,enriched.url.title,enriched.url.publicationDate.date,' +
  'enriched.url.image,enriched.url.text&start=now-30d&end=now&q.enriched.url.title=' +
  'A[seattle^gun]&q.enriched.url.text=A[seattle^gun^violence]&return=enriched.url.title&apikey=' +
  process.env.WATSON_API)

  .end((err, data) => {
    if (err) return eH(err);
    trigger.emit('finished', data);
  });
  trigger.on('finished', (data) => {
    res.status(200).json(data);
  });
});

@@ -389,23 +389,16 @@
 ode=json
-' +%0A  '
 &return=
@@ -467,23 +467,16 @@
 te.date,
-' +%0A  '
 enriched
@@ -518,10 +518,10 @@
 now-
-30
+29
 d&en
@@ -551,15 +551,8 @@
 tle=
-' +%0A  '
 A%5Bse
@@ -639,16 +639,56 @@
 &apikey=
+a9a5ee133f49a99df63f0481f07a8c96cea293b1
 ' +%0A  pr
@@ -707,16 +707,17 @@
 TSON_API
+2
 )%0A%0A  .en

add new api key to news router