'use strict';

const winston = require('winston');
const Twitter = require('twitter');
const cache = require('./cache');
const parse = require('./parse');

const searchTerm = 't.d3fc.io';

const client = new Twitter({
  consumer_key: process.env.consumer_key,
  consumer_secret: process.env.consumer_secret,
  access_token_key: process.env.access_token_key,
  access_token_secret: process.env.access_token_secret
});

module.exports = () => {
  winston.info('Updating search results');
  client.get('search/tweets', {q: searchTerm}, (error, tweets, response) => {
    if (error) {
      return winston.warn(error);
    }
    winston.info('Search completed', tweets.statuses.length);
    const statuses = tweets.statuses
      .filter((status) => !status.retweeted_status)
      .map(parse);
    const validStatuses = statuses.filter((status) => status.es5);
    cache.statuses(validStatuses);
    winston.info('Search results updated', validStatuses.length);
  });
};

@@ -492,16 +492,21 @@
 ent.get(
+%0A    
 'search/
@@ -513,18 +513,23 @@
 tweets',
+%0A   
  %7B
+ 
 q: searc
@@ -537,10 +537,27 @@
 Term
-%7D
 ,
+ count: 100 %7D,%0A   
  (er
@@ -588,16 +588,18 @@
 %3E %7B%0A    
+  
 if (erro
@@ -609,16 +609,18 @@
 %7B%0A      
+ 
+ 
 return w
@@ -639,16 +639,18 @@
 error);%0A
+  
     %7D%0A  
@@ -647,24 +647,26 @@
       %7D%0A    
+  
 winston.info
@@ -711,24 +711,26 @@
 ength);%0A    
+  
 const status
@@ -750,16 +750,18 @@
 tatuses%0A
+  
       .f
@@ -810,16 +810,18 @@
 )%0A      
+  
 .map(par
@@ -825,16 +825,18 @@
 parse);%0A
+  
     cons
@@ -898,16 +898,18 @@
 5);%0A    
+  
 cache.st
@@ -931,24 +931,26 @@
 tuses);%0A    
+ 
+ 
 winston.info
@@ -1001,15 +1001,20 @@
 gth);%0A  
-%7D
+  %7D%0A  
 );%0A%7D;%0A

Bump result count to work around paging for now