package kr.co.swh.lecture.opensource.discord; 

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;

/**
 * <pre>
 * kr.co.swh.lecture.opensource.discord 
 * TwitterContents.java
 *
 * 설명 :	https://github.com/Twitter4J/Twitter4J
 * </pre>
 * 
 * @since : 2019. 12. 13.
 * @author : tobby48
 * @version : v1.0
 */
public class TwitterContents {

	String consumerKey;
	String consumerSecret;
	String acessToken;
	String acessTokenSecret;
	
	public TwitterContents() {
		consumerKey = "M3ioqfTgFkX2x04cYj8zoxoqB";
        consumerSecret = "W52Zj3NL4CCwN1ROFsJY2M6qP6AZtNtWu2Ppkvf21x7PkFnEcz";
        acessToken = "728767904-rvWxQuaQ7kIpOibulxvoHipDT8pWuEoukp4GaFYu";
        acessTokenSecret = "DrIV41WcnXKCTW1rDUAzmcD4alzq3cHYW90pfrOvvhuvL";
	}
	
	public List<Status> getContents(String key){
        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setDebugEnabled(true)
                .setOAuthConsumerKey(consumerKey)
                .setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(acessToken)
                .setOAuthAccessTokenSecret(acessTokenSecret);
        TwitterFactory tf = new TwitterFactory(configurationBuilder.build());
        Twitter twitter = tf.getInstance();
        
        Query query = new Query();
        query.setLang("ko");
        query.setQuery(key);
        query.setSince("2019-09-28");
        
        QueryResult queryResult = null;
		try {
			queryResult = twitter.search(query);
		} catch (TwitterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        ArrayList<Status> result = new ArrayList<>();
        for (Status status : queryResult.getTweets()) {
            result.add(status);
        }
        return result;
	}
}
