package com.nokia.ph.hack.stock.adapter;

import java.util.ArrayList;
import java.util.List;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

public class TwitterAdapter
{
    private Twitter twitter;

    public TwitterAdapter() throws TwitterException
    {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled( true ).setOAuthConsumerKey( "n1j4GDnQSr52q42yUSo2SRmnZ" ).setOAuthConsumerSecret(
            "CxzqvBFnmNFqWGHqKdPuiCgT0fHLCGCt9K6JgQ7Q1iGamcrd9D" ).setOAuthAccessToken(
                "1642861602-qXlaGE9LunnUyG9bZfD5T1qB7WSgR5PLOUrjXvk" ).setOAuthAccessTokenSecret(
                    "CA2tpVaehgxI6oS6ATIu5wWouykeBXQjLRHPZ7mZ4SffC" );
        TwitterFactory tf = new TwitterFactory( cb.build() );
        twitter = tf.getInstance();
    }

    public List<String> getSymbolPublicTweets( String symbol ) throws TwitterException
    {
        List<String> retVal = new ArrayList<>();
        Query query = new Query( "$SECB since:2013-10-31 until:2016-11-11" );
        QueryResult result = twitter.search( query );
        for( Status status : result.getTweets() )
        {
            retVal.add( status.getText() );
        }

        return retVal;
    }
}

@@ -87,16 +87,46 @@
 .List;%0A%0A
+import twitter4j.GeoLocation;%0A
 import t
@@ -1165,39 +1165,185 @@
 ery(
- %22$SECB s
+);%0A        query.setCount( 200 );%0A%0A        //Search query%0A        query.setQuery( %22$GOOG%22 );%0A%0A        //One day%0A        query.setS
 ince
-:2013-10-31 u
+( %222016-11-10%22 );%0A        query.setU
 ntil
-:
+( %22
 2016
@@ -1349,24 +1349,202 @@
 6-11-11%22 );%0A
+%0A        //Limit to US%0A        query.setGeoCode( new GeoLocation( 39.726867, -98.656872 ), 2500, Query.KILOMETERS );%0A%0A        System.out.println( %22Searching using: %22 + query );%0A%0A
         Quer
@@ -1597,28 +1597,29 @@
     
-for( 
+List%3C
 Status
- status :
+%3E tweets =
  res
@@ -1633,16 +1633,53 @@
 Tweets()
+;%0A        for( Status status : tweets
  )%0A     
@@ -1734,24 +1734,81 @@
 %0A        %7D%0A%0A
+        System.out.println( %22Found %22 + tweets.size() );%0A%0A
         retu

Twitter query